Configuring Azure Key Vault References in Azure Functions

AI-200 By islever Editorial Last updated

Short answer

C Store the Key Vault reference using the @Microsoft.KeyVault(SecretUri=...) syntax in the Function App configuration to allow the runtime to resolve the secret securely.

Question

You are developing an Azure Function that calls external APIs by providing an access token for the API. The access token is stored in a secret named token in an Azure Key Vault named mykeyvault. You need to ensure the Azure Function can access the token. Which value should you store in the Azure Functions app configuration?
  1. App:Settings:Secret:mykeyvault:token
  2. KeyVault:mykeyvault;Secret:token
  3. @Microsoft.KeyVault(SecretUri=https://mykeyvault.vault.azure.net/secrets/token/) Correct Answer
  4. AZUREKVCONNSTR_ https://mykeyvault.vault.azure.net/secrets/token/

Key Takeaways

To securely access secrets in Azure Key Vault from an Azure Function, you must use the @Microsoft.KeyVault(SecretUri=...) syntax in the app configuration. This placeholder allows the runtime to resolve the secret dynamically without exposing the value in settings. Option C correctly implements this secure resolution pattern.

Expert Analysis

To securely provide the Azure Function with the secret without exposing it in application code, store a Key Vault reference in the Function App configuration settings using the @Microsoft.KeyVault(SecretUri=...) syntax. Omitting a version targets the latest version of the secret.

The core challenge in this scenario is enabling an Azure Function to access secrets stored in Azure Key Vault without hardcoding credentials or exposing them in plain text within the application's configuration. The correct mechanism for achieving this is through a specific placeholder syntax that the Azure Functions runtime resolves at startup. This approach leverages Managed Identities and the integration between App Configuration and Key Vault.

Option C, @Microsoft.KeyVault(SecretUri=https://mykeyvault.vault.azure.net/secrets/token/), is the correct value to store in the Function App's configuration settings. This string acts as a template or reference. When the Azure Functions host initializes, it detects this special prefix (@Microsoft.KeyVault) and automatically replaces it with the actual value of the secret named token from the vault named mykeyvault. By omitting the version number in the URI, the system targets the latest version of the secret, which is often desirable for dynamic credential rotation but requires careful management to avoid breaking changes if older versions are needed. This method ensures that the raw secret never appears in the Application Settings blade in the Azure Portal, nor in any logs or deployment packages, significantly reducing the attack surface.

Option A, App:Settings:Secret:mykeyvault:token, represents a hierarchical configuration path format often seen in.NET Core appsettings.json files or environment variable mappings. However, storing this literal string in the Azure Functions configuration does not trigger any resolution mechanism. The platform will treat it as a static string value. If the function code attempts to read a setting with this key, it will receive the literal path string, not the secret content. Furthermore, Azure Functions does not natively parse this specific nested structure to fetch secrets from Key Vault without additional custom middleware or logic, which contradicts the requirement for a simple configuration-based solution.

Option B, KeyVault:mykeyvault;Secret:token, resembles a connection string format or a legacy configuration pattern. Similar to Option A, this is just a plain text string. It lacks the specific directive syntax that the Azure Functions infrastructure recognizes to initiate a secure lookup against Key Vault. Consequently, the function would see this string as the actual value of the configuration setting, leading to authentication failures when trying to call external APIs because the token value itself would be invalid.

Option D, AZUREKVCONNSTR_ https://mykeyvault.vault.azure.net/secrets/token/, attempts to use a naming convention often associated with environment variables or specific connector prefixes. While some services might support prefixed keys for automatic injection, the standard and documented way for Azure Functions to resolve Key Vault secrets via App Settings is strictly through the @Microsoft.KeyVault(...) syntax. The prefix AZUREKVCONNSTR_ is not recognized by the native resolver. Even if it were intended to mimic a connection string style, without the proper protocol handler syntax, the runtime cannot extract the secret URI and resolve it. This option creates a malformed expectation for the runtime engine.

Underpinning this behavior is the requirement that the Azure Function must have a System-Assigned or User-Assigned Managed Identity enabled, and that Identity must have appropriate access policies (specifically 'Get' permission) on the Key Vault mykeyvault. The configuration setting itself is merely the pointer; the identity provides the credentials to traverse that pointer. Without the Managed Identity, even the correct syntax in Option C would fail during resolution. However, among the choices provided, only Option C uses the syntactically correct directive required by the Azure Functions platform to bridge the gap between local configuration and remote secret storage.

Official Reference

https://learn.microsoft.com/en-us/azure/app-service/app-service-key-vault-references

This link opens the official vendor documentation in a new tab.

Exam Strategy

When configuring secrets for Azure Functions, always look for the @Microsoft.KeyVault(...) syntax in the options. This is the standard, built-in method for resolving Key Vault references directly in App Settings without modifying code. Remember that the Managed Identity of the Function App must have 'Get' permissions on the Key Vault for this resolution to succeed at runtime.

Practice All AI-200 Questions

Access 69 questions with complete answers and detailed explanations.

View Full AI-200 Practice Test →

← Back to AI-200 Study Guide