You are developing an Azure Function App (V4 runtime) that must retrieve a database connection string from an Azure Key Vault using Key Vault references. You enable a system-assigned managed identity for the Function App. You then add the following environment variable to the Function App configuration:
DbConnectionString = @Microsoft.KeyVault(SecretUri=https://mykeyvault.vault.azure.net/secrets/db-conn/)
When the function executes, it fails to connect to the database. Upon inspection, you find that the function is retrieving the raw reference string @Microsoft.KeyVault(...) instead of the secret value.
Which of the following is the most likely cause of this behavior?
- AThe Key Vault reference syntax is invalid because it must use the App Configuration reference prefix @Microsoft.AppConfiguration instead of @Microsoft.KeyVault.
- BThe Function App is hosted on a Consumption plan, which does not support the resolution of Key Vault references.
- The system-assigned managed identity of the Function App has not been granted permission to retrieve secrets from the Key Vault.Answer
- DThe Key Vault reference syntax is invalid because it is missing the client ID of the system-assigned managed identity.
Answer
The system-assigned managed identity of the Function App has not been granted permission to retrieve secrets from the Key Vault.
The system-assigned managed identity of the Function App must be granted permissions to read secrets from the Key Vault. If this permission is missing, the Azure Functions runtime cannot retrieve the secret, and the environment variable is populated with the raw reference string instead of the secret value.
Step-by-Step Solution
Key Concept
Key Vault References and Managed Identities in Azure Functions
Estimated Time:1m 30s