You are developing an Azure Function App in C# that needs to retrieve a third-party API key stored as a secret in an Azure Key Vault. The Function App must authenticate to Key Vault securely using a system-assigned managed identity, adhering to the principle of least privilege.
Which five actions should you perform in sequence to configure the resources and write the code? To answer, arrange all the actions from the list of actions to the correct order.
- 1Enable the system-assigned managed identity on the Azure Function App resource.
- 2Assign the Key Vault Secrets User role to the Function App's managed identity on the target Key Vault.
- 3In the Function App code, instantiate a DefaultAzureCredential object from the Azure.Identity namespace.
- 4Instantiate a SecretClient from the Azure.Security.KeyVault.Secrets namespace, passing the Key Vault URI and the credential object.
- 5Call the GetSecretAsync method on the SecretClient object to retrieve the API key secret.
Answer
To retrieve the secret securely, first enable the system-assigned managed identity on the Function App. Next, assign the Key Vault Secrets User RBAC role to this identity to grant read access. In the code, instantiate a DefaultAzureCredential, pass it to initialize a SecretClient, and then call GetSecretAsync to retrieve the secret value.
The correct sequence begins by provisioning the identity, granting it read-only permissions via RBAC (Key Vault Secrets User), instantiating the credential provider (DefaultAzureCredential), initializing the Key Vault client (SecretClient), and executing the secret retrieval request.
Step-by-Step Solution
Key Concept
Establishing a secure connection from an Azure Function App to Azure Key Vault using modern C# SDKs and a managed identity with role-based access control.