Key Vault references let an App Service app or Azure Functions app read secrets from Azure Key Vault through its managed identity, so connection strings and API keys stop living in plain app settings. App settings are one of the most common places secrets accumulate in Azure. Anyone with read access to the app's configuration, every ARM template export and every deployment pipeline that sets them can see the values. Key Vault references replace each secret value with a pointer, and the platform resolves the pointer at runtime using the app's own identity.
This guide walks through the reference syntax, the identity and permission setup, rotation behaviour, network-restricted vaults, the Functions content share setting that trips many teams up, deployment slots, templates and troubleshooting. For hardening the vault itself, see our Azure Key Vault Security Guide.
This is an independent guide from NHI Mgmt Group, based on Microsoft's public documentation as of November 2026. It is not sponsored or reviewed by Microsoft. Product features change, so confirm settings against Microsoft's current documentation.
Key takeaways
- A reference is an app setting value of the form
@Microsoft.KeyVault(SecretUri=...)or@Microsoft.KeyVault(VaultName=...;SecretName=...). Application code reads the setting exactly as before. - The platform resolves references with the app's system-assigned managed identity by default, or a user-assigned identity set through
keyVaultReferenceIdentity. - The identity needs only to read secrets: the Key Vault Secrets User role on RBAC vaults, or the Get secret permission on access policy vaults.
- Unversioned references pick up new secret versions within 24 hours. Any configuration change, or a refresh API call, fetches them immediately.
- If a reference fails to resolve, the app receives the literal
@Microsoft.KeyVault(...)string, not an error from the platform. Check reference status after every change. - Use one vault per application per environment, mark reference settings as slot settings, and tightly control who holds Contributor on the vault.
What a Key Vault reference changes, and what it does not
Without references, an app setting such as a database connection string holds the secret value itself. With a reference, the app setting holds a pointer to a secret in Key Vault. At start-up, App Service uses the app's managed identity to fetch the value, caches it, and exposes it to the application under the same setting name. No code change is needed, which is why references are usually the quickest way to remove secrets from app configuration.
From a non-human identity point of view, the change is significant:
- The secret value no longer appears in the app's configuration, in configuration exports or in the pipeline that deploys settings.
- Access to the value is governed by Key Vault permissions granted to the app's managed identity, which you can review and revoke in one place.
- Reads of the secret are recorded by Key Vault, so you can see which identity read what.
What a reference does not change: the secret is still a long-lived credential for whatever downstream service it unlocks, and the application still holds the value in memory. Key Vault references are a way to store and deliver secrets safely, not a way to get rid of them. Where the downstream Azure service supports Microsoft Entra authentication, removing the secret entirely is the stronger option, covered later in this guide.
Reference syntax
Microsoft documents two equivalent formats, both wrapped in @Microsoft.KeyVault(...):
| Format | Example | Notes |
|---|---|---|
| Secret URI, unversioned | @Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/mysecret) | Follows the latest version of the secret |
| Secret URI, versioned | @Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/mysecret/<version>) | Pinned to one version until you change the setting |
| Vault and secret name | @Microsoft.KeyVault(VaultName=myvault;SecretName=mysecret) | Optional SecretVersion= pins a version |
Choose between versioned and unversioned deliberately. Unversioned references make rotation easy because a new version in Key Vault flows to the app without touching configuration. Versioned references give you an explicit change record and a predictable rollback, at the cost of a configuration change for every rotation. Many teams use unversioned references for secrets rotated by automation and versioned references where a rotation must be coordinated with a release.
Step 1: give the app an identity
By default, references are resolved with the app's system-assigned managed identity. Turn it on in the app's Identity blade, or declare it in your template. A system-assigned identity has a useful property: it lives and dies with the app, so it cannot outlive the workload it serves.
Use a user-assigned managed identity when a secret must be referenced at creation time, before a system-assigned identity exists, or when you manage identities separately from apps. Microsoft's documented commands are:
identityResourceId=$(az identity show --resource-group <group-name> --name <identity-name> --query id -o tsv)
az webapp update --resource-group <group-name> --name <app-name> --set keyVaultReferenceIdentity=${identityResourceId}
Two points to note. The keyVaultReferenceIdentity setting applies to every Key Vault reference in the app, so one app uses one identity for all its references. And to go back to the system-assigned identity, set the property to SystemAssigned. If you share a user-assigned identity between apps, every one of those apps can read every secret that identity can read, so keep shared identities rare and their permissions narrow. Our Azure Managed Identities Security Guide covers the wider trade-offs.
Step 2: grant read access to secrets, and nothing more
The identity needs to read secret values. How you grant that depends on the vault's permission model:
| Vault permission model | Grant |
|---|---|
| Azure RBAC | The Key Vault Secrets User role |
| Vault access policy | The Get secret permission |
Microsoft's Key Vault RBAC guide describes access policies as the legacy data plane mechanism and states that RBAC is the default model for vaults created from API version 2026-02-01 onwards. Practical guidance from that page:
- Scope. Use a separate vault per application per environment and assign the role at vault scope. Microsoft does not recommend assigning roles on individual secrets, apart from narrow exceptions such as secrets shared between several applications.
- Least privilege. Key Vault Secrets User reads secret contents, which is all a reference needs. Do not give app identities Key Vault Secrets Officer, which can perform any action on secrets except managing permissions.
- Timing. Role assignments can take several minutes to take effect. A reference that fails immediately after you assign the role may simply need a few minutes and a restart.
- Model switch. Moving a vault from access policies to RBAC invalidates all existing access policy permissions. Assign the equivalent roles to every app identity first, or every reference in every dependent app breaks at once.
- Control plane. A user with Contributor on the vault's control plane can grant themselves data plane access by setting an access policy. Keep Contributor on vaults that hold app secrets to a small group.
To check for app identities that hold more than they need, see How to find over-privileged Azure managed identities.
Step 3: replace secret values with references
- Create or confirm the secret in the vault.
- In the app's configuration, replace the setting value with the reference string. Keep the setting name the same so application code is unaffected.
- Save. Any configuration change restarts the app and fetches all referenced secrets.
- Open the setting again with Edit and check its status. A resolved reference shows a success status. If no status appears at all, the platform has not recognised the value as a Key Vault reference, which usually means a syntax error.
- Delete the old secret value from anywhere else it was kept, including pipeline variables and parameter files, and rotate the secret if it was ever stored in plain configuration.
That last step matters. Moving a secret into Key Vault does not make the copy that sat in app settings for two years any less exposed. Treat migration as a rotation event.
Rotation and refresh behaviour
App Service caches resolved values. For unversioned references, it refetches them every 24 hours, so a new secret version reaches the app within that window. Three ways to pick up a new version sooner:
- Make any app configuration change, which restarts the app and refetches every referenced secret immediately.
- Call the documented refresh endpoint with an authenticated POST:
POST https://management.azure.com/[Resource ID]/config/configreferences/appsettings/refresh?api-version=2022-03-01. - Change a versioned reference to point at the new version.
Plan rotations around the cache. A safe pattern is to create the new credential on the downstream service while the old one is still valid, add it as a new secret version, trigger a refresh, confirm the app is using it, and only then revoke the old credential. If you revoke first, the app keeps presenting the cached old value for up to 24 hours unless you force a refresh. Key management practice in NIST SP 800-57 Part 1 on overlapping validity periods applies here.
Network-restricted vaults
If the vault's firewall restricts access, the app's public outbound IP addresses are not a reliable way in. Microsoft's guidance is to configure the vault to accept traffic from the virtual network the app is integrated with, and to route outbound traffic through that network. Linux apps that connect to private endpoints need outbound routing enabled explicitly; Flex Consumption function apps do this automatically:
az webapp config set --resource-group <group-name> --subscription <subscription> --name <app-name> --generic-configurations '{"vnetRouteAllEnabled": true}'
Then confirm the vault firewall allows the app's subnet. Microsoft notes that Key Vault audit logs may show a 403 Forbidden SecretGet from the public outbound IP followed by a successful SecretGet from the private IP, and states that this is by design. Know this before you build alerts on failed secret reads, or your detection will fire on every app restart.
Azure Functions: the content share setting
Function apps on plans that mount an Azure Files content share use the WEBSITE_CONTENTAZUREFILECONNECTIONSTRING setting, which holds a storage connection string. It can be a Key Vault reference, but by default validation fails, because the platform cannot resolve the secret while it processes the configuration request. Microsoft's documented workaround:
- Set
WEBSITE_SKIP_CONTENTSHARE_VALIDATIONto1to bypass validation. - Create the content share yourself in advance, because with validation skipped the platform does not create it.
- Be aware that if the connection string or share is invalid, the app fails to start and returns HTTP 500 errors.
- Until Azure Files is mounted, the app runs on a default file system and files are not copied, so avoid deployments in that window.
Microsoft's ARM template example shows AzureWebJobsStorage set from a Key Vault reference built from the secret's versioned URI, so the host storage connection string can be handled the same way as other secrets.
Application Insights settings (APPINSIGHTS_INSTRUMENTATIONKEY and APPLICATIONINSIGHTS_CONNECTION_STRING) can also be references, but if they are, the portal cannot show telemetry from the app resource and you work in the Application Insights resource directly. Microsoft states these values are not considered secrets, so setting them directly is a reasonable choice.
Going further: identity-based connections instead of secrets
A Key Vault reference still delivers a secret. For Azure services that accept Microsoft Entra authentication, Azure Functions supports identity-based connections, where the binding or host authenticates with the app's managed identity instead of a connection string. The Azure Functions developer guide states that these use the system-assigned identity by default, that a user-assigned identity is selected with the credential and clientId properties, and that local development uses the developer's own identity such as an Azure CLI login. Exact setting names vary by binding, so follow the connection documentation for each one.
A sensible order of preference for each setting is:
- Identity-based connection, so no secret exists.
- Key Vault reference, so the secret exists only in the vault.
- Plain app setting, only for values that are not secrets.
For the broader comparison of identity options, see Service Principals vs Managed Identities.
Deployment slots and templates
Because each environment should have its own vault, Microsoft recommends marking most Key Vault reference settings as slot settings. Otherwise a slot swap can move a production app onto a staging vault reference, or the reverse. Check which identity each slot resolves references with, and grant a staging identity access to the staging vault only.
When deploying with ARM templates, Microsoft's guidance is:
- Define app settings as a separate
configchild resource (appsettings), not inside the app'ssiteConfig. - Define the app with
"identity": { "type": "SystemAssigned" }first, so the identity exists before the vault permission refers to it. - Sequence the app, vault, secrets and app settings with
dependsOn. - Add
WEBSITE_ENABLE_SYNC_UPDATE_SITEset totrueso app setting updates are synchronous and source control deployments start only after settings are fully updated.
Keep the template free of secret values. The template should create the reference string, not the secret; secrets belong in the vault, set by a separate, tightly permissioned process.
Troubleshooting failed references
The most important behaviour to understand: when a reference cannot be resolved, the platform passes the literal reference string to the application. The app then fails in whatever way it handles an unexpected connection string, which can look like a database or network fault rather than a permission problem. Microsoft lists the common causes as a misconfigured access policy or RBAC role, a deleted secret, or a syntax error.
| Symptom | Where to look |
|---|---|
| No status shown on the setting | Syntax: the value is not recognised as a reference |
| Status shows an access error | Role or access policy on the vault, propagation time, identity selected by keyVaultReferenceIdentity |
| Works from one network, fails from another | Vault firewall, VNet integration and vnetRouteAllEnabled |
| Old secret value still in use | 24-hour cache: force a refresh |
| Function app returns HTTP 500 at start-up | Content share connection string and WEBSITE_SKIP_CONTENTSHARE_VALIDATION |
Use the built-in Key Vault Application Settings Diagnostics detector under Diagnose and solve problems: for App Service under Availability and Performance, Web app down, and for Azure Functions under Availability and Performance, Function app down or reporting errors. For identity token problems beyond references, see How to fix Azure managed identity token errors.
Common failure patterns
- Secret moved, never rotated. The old plain-text value remains valid and remains in exports, pipeline history and backups.
- App identities with write access. Granting Key Vault Secrets Officer or broad access policies "to make it work" lets a compromised app change or delete secrets.
- Shared vaults across environments. A staging app identity that can read production secrets turns a test compromise into a production one.
- Reference settings not marked as slot settings. A swap points production at the wrong vault.
- Silent failure. Teams do not check reference status after changes, and the app runs with the literal reference string until something breaks downstream.
- Revoke before refresh. The old credential is revoked while the app still holds the cached value.
- Uncontrolled Contributor on the vault. Control plane Contributors can grant themselves data plane access through access policies.
- Alerting on by-design 403s. Detection rules fire on the expected public IP 403 before the private endpoint read succeeds.
Practitioner checklist
- Inventory every app setting holding a secret across App Service and Function apps.
- Enable a system-assigned identity, or set
keyVaultReferenceIdentityto a dedicated user-assigned identity. - One vault per application per environment, with Key Vault Secrets User (or Get) at vault scope for the app identity only.
- Replace values with
@Microsoft.KeyVault(...)references and confirm each shows a resolved status. - Rotate every secret that previously sat in plain configuration, and remove old copies from pipelines and parameter files.
- Decide versioned or unversioned per secret, and document the refresh step in the rotation runbook.
- For restricted vaults, VNet integration,
vnetRouteAllEnabledwhere required and a vault firewall rule for the app subnet. - For Function apps on Azure Files, pre-create the content share before setting
WEBSITE_SKIP_CONTENTSHARE_VALIDATION. - Mark reference settings as slot settings and grant each environment's identity only its own vault.
- Move to identity-based connections wherever the target service supports Entra authentication.
- Restrict Contributor on vaults and review app identity permissions regularly.
Standards and references
- Microsoft: Use Key Vault references as app settings in Azure App Service and Azure Functions
- Microsoft: Provide access to Key Vault keys, certificates and secrets with Azure RBAC
- Microsoft: Azure Functions developer guide
- OWASP: Secrets Management Cheat Sheet
- NIST: SP 800-57 Part 1 Rev. 5, Recommendation for Key Management
- NIST: SP 800-53 Rev. 5 (IA-5 Authenticator Management, SC-12 Cryptographic Key Establishment and Management)
- MITRE ATT&CK: Credentials In Files
Related NHI Mgmt Group resources: Azure Key Vault Security Guide · Azure App Service Security Guide · Azure Managed Identities Security Guide · How to fix Azure managed identity token errors