You configure an application setting in an Azure Function App to reference a database connection string stored in Azure Key Vault using the syntax: `@Microsoft.KeyVault(VaultName=kv-prod;SecretName=conn-string)`. During testing, the function fails to connect to the database. You inspect the function logs and discover that the environment variable for the connection string contains the literal string `@Microsoft.KeyVault(VaultName=kv-prod;SecretName=conn-string)` instead of the resolved secret value. What is the most likely cause of this issue?
- The Function App's managed identity has not been granted permissions to read secrets from the Key Vault.Cevap
- BThe Key Vault reference syntax is invalid because the secret version was not specified in the parameters.
- CKey Vault references require a user-assigned managed identity, but the Function App is configured with a system-assigned managed identity.
- DKey Vault references are only supported in Dedicated (App Service) hosting plans, and the Function App is currently deployed on a Consumption plan.
Cevap
The Function App's managed identity has not been granted permissions to read secrets from the Key Vault.
The correct answer is correct because when a Key Vault reference cannot be resolved by the runtime, it returns the raw reference string instead of the secret. The most common cause for this is that the Azure Function App's managed identity has not been granted the 'Get' secret permission in the Key Vault access policies or the 'Key Vault Secrets User' role in Azure role-based access control (RBAC).
Adım Adım Çözüm
Anahtar Kavram
Azure Functions Security Configuration and Key Vault References