You are developing an ASP.NET Core web application hosted on Azure App Service that retrieves database connection strings from Azure Key Vault. The application uses the DefaultAzureCredential class from the Azure.Identity library to authenticate. To meet security requirements, the managed identity must be exclusive to this App Service instance, and its lifecycle must be bound directly to the App Service. You run the command 'az webapp identity assign --name MyWebApp --resource-group MyResourceGroup' to configure the App Service. However, when the web application starts up and attempts to retrieve a secret, a credential retrieval error occurs. Which of the following actions should you perform to resolve this issue?
- Assign the Key Vault Secrets User role to the App Service's system-assigned managed identity at the Key Vault scope.Answer
- BAssign the Reader role to the App Service's system-assigned managed identity at the Key Vault resource group scope.
- CCreate a new user-assigned managed identity, assign it the Key Vault Secrets User role, and associate it with the App Service.
- DModify the web application code to pass a Client ID to the DefaultAzureCredential constructor.
Answer
Assign the Key Vault Secrets User role to the App Service's system-assigned managed identity at the Key Vault scope.
The correct action is to assign the Key Vault Secrets User role to the App Service's system-assigned managed identity at the Key Vault scope. Running the Azure CLI command enables the system-assigned managed identity on the App Service. However, to access the Key Vault secrets, the identity must be explicitly authorized. The Key Vault Secrets User role provides the necessary data-plane permissions for reading secrets. Using a system-assigned identity satisfies the requirement that the identity's lifecycle is bound directly to the resource.
Step-by-Step Solution
Key Concept
Authorizing a system-assigned managed identity to access Azure Key Vault secrets using Role-Based Access Control (RBAC).