I have created a Key Vault in Azure DevOps using ARM and I now want to write a secret to it within the same pipeline.
I created an Azure PowerShell task with the following inline PowerShell:
$secretvalue = ConvertTo-SecureString $(Secret) -AsPlainText -Force
Set-AzureKeyVaultSecret -VaultName $(VaultName) -Name $(SecretName) -SecretValue (ConvertTo-SecureString $(Secret) -AsPlainText -Force)
The key vault gets created fine, but I get the following error when trying to write the secret:
[error]Access denied
If I run Set-AzureKeyVaultSecret
on my local machine it works fine.
EDIT
Here are some screenshots of what I've done. In Azure DevOps I created a Service Connection and verified it:
Here's what my Azure PowerShell task looks like to write the secret to the vault:
Key Vault permissions:
Do I need a separate Service Principal or do I need to create an App Registration?