In my devops pipeline, I have this task:
- task: AzureKeyVault@2
displayName: 'Fetch secrets from KeyVault used in Deploy stage'
inputs:
azureSubscription: '$(AzureServiceConnectionName)'
KeyVaultName: '$(AzureKeyVaultName)'
SecretsFilter: '*' # Fetch all secrets
RunAsPreJob: true
# Note: all the variables above are correctly resolving.
RunAsPreJob is set to ´true´ because I want to be able to use some secrets as variables in a few tasks after this one (but inside the same job, of course).
The problem is that when it tries to run as a pre-job, it throws the error:
Pre-job: Fetch secrets from KeyVault used in Deploy stage
View raw log
Starting: Fetch secrets from KeyVault used in Deploy stage
==============================================================================
Task : Azure Key Vault
Description : Download Azure Key Vault secrets
Version : 2.249.1
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-key-vault
==============================================================================
SubscriptionId: <not-the-actual-value>.
Key vault name: <not-the-actual-value>.
Downloading secrets using: https://<not-the-actual-value>.vault.azure.net/secrets?maxresults=25&api-version=2016-10-01.
##[error]Get secrets failed. Error: Client address is not authorized and caller is not a trusted service.
Client address: <not-the-actual-value>
Caller: appid=***;oid=<not-the-actual-value>;iss=https://sts.windows.net/<not-the-actual-value>/
Vault: <not-the-actual-value>;location=westeurope. The specified Azure service connection needs to have Get, List secret management permissions on the selected key vault. To set these permissions, download the ProvisionKeyVaultPermissions.ps1 script from build/release logs and execute it, or set them from the Azure portal..
Uploading /home/vsts/work/1/ProvisionKeyVaultPermissions.ps1 as attachment
Finishing: Fetch secrets from KeyVault used in Deploy stage
I have successfully run that script which added this to the keyvault's access policies:

Then I re-ran the pipeline but the error still remains... I also added this access policy manually to key vault and re-ran the pipeline to no avail...
Additionally, attempting a workaround, I tried adding a Variable group linked to the key vault:
as you can see, with no success...
I am a bit lost by now and without any more clues to what might the problem be.
Note: I have run this keyvault task with RunAsPreJob: false in the past and it went ok.
RunAsPreJob: false, it went ok, can you please enable the variable “system.debug”(set the value to “true”) in your pipeline, then trigger new runs and share the detailed logs of both success run and failed run? This helps to narrow down the issue.Error: Client address is not authorized and caller is not a trusted serviceis the same as this question. Please check if you have set firewalls and virtual networks setting. If you are using self-hosted agent and have enabled that setting, you can add the client IP of your agent in your Azure keyvault