Skill 4.1.1

Secure secrets by using Azure Key Vault, including rotation and retrieval

Key Concepts

A secret is a named value of up to 25 KB with versions; setting a secret again creates a new version, and the latest enabled version is returned unless a version is named. Applications read secrets with SecretClient(vault_url, DefaultAzureCredential()) and get_secret(name), using a managed identity that holds Key Vault Secrets User on the vault. Values should be cached for a short time, because Key Vault throttles high request rates. Hosting platforms can also resolve secrets by reference, so that application code reads an ordinary environment variable.

Rotation replaces a secret with a new value before the old one expires. A secret can have an expiration date, and Key Vault publishes a SecretNearExpiry event to Event Grid 30 days before it, which can trigger a function that creates a new credential in the target service and stores it as a new version. For services with two keys, the dual-credential pattern rotates one key while applications use the other. Cryptographic keys support an automatic rotation policy.