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.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@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!
Used Powershell to upload multiline text and able to retrieve using C#.
https://artisticcheese.wordpress.com/2018/01/04/storing-arbitrary-text-file-in-azure-key-vault-as-secrets-ssh-keys-cer-files-etc/
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
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