Managed Identity for Azure Key Vault — App Service Access
You are developing an ASP.NET Core web API that is hosted on Azure App Service. The API needs to read secrets from Azure Key Vault at startup. You want to avoid storing any credentials in the application code or configuration. Which approach should you use?
Quick Answer
The answer is to enable the system-assigned managed identity for the App Service and configure Key Vault access policies to allow that identity. This approach is correct because a managed identity, automatically managed by Microsoft Entra ID, provides an Azure resource with an automatically generated service principal, allowing it to authenticate to Azure Key Vault without any credentials stored in code or configuration files. On the AZ-204 exam, this scenario tests your understanding of secure secret management in Azure compute environments, often appearing as a direct question about eliminating hardcoded credentials from App Service applications. A common trap is choosing a client secret or certificate-based approach, which violates the requirement to avoid stored credentials. Remember the memory tip: "Managed identity means no stored identity"—if the question demands zero credentials in code, always reach for a managed identity, not a service principal with a secret.
⚠ Common exam trap
A common mix-up: candidates think storing credentials in App Service application settings is acceptable because they are 'not in code,' but the question explicitly requires avoiding any stored credentials, making managed identity the only secure, credential-free approach.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Enable the system-assigned managed identity for the App Service and configure Key Vault access policies to allow that identity.
Enabling a system-assigned managed identity for the App Service allows it to authenticate to Azure Key Vault without any credentials stored in code or configuration. The managed identity is automatically managed by Microsoft Entra ID (now Microsoft Entra ID) and can be granted access to Key Vault secrets via access policies, eliminating the need for client IDs, client secrets, or connection strings.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use the Key Vault SDK with a client ID and client secret stored in App Service application settings.
Why it's wrong here
A client secret in application settings is itself a stored credential, directly violating the requirement to keep secrets out of code and configuration. It is tempting because the Key Vault SDK works and App Service settings are encrypted, but managed identity removes the secret entirely by issuing tokens from Microsoft Entra ID.
- ✓
Enable the system-assigned managed identity for the App Service and configure Key Vault access policies to allow that identity.
Why this is correct
System-assigned managed identity lets App Service authenticate to Key Vault without any stored secret, satisfying the no-credentials constraint. Microsoft Entra ID issues the token automatically, and a Key Vault access policy grants that identity secret read permissions, so the API retrieves secrets at startup credential-free.
- ✗
Use Microsoft Entra ID application roles to assign the App Service a role that allows reading secrets.
Why it's wrong here
Application roles govern authorisation decisions for users and apps, not Key Vault data-plane access; they grant no secret-read permission. It is tempting because Entra ID roles do control access to many Azure resources, and would be right for gating API endpoints by role membership rather than retrieving vault secrets.
- ✗
Store the Key Vault URL and a connection string with the secret in the application's app.config file.
Why it's wrong here
A connection string in app.config embeds a credential in configuration, directly violating the no-stored-credentials requirement. It is tempting because app.config is the traditional .NET location for connection strings, and would be correct for non-secret settings such as the Key Vault URI itself.
Go deeper
Related to this question
Learn chapter
API Management Policies and Transformation
Key term
Managed identity
A managed identity is an automatically managed service principal in Azure that allows your code to authenticate to any service that supports Microsoft Entra ID authentication without storing credentials.
Key term
Key Vault Secrets
Key Vault Secrets are secure containers in Microsoft Azure that store sensitive information like passwords, connection strings, and API keys, keeping them encrypted and accessible only to authorized applications and users.
About these practice questions
This AZ-204 question is part of Courseiva's 883-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on AZ-204
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. You have an Azure Function app that needs to retrieve a secret from Azure Key Vault at runtime. You want to avoid storing any credentials in code or configuration. Which mechanism should you use?
easy- A.Service principal with client secret
- ✓ B.Managed identity
- C.Access key
- D.Shared access signature (SAS)
Why B: Managed identity (B) is the correct mechanism because it allows the Azure Function app to authenticate to Azure Key Vault without storing any credentials in code or configuration. Azure automatically manages the identity and provides a token from Azure AD that the function can use to access the vault, eliminating the need for secrets or keys in the application.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This AZ-204 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-204 exam.