Domain 4 β€” Module 1 of 5 20%
23 of 27 overall
Domain 4: Secure, monitor, and troubleshoot Azure solutions Free ⏱ ~12 min read

Azure Key Vault: Secrets, Rotation, Retrieval

The hardened store for the strings that must not leak. Vaults vs HSMs, RBAC vs access policies, secret rotation strategies, and how Container Apps, Functions, and AKS read secrets without ever holding a copy.

Why everything ends up in Key Vault

Simple explanation

Azure Key Vault is where every secret string in your app belongs: API keys, database passwords, certificate private keys, encryption keys, OAuth client secrets. Two things matter most for AI-200:

  • How services retrieve secrets without a copy. Container Apps, Functions, App Service, AKS all support pulling Key Vault secrets at startup using managed identity.
  • How you rotate secrets without downtime. Most Azure services Key Vault integrates with auto-rotate; for the rest you write a small rotation function.

Key Vault has access models (RBAC vs legacy access policies), and SKUs (Standard for software-protected keys, Premium for HSM-protected). The exam tests when each matters.

Access model β€” RBAC is the modern path

Key Vault has two coexisting access models:

ModelWhat it doesStatus
Microsoft Entra RBACAzure roles control access (Key Vault Secrets User, Key Vault Secrets Officer, etc.)Recommended
Vault access policiesPer-principal access policies stored on the vaultLegacy β€” being deprecated
# Switch a vault to RBAC permission model
az keyvault update --name roo-kv --enable-rbac-authorization true

# Grant the Container App's managed identity read access to secrets
az role assignment create \
  --assignee $PRINCIPAL_ID \
  --role "Key Vault Secrets User" \
  --scope $(az keyvault show -n roo-kv --query id -o tsv)

Built-in data-plane roles you must know:

RolePermissions
Key Vault ReaderList secret/key/cert metadata only
Key Vault Secrets UserGet a secret value
Key Vault Secrets OfficerGet + Set + List + Delete
Key Vault Crypto UserUse a key to encrypt/decrypt/sign/verify/wrap/unwrap
Key Vault Crypto OfficerManage keys
Key Vault Certificates OfficerManage certificates
Key Vault AdministratorEverything (data plane + management plane)
Exam tip: 'least-privilege' = Secrets User, not Officer

When the question says β€œthe worker needs to read the OpenAI API key”, the right role is Key Vault Secrets User β€” only Get on secrets. Don’t pick Secrets Officer (which adds Set, List, Delete) or Administrator. The exam rewards minimum sufficient privilege.

Retrieval β€” three patterns

Pattern 1 β€” Key Vault references in app settings

Used by App Service and Function Apps. The host resolves the reference at startup; the container sees the live value.

