You are deploying an ASP.NET Core web application to an Azure App Service. The application must retrieve secrets from an Azure Key Vault using a user-assigned managed identity. The application code uses DefaultAzureCredential from the Azure.Identity SDK to authenticate. Which sequence of steps should you perform to configure the environment and enable secure access?
- 1Create a user-assigned managed identity resource in your Azure subscription.
- 2Associate the user-assigned managed identity with the Azure App Service.
- 3Assign the Key Vault Secrets User role to the user-assigned managed identity on the Key Vault.
- 4Configure the AZURE_CLIENT_ID application setting on the App Service with the Client ID of the managed identity.
Answer
First, create the user-assigned managed identity. Second, associate the identity with the App Service. Third, assign the Key Vault Secrets User RBAC role to the identity on the Key Vault. Finally, configure the AZURE_CLIENT_ID application setting on the App Service with the identity's client ID.
Configuring a user-assigned managed identity requires a specific sequence: you must create the standalone identity resource, associate it with the App Service resource, grant the identity permission to access the Key Vault, and configure the AZURE_CLIENT_ID app setting. Setting the AZURE_CLIENT_ID environment variable is necessary because DefaultAzureCredential will not automatically know which user-assigned identity to use without it.
Step-by-Step Solution
Key Concept
Configuration workflow for user-assigned managed identities with DefaultAzureCredential