set policy to access secrets in your key vault

Ifiokobong Offiong 56 Reputation points
2022-06-29T15:23:36.587+00:00

Hi Please can someone help me on how to fix this error.

I am using the secret store csi driver to mount secrets and certificates from Azure key Vault to pods in my AKS cluster.

The whole process is via a CI/CD pipeline (Github Actions).

My first job enables the secret store csi driver on my exisiting cluster.

My Second job depends on the 1st job and it sets the access policy to the key vault and this is where i have the error:

ERROR: The command failed with an unexpected error. Here is the traceback:  
ERROR: Insufficient privileges to complete the operation.  
azure.cli.core.azclierror.HTTPError: Forbidden(***"error":***"code":"Authorization_RequestDenied","message":"Insufficient privileges to complete the operation."  

this is an extract of my second job:

  enable-key-vault-access:  
    runs-on: [self-hosted, linux]  
    environment: ${{inputs.ENVIRONMENT }}  
  
    steps:  
      - name: Azure Login  
        uses: azure/login@v1  
        with:  
          creds:${{secrets.AZURE_CREDENTIALS }}  
  
      - name: connect to key Vault  
        run: |  
          MI_CLIENT_ID=$(az aks show -g ${{secrets.aks_rg }} -n ${{secrets.aks_name }} --query addonProfiles.azureKeyvaultSecretsProvider.identity.clientId -o tsv)  
          az keyvault set-policy -n ${{secrets.keyvault }} --secret-permissions get --spn $MI_CLIENT_ID  
          az keyvault set-policy -n ${{secrets.keyvault }} --certificate-permissions get --spn $MI_CLIENT_ID  
          az keyvault set-policy -n ${{secrets.keyvault }} --key-permissions get --spn $MI_CLIENT_ID  

$MI_CLIENT_ID is the Value of my User Managed Identity from the 1st job.

Everything works fine when i set the policy outside of the CI/CD pipline from my vs code terminal but when i do the same thing in the pipline i have this error. Any idea on how to fix this error? Thank you

Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,314 questions
Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,146 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.