doc/ci/secrets/azure_key_vault.md
{{< details >}}
{{< /details >}}
{{< history >}}
{{< /history >}}
You can use secrets stored in the Azure Key Vault in your GitLab CI/CD pipelines.
Prerequisites:
AZURE_KEY_VAULT_SERVER_URL: The URL of your Azure Key Vault server, such as https://vault.example.com.AZURE_CLIENT_ID: The client ID of the Azure application.AZURE_TENANT_ID: The tenant ID of the Azure application.You can use a secret stored in your Azure Key Vault in a job by defining it with the
azure_key_vault keyword:
job:
id_tokens:
AZURE_JWT:
aud: 'https://gitlab.com'
secrets:
DATABASE_PASSWORD:
token: $AZURE_JWT
azure_key_vault:
name: 'DATABASE-PASSWORD'
version: '00000000000000000000000000000000'
To use multiple secrets from Azure Key Vault in the same job, define each secret under the secrets keyword:
job:
id_tokens:
AZURE_JWT:
aud: 'https://gitlab.com'
secrets:
REDIS_PASSWORD:
token: $AZURE_JWT
azure_key_vault:
name: 'REDIS-PASSWORD'
version: '00000000000000000000000000000000'
DATABASE_PASSWORD:
token: $AZURE_JWT
azure_key_vault:
name: 'DATABASE-PASSWORD'
version: '00000000000000000000000000000000'
In these examples:
aud is the audience, which must match the audience used when creating the federated identity credentialsname is the name of the secret in Azure Key Vault.version is the version of the secret in Azure Key Vault. The version is a generated
GUID without dashes, which can be found on the Azure Key Vault secrets page.DATABASE_PASSWORD or REDIS_PASSWORD), similar to
file type CI/CD variables.Refer to OIDC for Azure troubleshooting for general problems when setting up OIDC with Azure.
JWT token is invalid or malformed messageYou might receive this error when fetching secrets from Azure Key Vault:
RESPONSE 400 Bad Request
AADSTS50027: JWT token is invalid or malformed.
This occurs due to a known issue in GitLab Runner where the JWT token isn't parsed correctly. To resolve this, upgrade to GitLab Runner 16.6 or later.
Caller is not authorized to perform action on resource messageYou might receive this error when fetching secrets from Azure Key Vault:
RESPONSE 403: 403 Forbidden
ERROR CODE: Forbidden
Caller is not authorized to perform action on resource.\r\nIf role assignments, deny assignments or role definitions were changed recently, please observe propagation time.
ForbiddenByRbac
If your Azure Key Vault is using RBAC, you must add the Key Vault Secrets User role assignment to your Azure AD application.
For example:
appId=$(az ad app list --display-name gitlab-oidc --query '[0].appId' -otsv)
az role assignment create --assignee $appId --role "Key Vault Secrets User" --scope /subscriptions/<subscription-id>
You can find your subscription ID in:
The secrets provider can not be found. Check your CI/CD variables and try again. messageYou might receive this error when attempting to start a job configured to access Azure Key Vault:
The secrets provider can not be found. Check your CI/CD variables and try again.
The job can't be created because one or more of the required variables are not defined:
AZURE_KEY_VAULT_SERVER_URLAZURE_CLIENT_IDAZURE_TENANT_ID