Azure-docs: Read Secret with Line Breaks

Created on 13 Aug 2019  Â·  13Comments  Â·  Source: MicrosoftDocs/azure-docs

In Azure Key Vault, when reading the secret value from the portal, line breaks contained within the secret are ignored. Clicking "Copy to Clipboard" copies the entire secret without line breaks. This causes an issue particularily when storing an RSA key.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri3 cxp key-vaulsvc needs-more-info product-feedback triaged

Most helpful comment

I am having the same issue. Private keys in Azure KeyVault lose their linebreaks when exported. This is not very convenient when using the keyvault on the agent machines, as the ssh will return "invalid format", and there is no way to fix the format as Azure prevents it.

The suggested fix, removes the line breaks, thus enhances the problem rather than fix it. What one needs to do, if not one a hosted agent is to ADD line breaks:

sed -e "s/-----BEGIN RSA PRIVATE KEY-----/&\n/" -e "s/-----END RSA PRIVATE KEY-----/\n&/" -e "s/\S\{64\}/&\n/g" mykey > myfixedkey

An alternative is to save the key as a file, which hopefully does not alter the content:
az keyvault secret set --name myprivatekey --vault-name mykeyvault --file C:\test\mykey

All 13 comments

@dangershin Could you please provide us with the documentation link related to your question?

Thanks,
Adam

@Adam-Smith-MSFT The link has been added already, but for reference, it is here: https://docs.microsoft.com/en-us/azure/key-vault/quick-create-portal

Hi @dangershin

Looks like there is a workaround for this posted here. You can use a perl command to get rid of the line breaks:

perl -pi -e 'chomp if eof' ~/.ssh/mykey

# Set permissions to user-read only
chmod 600 ~/.ssh/mykey

Have you tried this? https://serverfault.com/questions/848168/putting-rsa-keys-into-azure-key-vault

See also: https://github.com/Microsoft/azure-pipelines-tasks/issues/4715

This might be considered more of a product feedback than doc feedback, unless you think this should be added specifically to the docs. @barclayn

All product feedback should be added to User Voice so that the product team can respond directly. https://feedback.azure.com/forums/169401-azure-active-directory

Closing this out as I have not heard back. Feel free to tag me in the comments or open a new issue if you'd like to continue the discussion.

I am having the same issue. Private keys in Azure KeyVault lose their linebreaks when exported. This is not very convenient when using the keyvault on the agent machines, as the ssh will return "invalid format", and there is no way to fix the format as Azure prevents it.

The suggested fix, removes the line breaks, thus enhances the problem rather than fix it. What one needs to do, if not one a hosted agent is to ADD line breaks:

sed -e "s/-----BEGIN RSA PRIVATE KEY-----/&\n/" -e "s/-----END RSA PRIVATE KEY-----/\n&/" -e "s/\S\{64\}/&\n/g" mykey > myfixedkey

An alternative is to save the key as a file, which hopefully does not alter the content:
az keyvault secret set --name myprivatekey --vault-name mykeyvault --file C:\test\mykey

@MarileeTurscak-MSFT #please-reopen!

i can't understand such things

@anvarich can you talk more about what you don't understand?

@MarileeTurscak-MSFT #please-reopen!
I want to store & read Secret with Line Breaks using C#. Any help?

Even worse, the solution above creates a key that doesn't work in every app using ssh. To get a git client to accept the key, I had to use:

sed -e "s/-----BEGIN RSA PRIVATE KEY-----/&\n/" -e "s/-----END RSA PRIVATE KEY-----/\n&/" -e "s/\S{64}/& \n/g" mykey > myfixedkey

Note the " \n" which adds a whitespace character. This is necessary for some apps. Please reopen and ensure that azure key vaults don't mangle ssh keys.

I just created a priority support ticket, hopefully we hear something back soon!

So the answer is that you cannot set multi-line secrets in the portal due to a limitation in the Azure SDK. You can set multi-line secrets via PowerShell as shown above. #please-close

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spottedmahn picture spottedmahn  Â·  3Comments

Agazoth picture Agazoth  Â·  3Comments

jharbieh picture jharbieh  Â·  3Comments

Favna picture Favna  Â·  3Comments

jamesgallagher-ie picture jamesgallagher-ie  Â·  3Comments