Managing Secrets, Keys and Certificates with Azure Key Vault
This lesson explains how vaults are secured, and how pipelines read from them.
Learning outcomes
After completing this lesson, you will be able to:
- Describe Key Vault objects and protections.
- Choose a data plane role.
- Read secrets in Azure Pipelines.
- Read secrets in GitHub Actions.
Key Vault fundamentals
Azure Key Vault stores three kinds of object. Secrets are values such as passwords and connection strings. Keys are cryptographic keys, which are used inside the vault, so the key material does not leave it. Certificates are X.509 certificates, and a vault can manage their lifecycle and renewal.
Centralizing these objects has clear advantages. Each access is logged, a value can be rotated in one place without changing any pipeline, and each object has versions. Protection against mistakes comes from soft delete, which is always on and holds deleted items for a retention period, and purge protection, which stops anyone from permanently deleting an item during that period.
Secret, key or certificate?
Controlling access
Azure RBAC is the recommended permission model for vaults, and is the default for new vaults from API version 2026-02-01. Roles separate duties at the data plane. The older model is called access policies.
| Role | Allows |
|---|---|
| Key Vault Secrets User | Reading secret values |
| Key Vault Secrets Officer | Managing secrets |
| Key Vault Crypto User | Using keys for cryptographic operations |
| Key Vault Certificates Officer | Managing certificates |
| Key Vault Reader | Reading metadata, not values |
| Key Vault Administrator | All data plane operations |
A pipeline normally needs only Key Vault Secrets User, ideally at the level of the vault used by one environment. A separate vault for each environment and application is a sound design, because a vault is the natural boundary for access. If public access is disabled on a vault, a hosted agent cannot reach it, so a self-hosted agent or Managed DevOps Pool in the virtual network is required.
Key Vault RBAC roles
Reading secrets in Azure Pipelines
There are two main methods.
AzureKeyVault@2 task
The AzureKeyVault@2 task downloads named secrets into pipeline variables during a run. The SecretsFilter input limits which ones, and it is better to list only those required than to use *. With RunAsPreJob: true, secrets are fetched before the job begins, so that they are available to all steps.
steps:
- task: AzureKeyVault@2
inputs:
azureSubscription: sc-azure-prod
KeyVaultName: kv-contoso-prod
SecretsFilter: 'DbPassword,ApiKey'
RunAsPreJob: false
- script: ./deploy.sh
env:
DB_PASSWORD: $(DbPassword)Secret variables are not passed to scripts as environment variables automatically, so they must be mapped explicitly through env, as shown. Values are masked in logs.
Key Vault-linked variable group
A variable group in the Library can be linked to a vault. An administrator authorizes a service connection, then selects which secrets to map as variables. Only names are stored in Azure DevOps, and the latest values are fetched at run time, so that a rotated secret takes effect with no pipeline change. This suits several pipelines sharing the same values.
variables:
- group: prod-secrets # linked to kv-contoso-prod
steps:
- script: ./deploy.sh
env:
DB_PASSWORD: $(DbPassword)The following diagram shows eight pipelines reading a password from Key Vault through one linked variable group.

AzureKeyVault@2 or a linked variable group?
Reading secrets in GitHub Actions
GitHub Actions has no dedicated task, and the usual pattern is to sign in with azure/login, then read values with the Azure CLI. A value should be registered with add-mask, so that it does not appear in logs, and written to $GITHUB_ENV or passed directly to a step.
- uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Read a secret
id: vault
run: |
value=$(az keyvault secret show --vault-name kv-contoso-prod --name ApiKey --query value -o tsv)
echo "::add-mask::$value"
echo "api-key=$value" >> "$GITHUB_OUTPUT"
- run: ./deploy.sh
env:
API_KEY: ${{ steps.vault.outputs.api-key }}Keys, certificates and rotation
Keys can sign artifacts, and a build can call the vault to sign without the private key ever reaching the agent. Certificates can be retrieved as secrets, and App Service can import them directly from a vault. Certificates issued through integrated providers can renew automatically.
Rotation limits the damage from a leak. Key Vault publishes events through Azure Event Grid when a secret is near expiry, so an Azure Function can create a new value and update the vault. Applications that read the latest version pick it up without redeployment. Audit reads by sending vault logs to Log Analytics with a diagnostic setting.
Keys, certificates and rotation
Rotation without pipeline changes
Eight pipelines use a database password stored as a secret variable in each pipeline. Rotating it takes a day, and it is often forgotten. What should you recommend?
Store the password in Azure Key Vault, and use a Key Vault-linked variable group across the eight pipelines, with the identity holding Key Vault Secrets User. Values are read at run time, so rotation happens once, in the vault. A plain variable group centralizes the value, but it does not provide audit logs or managed rotation. A secret in each repository's YAML would expose the value.
A vault has public access disabled. Why might a hosted agent fail to read it?
Show answer
The hosted agent is outside the private network, so a self-hosted agent or Managed DevOps Pool in the network is needed.
Exam Tips
Remember for the exam
- Key Vault stores secrets, keys and certificates.
- Key Vault Secrets User lets a pipeline read secret values.
- Use AzureKeyVault@2 or a Key Vault-linked variable group.
- Linked variable groups fetch current values at run time.
- Map secrets explicitly to scripts through env.