Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot acces keyvault secrets through service endpoint in a VSTS release

We're trying to download secrets with the download key vault secrets release task in VSTS.

The service principal is add in the key vault's access policies, all rights are checked, including get, list secrets.

I created a service endpoint with this service principal and use that to deploy to Azure, but I get following error when trying to retrieve the keyvault secrets:

2018-05-21T12:18:53.9240364Z ##[error]Get secrets failed. Error: Access denied. Specified Azure endpoint needs to have Get, List secret management permissions on the selected key vault. To set these permissions, download ProvisionKeyVaultPermissions.ps1 script from build/release logs and execute it OR set them from Azure portal.

like image 604
fvl Avatar asked Jun 21 '18 12:06

fvl


People also ask

How do I use key vault in release pipeline Azure?

Search for vault and select the Azure Key Vault task. Select your Azure subscription and then select Authorize. Select your Key vault from the dropdown menu, and then select Add to add the task to your YAML pipeline. The Make secrets available to whole job feature is not supported in Azure DevOps Server 2019 and 2020.

How do I access Azure key vault secrets?

Retrieve a secret from Key VaultUse https://<your-unique-keyvault-name>.vault.azure.net/secrets/ExamplePassword to get the current version. Now, you have created a Key Vault, stored a secret, and retrieved it.


2 Answers

0) Go to your variables library

1) Tick on Link secrets from an Azure key vault as variables

2) Select subscription

3) Select key vault

4) Click Authorize

ACLing will be done by MS and you'll be able to use key vault task.

I'm sure there used to be an Authorize button when selecting the key vault in the task, but I may be missremembering. Just sunk 2h in to figuring this out....

enter image description here

Issue tracked here

like image 111
Mardoxx Avatar answered Sep 21 '22 10:09

Mardoxx


The Dev Ops server also needs to be able to access the keyvault through the firewall if the firewall is turned on ("Allow access from..." on the firewalls and virtual networks page).

The network access to the keyvault for variables is done through a non-agent part of AzDevOps I believe but I haven't figured out how to whitelist those servers.

Turning on the "Allow trusted Microsoft services to byass this firewall" did not work.

I had to allow access for "all networks" to work around this for now as the simplest solution.

The other safer option using an agent task and not a variable group is to..

  1. Have your own agent pool in an Azure VM
  2. Either..
    1. Connect this to a private vnet which is also connected to the KeyVault or...
    2. Whitelist the agent's public endpoint in the keyvault
  3. Read in variables from the keyvault secrets during the agent process using the KayVault task (i.e. read the secrets as part of the pipeline).

Hope this helps. Mark.

like image 44
MarkD Avatar answered Sep 22 '22 10:09

MarkD