You are configuring an Azure Function App (Runtime version 4.x) to securely retrieve database credentials from Azure Key Vault. Security guidelines require the following constraints:
- You must use a user-assigned managed identity.
- You must not enable or use a system-assigned managed identity.
- The Azure Functions hosting platform must natively resolve the secrets without custom code.
- The configuration must follow the principle of least privilege, ensuring no intermediate state exposes unresolved secrets to the application runtime or results in service resolution failures.
In which order should you execute the configuration steps to successfully enable the Function App to resolve the Key Vault secrets?
- 1Create a user-assigned managed identity in Microsoft Entra ID.
- 2Assign the user-assigned managed identity to the identity configuration of the Azure Function App.
- 3Assign the Key Vault Secrets User role to the user-assigned managed identity on the target Azure Key Vault.
- 4Configure the keyVaultReferenceIdentity property of the Function App to the resource ID of the user-assigned managed identity.
- 5Add an application setting to the Function App referencing the secret URI using the @Microsoft.KeyVault syntax.
Answer
The correct sequence is: first create the user-assigned managed identity, associate it with the Function App, grant it the Key Vault Secrets User role on the Key Vault, configure the keyVaultReferenceIdentity property of the Function App to use this identity, and finally add the application setting using the Key Vault reference syntax.
To resolve Key Vault references using a user-assigned managed identity, the identity must first exist. It then must be associated with the Function App. Granting Key Vault Secrets User permissions ensures that the identity can retrieve the secret. The keyVaultReferenceIdentity property must be configured to point to this identity before the application setting is created. If the application setting is added first, the platform will attempt to resolve the reference using either the system-assigned identity (which is disabled) or will fail to resolve because it does not know which user-assigned identity to use.
Step-by-Step Solution
Key Concept
Configuring Azure Functions to retrieve app settings securely using User-Assigned Managed Identity and Key Vault References.