question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[KeyVault] Unable to create self-signed certificate with Azure CLI 2.0 with PowerShell

See original GitHub issue

Description

When trying to create a self-signed certificate, it generates a JSON parsing error.

az keyvault certificate create --vault-name my-keyvault -n cert1 -p "$(az keyvault certificate get-default-policy)"

I also tried to put the actual JSON content instead of the command interpolation. I also tried to escape the actual JSON content, etc.

Nothing seems to work.

Expecting property name enclosed in double quotes: line 1 column 5 (char 4)

What I’m expecting is to be able to either pass the filename in a parameter so that it can be read and deserialized properly or pass the content of the file in a reasonably formatted fashion.


Environment summary

Install Method: How did you install the CLI? (e.g. pip, interactive script, apt-get, Docker, MSI, nightly)
Answer here: MSI

CLI Version: What version of the CLI and modules are installed? (Use az --version)
Answer here: azure-cli (2.0.18)

acr (2.0.12) acs (2.0.16) appservice (0.1.17) backup (1.0.1) batch (3.1.4) billing (0.1.5) cdn (0.0.9) cloud (2.0.8) cognitiveservices (0.1.8) command-modules-nspkg (2.0.1) component (2.0.7) configure (2.0.11) consumption (0.1.5) container (0.1.11) core (2.0.17) cosmosdb (0.1.13) dla (0.0.12) dls (0.0.14) eventgrid (0.1.4) extension (0.0.3) feedback (2.0.6) find (0.2.7) interactive (0.3.10) iot (0.1.12) keyvault (2.0.11) lab (0.0.11) monitor (0.0.10) network (2.0.15) nspkg (3.0.1) profile (2.0.13) rdbms (0.0.7) redis (0.2.9) resource (2.0.15) role (2.0.12) servicefabric (0.0.4) sql (2.0.12) storage (2.0.16) vm (2.0.15)

OS Version: What OS and version are you using?
Answer here: Windows 10 version 1703 (OS Build 15063.632)

Shell Type: What shell are you using? (e.g. bash, cmd.exe, Bash on Windows)
Answer here: PowerShell

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tjprescottcommented, Oct 6, 2017

Fixed by PR #4628.

0reactions
MaximRouillercommented, Oct 6, 2017

Issue:

Doing az keyvault certificate get-default-policy > defaultpolicy.json would generate a file UTF-16LE encoded under PowerShell and UTF-8 under Bash or CMD.

Although, azure-cli is supposed to handle it… my bet is that it fails to detect UTF-16LE and uses UTF-16 instead which transforms it to a deserialization error instead of an encoding error.

Workaround for those walking this path in the future:

az keyvault certificate get-default-policy | Out-File -Encoding utf8 defaultpolicy.json

This forces the encoding to UTF-8 and the az command can now be used properly in PowerShell like so by escaping the @.

az keyvault certificate create --vault-name my-keyvault -n cert --policy `@defaultpolicy.json
Read more comments on GitHub >

github_iconTop Results From Across the Web

Generate self-signed certificate with a custom root CA
Learn how to generate an Azure Application Gateway self-signed certificate with a custom root CA.
Read more >
TLS termination with Key Vault certificates - Azure
This model is the traditional way to pass TLS/SSL certificates to Application Gateway for TLS termination. Provide a reference to an existing ...
Read more >
Create an Azure service principal – Azure CLI - Microsoft Learn
The --keyvault parameter can be added to use a certificate in Azure Key Vault. In this case, the --cert value is the name...
Read more >
Manage Key Vault using the Azure CLI - Microsoft Learn
You may see the error "The subscription is not registered to use namespace 'Microsoft.KeyVault'" when you try to create a new key vault....
Read more >
Add and manage TLS/SSL certificates - Azure App Service
On your app's navigation menu, select TLS/SSL settings. On the pane that opens, select Private Key Certificates (.pfx) > Create App Service ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found