Key Vault & App Configuration
Key Vault secrets · RBAC roles · references · soft-delete · rotation · App Configuration keys, labels, refresh, roles, snapshots
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Key Vault secrets
- Key Vault stores generic secrets such as passwords and database connection strings. A secret has a maximum size of 25 KB.
- Secret attributes:
exp(default forever),nbf(default now),enabled(default true).expandnbfare informational. - A get on a not-yet-valid or expired secret still works, outside the nbf / exp window. Reading an expired secret can serve recovery.
- The
contentTypefield holds up to 255 characters. A secret supports up to 15 tags, each with a 512-character name and value. - Secret permissions: get, list, set, delete, recover, backup, restore. The privileged operation is purge.
- Use one vault per application, region and environment. Don't use Key Vault as a store for service configuration (use App Configuration or Storage) and don't store certificates as secrets.
| Azure RBAC role | What it does |
|---|---|
| Key Vault Secrets User | Read secret contents |
| Key Vault Secrets Officer | Any action on secrets, except manage permissions |
| Key Vault Reader | Read metadata only. Cannot read secret contents or key material |
| Key Vault Crypto Officer | Any action on keys, except manage permissions |
| Key Vault Administrator | All data plane operations on the vault and its objects |
These roles work only for vaults that use the Azure role-based access control permission model. RBAC is recommended. Legacy access policies are not.
Retrieve secrets in code and from app settings
- Python:
SecretClient(vault_url=KVUri, credential=credential)withDefaultAzureCredential(). Useset_secret,get_secretandbegin_delete_secret(asynchronous, returns a poller). - In the quickstart
DefaultAzureCredentialuses the local development user logged into the Azure CLI. After deployment to Azure the same code can discover a managed identity assigned to an App Service, Virtual Machine or other service. - A Key Vault reference in an app setting:
@Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/mysecret)or@Microsoft.KeyVault(VaultName=myvault;SecretName=mysecret). SecretVersion is optional. - References use the app's system-assigned identity by default. For a user-assigned identity, set
keyVaultReferenceIdentityto its resource ID. - RBAC vault: assign Key Vault Secrets User. Access policy vault: assign the Get secrets permission.
- With no version in the reference the app uses the latest version and picks up a new one within 24 hours. A configuration change restarts the app and refetches every referenced secret at once.
- Mark most Key Vault reference settings as slot settings, because each environment should have its own vault.
Soft-delete and purge protection
- Soft-delete is on by default for a new vault and can't be disabled.
- Deleted objects stay recoverable for 7 to 90 days. The default is 90. You set the interval only at vault creation.
- Permanent deletion takes two steps: delete, then purge the soft-deleted object. Purge needs the purge permission, for example the Key Vault Purge Operator role.
- Turn on purge protection to protect against accidental or malicious deletion even after soft-delete is enabled.
Rotation
| Asset | Autorotation |
|---|---|
| Keys | New key versions from a rotation policy |
| Secrets | Event-triggered updates (Event Grid + Azure Functions) |
| Certificates | Automatic renewal before expiry |
- Key rotation policy: rotation time minimum is seven days. Default type is renew at a given time after creation. Renew before expiry needs an expiry time on the policy and an expiration date on the key.
- Under RBAC assign Key Vault Crypto Officer to manage the rotation policy and on-demand rotation. Rotate encryption keys at least every two years.
- Rotation creates a new key version with new key material. It re-wraps data encryption keys and doesn't re-encrypt the underlying data.
- Secret rotation tutorial: Key Vault publishes a near-expiry event 30 days before expiry. Event Grid POSTs to the function app. The function creates a new secret version, then updates SQL Server. Event Grid retries for two hours if a step fails.
App Configuration
- App Configuration centrally manages application settings and feature flags. It complements Key Vault, which stores secrets.
- Keys are case-sensitive unicode strings. Any unicode character except
%is allowed. A key-value (key, value and attributes) is limited to 10 KB. - A label differentiates key-values with the same key, for example Test, Staging, Production. A key-value has no label by default. Reference it with
\0(%00in URLs). - Query patterns:
key=abcexact,key=abc*prefix,key=abc,xyzeither (limited to five values). - Stacking: load unlabeled key-values, then load a labeled set. Matching keys from the later set overwrite the earlier ones.
- Refresh needs no restart. Providers monitor all selected keys (a change to any one reloads the whole configuration) or a sentinel key that you update last. The Python provider can't monitor all selected keys; it monitors individual keys, such as a sentinel key.
- Python provider:
pip install azure-appconfiguration-provider, thenload(endpoint=endpoint, credential=credential). The result works like a dictionary.SettingSelectorfilters by key and label.trim_prefixesstrips prefixes from key names. - A Key Vault reference key stores the secret's URI, not the value. The app authenticates to both services, because they don't communicate directly.
| Role | Access |
|---|---|
| App Configuration Data Reader | Read key-values (data plane) |
| App Configuration Data Owner | Read, write and delete key-values (data plane) |
| App Configuration Contributor | Manage the store resource, not the data. Can read access keys |
| App Configuration Reader | Read the store resource, not access keys or data |
Allow up to 15 minutes for a new role assignment to propagate. Managed identity can't authenticate an app that runs locally.
Snapshots, events and tiers
- A snapshot is a named, immutable subset of key-values chosen by key and label filters. You create and archive snapshots. You can't delete, purge or edit them.
- The retention period is set at creation. Default 30 days (Standard, Premium) or 7 days (Free, Developer).
- Event Grid events: KeyValueModified (created or replaced), KeyValueDeleted and SnapshotCreated.
- Request limits: Free 1,000 per day, Developer 6,000 per hour, Standard 30,000 per hour, Premium none. Over-quota requests can return HTTP 429.
- The Developer tier also includes Private Link. The Standard and Premium tiers offer more functionality, including Private Link support, customer-managed keys, soft delete protection and geo-replication.
CLI and PowerShell
| Task | Azure CLI | PowerShell |
|---|---|---|
| Create a vault with RBAC and purge protection | az keyvault create --name "<vault-name>" --resource-group "myResourceGroup" --enable-rbac-authorization true --enable-purge-protection true | - |
| Create a secret | az keyvault secret set --vault-name "<vault-name>" --name "ExamplePassword" --value "hVFkk965BuUv" | - |
| Show a secret value | az keyvault secret show --name "ExamplePassword" --vault-name "<vault-name>" --query "value" | - |
| Set a key rotation policy from a file | az keyvault key rotation-policy update --vault-name <vault-name> --name <key-name> --value </path/to/policy.json> | - |
| Rotate a key now | az keyvault key rotate --vault-name <vault-name> --name <key-name> | - |
| Install the Microsoft Entra identity library (Python) | - | pip install azure-identity |
| Install the Key Vault secrets library (Python) | - | pip install azure-keyvault-secrets |
| Create a secret client (Python) | - | client = SecretClient(vault_url=KVUri, credential=credential) |
| Read a secret (Python) | - | retrieved_secret = client.get_secret(secretName) |
| Install the App Configuration provider (Python) | - | pip install azure-appconfiguration-provider |
| Load settings with Microsoft Entra ID (Python) | - | config = load(endpoint=endpoint, credential=credential) |
| Filter keys and labels (Python) | - | selects = {SettingSelector(key_filter="message*", label_filter="\0")} |
Exam Tips
Tick each tip once you can answer it without looking.
“App Service app reads a Key Vault secret through an app setting; vault uses RBAC” → Key Vault Secrets User for the managed identity. Trap: Key Vault Reader can't read secret contents. Secrets Officer does more than read.
“Vault uses access policies; identity only reads secrets” → Get permission on secrets. Trap: List only lists. Set creates. Purge deletes permanently.
“Valid Key Vault reference” → @Microsoft.KeyVault(SecretUri=...full URI...) or (VaultName=...;SecretName=...). Trap: SecretUri must be the full data-plane URI. The prefix is @Microsoft.KeyVault.
“Rotated secret, reference has no version” → App uses the new version within 24 hours; a config change refetches at once. Trap: Pin a version and the app stays on it.
“References with a user-assigned identity” → Set keyVaultReferenceIdentity to the identity's resource ID. Trap: System-assigned is the default. The client ID isn't what the property takes.
“Secret deleted by mistake, default vault” → Recoverable for 90 days; interval 7 to 90 set only at creation. Trap: Soft-delete can't be disabled. Purge is a second, separate step.
“Secret needs automatic replacement before expiry” → Event Grid near-expiry event to a function that creates a new version and updates the service. Trap: Rotation policies are for keys. The exp attribute is informational.
“Order of the SQL password rotation” → Near-expiry event, Event Grid POST, new secret version, SQL update. Trap: Key Vault publishes the event 30 days before expiry. Event Grid retries for two hours.
“Who manages a key rotation policy under RBAC?” → Key Vault Crypto Officer; minimum rotation interval seven days. Trap: Rotation re-wraps data keys. It doesn't re-encrypt data.
“Where do settings live and where do secrets live?” → Settings in App Configuration; secrets in Key Vault. Trap: Don't use Key Vault as a configuration store. App Configuration complements it.
“Python read of a secret” → DefaultAzureCredential, SecretClient, get_secret. Trap: set_secret writes. begin_delete_secret deletes. Hard-coded credentials are discouraged.
“Same key, different value per environment” → Labels (Test, Staging, Production); \0 is no label. Trap: Keys are case-sensitive. Don't use case to tell keys apart.
“Update many key-values, reload once” → Monitor a sentinel key and change it last. Trap: Monitoring all selected keys reloads on any single change.
“App only reads App Configuration data” → App Configuration Data Reader. Trap: Data Owner can write and delete. The Reader and Contributor roles act on the resource, not the data.
“Secret value delivered through an App Configuration key” → Key Vault reference key; identity needs Data Reader and Key Vault Secrets User. Trap: The two services don't talk to each other. A Data Reader role alone isn't enough.
“Immutable known-good configuration for rollout” → Snapshot: create and archive, can't edit or delete. Trap: Retention is fixed at creation (30 days Standard and Premium, 7 days Free and Developer).
Sources
- About Azure Key Vault secrets
- Use Key Vault references as app settings
- Azure Key Vault soft-delete
- Secure your Azure Key Vault
- Provide access to Key Vault with Azure RBAC
- Quickstart: Key Vault Python client library for secrets
- Quickstart: Key Vault secrets with Azure CLI
- Understanding autorotation in Azure Key Vault
- Configure key auto-rotation in Key Vault
- Rotation tutorial for one set of credentials
- What is Azure App Configuration?
- App Configuration key-value store
- App Configuration best practices
- Quickstart: App Configuration with Python
- Access App Configuration using Microsoft Entra ID
- Use managed identities to access App Configuration
- Key Vault references in App Configuration
- App Configuration snapshots
- App Configuration events
- App Configuration FAQ
Checked against Microsoft Learn on November 13, 2026.