Lesson 1 of 3 Managing Secrets with Azure Key Vault

Understanding Azure Key Vault for Developers

This lesson explains why secrets belong in Key Vault, the objects, versions and attributes it holds, access control, protection settings and limits.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain when Key Vault is needed and when an identity removes the secret.
  • Describe secret versions and attributes.
  • Choose a least-privilege Key Vault role.
  • Describe soft delete, purge protection and throttling.

Why secrets belong in Key Vault

AI back ends depend on secrets: API keys for external model providers, database passwords where managed identities are not possible, webhook signing keys, and certificates. Secrets kept in source code, configuration files or container images spread to every copy of the code, cannot be rotated without redeployment, and leave no record of who read them. Azure Key Vault centralizes them: applications authenticate with Microsoft Entra ID, authorization decides exactly which secrets each identity can read, every access can be logged, and values can be versioned and rotated in one place.

The best secret is one that does not exist. Where a service supports Microsoft Entra authentication, as Cosmos DB, Service Bus, Event Grid, Azure Managed Redis, Storage and PostgreSQL do, a managed identity removes the secret entirely. Key Vault is for the secrets that remain.

Sort into groups

Key Vault or managed identity?

Exam skills 4.1.1

Decide whether each credential should be removed with a managed identity or stored in Key Vault.

Log in to try this activity Interactive activities are free with an account.

Objects, versions and attributes

A vault holds three kinds of object. Secrets are values of up to 25 KB that applications retrieve, such as passwords and API keys. Keys are cryptographic keys that perform operations, such as signing or wrapping, inside the vault, so the key material never leaves it. Certificates are X.509 certificates with their private keys and renewal policies.

Every object has versions. Setting a secret that already exists creates a new version and leaves the old ones in place. A secret's identifier is a URI: https://VAULT.vault.azure.net/secrets/NAME refers to the current version, and https://VAULT.vault.azure.net/secrets/NAME/VERSION to a specific one. Each version has attributes: enabled, an activation date (nbf), an expiry date (exp), a content type such as text/plain or application/json, and tags. Key Vault does not refuse to return an expired secret, but the expiry date drives near-expiry events and monitoring.

True or false

Objects and versions

Exam skills 4.1.1

Decide whether each statement about Key Vault objects is true.

Log in to try this activity Interactive activities are free with an account.

Access control

Requests to a vault are authenticated with Microsoft Entra ID and authorized on two planes. The control plane manages the vault resource, such as its network settings; the data plane reaches its contents. With the Azure RBAC permission model, which is the default for vaults created with current API versions, data access uses dedicated roles.

RoleAllowsTypical holder
Key Vault Secrets UserRead secret valuesAn application's managed identity
Key Vault Secrets OfficerCreate, update, delete and read secretsA rotation function or a deployment pipeline
Key Vault ReaderRead metadata, not secret valuesInventory and monitoring tools
Key Vault Crypto UserPerform operations with keysA service that signs or encrypts
Key Vault AdministratorAll data plane operationsVault administrators

Roles are normally assigned at vault scope, which is why the recommended design is one vault per application per environment: the vault becomes the access boundary, and a compromised application cannot read other applications' secrets. The legacy access policy model is still supported for existing vaults.

The following diagram shows the role each identity holds and what it allows.

Least-privilege Key Vault roles for three managed identities, all assigned at the scope of the application's own vault. The web API reads values with Key Vault Secrets User, the rotation function sets new versions with Key Vault Secrets Officer, and the security dashboard lists secrets and their expiry dates with Key Vault Reader, which never returns values.
All three roles are assigned at the scope of the application's own vault.
Match the pairs

Key Vault roles

Exam skills 4.1.1

Match each identity with the least-privilege Key Vault role.

Log in to try this activity Interactive activities are free with an account.

Protection, networking and limits

Soft delete is always on: deleted vaults and objects can be recovered for a retention period of 7 to 90 days (90 by default), set at creation. Purge protection, which cannot be turned off once enabled, prevents anyone from permanently deleting soft-deleted items before the retention period ends. The vault firewall can restrict access to selected networks, and private endpoints give private access, in which case applications must reach the vault over that network.

Key Vault throttles requests above service limits, which are counted per vault per region within short time windows, and returns HTTP 429. Applications that read a secret on every request can hit these limits under load, so they cache secrets. Every data plane operation can be recorded in the AuditEvent category of the vault's diagnostic logs, sent to a Log Analytics workspace.

az keyvault create --resource-group RG --name VAULT --location LOCATION --enable-purge-protection true
az role assignment create --assignee-object-id APP_PRINCIPAL_ID --assignee-principal-type ServicePrincipal \
  --role "Key Vault Secrets User" --scope $(az keyvault show --name VAULT --query id -o tsv)
az keyvault secret set --vault-name VAULT --name model-api-key --value "VALUE" \
  --content-type text/plain --expires 2027-05-01T00:00:00Z
Scenario questions

Protecting a vault

Exam skills 4.1.1

Choose the Key Vault feature that fits each requirement.

Log in to try this activity Interactive activities are free with an account.
Worked example

Least privilege for three identities

A web API must read a third-party model API key from Key Vault. A rotation function must write new versions of that key every 60 days. A security dashboard must list which secrets are near expiry but must never see values. All use managed identities.

The API's identity gets Key Vault Secrets User, which reads values but cannot change them. The rotation function's identity gets Key Vault Secrets Officer, which can set new versions. The dashboard's identity gets Key Vault Reader, which lists secrets and their attributes, including expiry dates, without values. All three are assigned at the scope of the application's own vault.

Key Vault Administrator for the function would work but exceeds its needs. Key Vault Secrets User for the dashboard would expose values it must not see. Contributor on the vault gives no data plane access under Azure RBAC.

Check yourself

Which Key Vault role lets a dashboard list secret names and expiry dates without reading values?

Show answer

Key Vault Reader, which reads metadata but not secret values.

Exam Tips

Remember for the exam

  • Prefer managed identities; use Key Vault for the secrets that remain.
  • Setting a secret creates a new version; a URI without a version means the current version.
  • Secrets User reads values, Secrets Officer manages secrets, Reader sees metadata only.
  • One vault per application per environment; cache secrets to avoid throttling.