OPENAI_API_KEY=@Microsoft.KeyVault(SecretUri=https://roo-kv.vault.azure.net/secrets/OpenAIKey)

Conditions: app has managed identity, identity has Get on the secret, app can reach Key Vault on the network.

Pattern 2 β€” Container Apps secret with keyvaultref:

az containerapp secret set \
  --name roo-fn -g roo-prod \
  --secrets openai-key=keyvaultref:https://roo-kv.vault.azure.net/secrets/OpenAIKey,identityref:system

az containerapp update --name roo-fn -g roo-prod \
  --set-env-vars OPENAI_API_KEY=secretref:openai-key

Pattern 3 β€” SDK retrieval at runtime

from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient

client = SecretClient(
    vault_url="https://roo-kv.vault.azure.net",
    credential=DefaultAzureCredential(),
)
secret = client.get_secret("OpenAIKey").value

Use this when you need to fetch fresh values during runtime β€” for example, after rotation, without an app restart. Cache the value briefly to avoid hammering Key Vault.

Pattern 4 β€” Secrets Store CSI driver (AKS)

For AKS, the CSI driver projects Key Vault secrets as files (or env vars) into pods, with optional polling for rotation.

Versioning and rotation

Every secret in Key Vault has versions. URLs can target the current version (no version segment) or a specific version:

https://roo-kv.vault.azure.net/secrets/OpenAIKey                  # current
https://roo-kv.vault.azure.net/secrets/OpenAIKey/<version-id>     # specific

For most apps reference the unversioned URL β€” rotation just produces a new version, and the app picks it up on next read.

Rotation strategies

StrategyHowBest for
Native auto-rotationKey Vault auto-rotates the secret on a schedule for supported integrations (e.g., Storage account keys, Cosmos DB keys)Azure-native services with rotation hooks
Event-driven rotationKey Vault emits a Microsoft.KeyVault.SecretNearExpiry event; an Event Grid subscription triggers a Function that creates a new versionAny service Microsoft doesn’t auto-rotate
Scheduled rotation FunctionA timer-triggered Function rotates secrets on a cadenceSimpler shape than event-driven; works without Event Grid
# Auto-rotation example: rotate Storage account keys every 60 days
az keyvault setting update --vault-name roo-kv \
  --name AllowKeyManagementOperationsThroughARM --value true

# Then configure the rotation policy on the secret in the portal
# or via the Microsoft.KeyVault.SetSecretRotationPolicy ARM action

Apps that hold the unversioned URL automatically pick up the new version on next retrieval. Apps that pin a version id must be redeployed β€” usually NOT what you want.

Soft delete and purge protection

Key Vault has two safety nets every production vault should consider:

FeatureWhat it doesDefault?
Soft deleteDeleted items go to a recoverable state for the retention period (7-90 days)On by default (mandatory since Feb 2025; cannot be disabled)
Purge protectionEven an admin cannot permanently delete items during the retention window β€” protects against malicious or accidental destructionOff by default β€” opt in for any vault holding production secrets

Soft delete protects against accidental delete; purge protection additionally blocks permanent deletion. They are different controls β€” enable purge protection explicitly for regulated workloads.

Networking β€” public, private, or VNet-restricted

ModeUse
Public access (default)Quick start, dev/test
Selected networks (firewall)Allow specific VNets and IP ranges
Private endpointThe vault is reachable only from a private IP inside your VNet

For regulated AI workloads (Theo’s Tidewater Health), private endpoint + VNet integration on consumers is the standard pattern.

Key terms

Question

What's the recommended Key Vault access model?

Click or press Enter to reveal answer

Answer

Microsoft Entra RBAC. Use built-in roles (`Key Vault Secrets User` for read-only secret access) at the vault, secret, key, or certificate scope. The legacy 'Vault access policy' model is being deprecated; prefer RBAC for new deployments.

Click to flip back

Question

What's the right role for an app that needs to read one secret?

Click or press Enter to reveal answer

Answer

Key Vault Secrets User β€” granting Get on secrets. It does NOT grant Set, List, or Delete. Apply it at the secret scope (or vault scope if you can't be more specific) for least-privilege access.

Click to flip back

Question

What's the difference between Standard and Premium Key Vault?

Click or press Enter to reveal answer

Answer

Standard uses software-protected keys (FIPS 140-2 Level 1). Premium uses HSM-backed key storage (FIPS 140-2 Level 2 or 3). Pick Premium when you need hardware-protected keys for regulated workloads. For dedicated HSMs, Azure Managed HSM is a separate product.

Click to flip back

Question

How does Key Vault handle secret rotation without app downtime?

Click or press Enter to reveal answer

Answer

Reference the unversioned secret URL in your app. Rotation creates a new version under the same name; the next time the app retrieves the secret, it gets the new value. Apps that pin a specific version id must be redeployed β€” usually not what you want.

Click to flip back

Question

What is purge protection in Key Vault?

Click or press Enter to reveal answer

Answer

A safety setting that prevents permanent deletion of soft-deleted items during the retention window β€” even by administrators. Required for many compliance scenarios. Pair with soft delete for full recovery from accidental or malicious deletes.

Click to flip back

Knowledge check

Knowledge Check

Theo's Container App needs read-only access to one specific secret in Key Vault. He's choosing the role to grant the app's managed identity. Which is least privilege?

Knowledge Check

Mira wants the worker to pick up a new OpenAI key the moment it's rotated, with no redeploy. The key is referenced via app settings as `@Microsoft.KeyVault(SecretUri=https://roo-kv.vault.azure.net/secrets/OpenAIKey/abc123)`. Why won't this work, and what's the fix?

Knowledge Check

Lin's vault is public-network-accessible. The security review wants Key Vault reachable only from inside the production VNet. What's the right configuration?