Azure Key Vault Explained: The One Secret Tutorials Never Remove
Moving every secret into Key Vault leaves exactly one behind — the credential that opens the vault. A managed identity is what finally gets you to zero.
You moved every secret into Key Vault. The database password, the payment provider key, the Maps key, the OpenAI key — all six, gone from config. Nice work.
Now open appsettings.json. There’s still a ClientId and a ClientSecret in there. You have exactly one secret left, and it’s the worst one: it opens all the others.
What is Azure Key Vault?
Azure Key Vault is a managed store for the three kinds of sensitive material an app needs, with an audit log of every read:
Kind
What it holds
Can the app read the raw value?
Secrets
Connection strings, API keys — anything that’s just a string
Yes
Keys
Cryptographic keys
No — you send data to be signed or wrapped
Certificates
TLS certs, with auto-renewal from an integrated CA
Yes, as a secret
What Key Vault tutorials leave out
The credential that opens the vault. Almost every tutorial ends at “and now your secrets are in the vault”, with the app authenticating using a client id and secret that are… in the config file.
You didn’t remove a secret. You swapped six for one master secret, in the same file, in the same repo. And that one expires — usually at 2am, usually 24 months after the person who created it left the company.
How does managed identity remove the last secret?
Azure gives the resource itself an identity. No password, no certificate, nothing on disk. The platform hands short-lived tokens to your App Service and rotates them for you.
Figure 1 — the tutorial way leaves one secret behind; a managed identity removes it.
Here’s the whole change in ASP.NET Core:
builder.Configuration.AddAzureKeyVault( new Uri("https://msdev-kv.vault.azure.net/"), new DefaultAzureCredential());
That’s it. DefaultAzureCredential uses your az login on your laptop and the managed identity once deployed, so the same line works in both places with no #if DEBUG.
Access policies vs RBAC
RBAC. Key Vault has two permission models, and access policies are the older, all-or-nothing one. With Azure RBAC you grant Key Vault Secrets User — read only, secrets only. Your app has no business writing, deleting or listing keys, so don’t give it the ability to.
Settings to turn on before you need them
Soft delete and purge protection. Soft delete is on by default now; purge protection isn’t. Purge protection is the one that stops a compromised identity from destroying your secrets permanently.
Diagnostic logging to Log Analytics. “Who read which secret, and when” is the whole reason to use a vault instead of an environment variable.
A firewall or private endpoint, so the vault isn’t reachable from the internet.
Expiry dates on secrets, plus the Event Grid near-expiry event wired to something that pages a human.
For Azure-to-Azure calls, skip the vault as well. Azure SQL, Storage, Service Bus, Cosmos DB and Azure OpenAI all accept managed identity directly. A secret you never created can’t leak, can’t expire, and can’t be rotated wrong.
Key takeaways
Authenticating to Key Vault with a ClientId/ClientSecret just moves the problem into one master secret.
Managed identity plus DefaultAzureCredential removes the last stored credential, and works the same locally and in Azure.
Grant Key Vault Secrets User through RBAC so the app can read secrets and nothing else.
Turn on purge protection and diagnostic logging before an incident, not during one.
AddAzureKeyVault caches at startup — set a ReloadInterval or rotation silently needs a redeploy.
Answer the questions, then submit to see your score and the explanations. Each question is tagged with the
certification exam that covers the skill:
SC-500, AI-200, AZ-305.
SC-500Manage identity, access, and governance
A managed identity gives the resource itself an identity, with no password or certificate on disk, and Azure rotates its tokens. DefaultAzureCredential uses az login on your laptop and the managed identity in Azure, so one line works in both places.
SC-500Manage identity, access, and governance
Key Vault Secrets User is read-only and secrets-only. The app has no business writing, deleting or listing keys, so it shouldn't be able to, even if it is compromised. RBAC replaces the older, coarser access policy model.
AI-200Implement secure Azure solutions
The configuration provider reads once at startup and caches. Without a ReloadInterval, the app keeps the old value until it restarts, so your 'no redeploy' rotation quietly needs one.
SC-500Secure storage, databases, and networking
Soft delete is on by default, but a deleted secret can still be purged. Purge protection blocks that permanent delete. Logging tells you who read what, and expiry dates warn you before a secret lapses.
AZ-305Design identity, governance, and monitoring solutions
Azure SQL, Storage, Service Bus, Cosmos DB and Azure OpenAI all accept managed identity directly. A secret you never created can't leak, expire or be rotated wrong.
0 of 5 answered
These are practice questions written from this article, not questions taken from a real exam. Exam tags follow
the skills listed in each exam's official study guide on Microsoft Learn.
Azure Key Vault is a managed service that stores secrets (connection strings, API keys), cryptographic keys that never leave the vault, and TLS certificates with auto-renewal. Your application reads what it needs at runtime, and every read is logged, so nothing sensitive has to live in config files or source control.
Why is a ClientSecret used to authenticate to Key Vault still a problem?
Because it replaces several secrets with one master secret, still stored in the same config file and the same repository. That credential eventually expires — often two years later, after whoever created it has left — and it leaks the same way any other hardcoded secret does.
How does DefaultAzureCredential work in both local development and Azure?
It tries a sequence of credential sources and uses the first one available: your az login session on your laptop, and the resource's managed identity once deployed. The same line of code authenticates in both places, with no #if DEBUG branching.
Should Key Vault use access policies or Azure RBAC?
Azure RBAC. Access policies are the older, coarser model. RBAC lets you grant a narrow role like Key Vault Secrets User — read-only, secrets-only — so the application identity cannot write, delete or list keys even if it is compromised.
Does a rotated Key Vault secret update a running ASP.NET Core app?
Not by default. AddAzureKeyVault reads secrets at startup and caches them, so the running app keeps the old value until it restarts. Pass a ReloadInterval in the options so rotation takes effect without a redeploy.
HTTPS, authentication, authorization, secrets, then monitoring — five layers for a mobile API on Azure, and why doing them out of order defeats the point.
An APK or IPA is a zip file. Anything hardcoded inside it, including your API key, is already public — and here is how to get it off the phone for good.
viewsRead →
Ask Suthahar
Answers from the article instantly
MSDEVBUILD
/ blog Multi-Stack Dev Build · by Suthahar Azure
Since 2007
India · Malaysia Speaks English and Tamil
About the speaker
Suthahar Jegatheesan
Cloud, AI & Mobile Solutions Architect
Helping the IT industry since 2007, with a passion for giving developers a helping
hand across India and Malaysia.
19+years in IT
5M+views
50+sessions
15,000+developers
Recognition
Microsoft Azure Content Hero
C# Corner MVP
Top 100 Microsoft Azure Blogs
Microsoft Certified Trainer
LinkedIn in/jssuthahar
What is Azure Key Vault used for?
Azure Key Vault is a managed service that stores secrets (connection strings, API keys), cryptographic keys that never leave the vault, and TLS certificates with auto-renewal. Your application reads what it needs at runtime, and every read is logged, so nothing sensitive has to live in config files or source control.
Why is a ClientSecret used to authenticate to Key Vault still a problem?
Because it replaces several secrets with one master secret, still stored in the same config file and the same repository. That credential eventually expires — often two years later, after whoever created it has left — and it leaks the same way any other hardcoded secret does.
How does DefaultAzureCredential work in both local development and Azure?
It tries a sequence of credential sources and uses the first one available: your az login session on your laptop, and the resource's managed identity once deployed. The same line of code authenticates in both places, with no #if DEBUG branching.
Should Key Vault use access policies or Azure RBAC?
Azure RBAC. Access policies are the older, coarser model. RBAC lets you grant a narrow role like Key Vault Secrets User — read-only, secrets-only — so the application identity cannot write, delete or list keys even if it is compromised.
Does a rotated Key Vault secret update a running ASP.NET Core app?
Not by default. AddAzureKeyVault reads secrets at startup and caches them, so the running app keeps the old value until it restarts. Pass a ReloadInterval in the options so rotation takes effect without a redeploy.
Get notified about new articles
A new version is ready
Install MSDEVBUILD on your Home Screen
Install on iPhone or iPad
Apple only allows adding an app from Safari. Three quick taps:
Tap the Share button
— bottom bar on iPhone, top-right on iPad.
Scroll down and tap Add to Home Screen.
Tap Add, then open MSDEVBUILD from the new icon — it launches like an app, and only then can you turn on notifications.
You're not in Safari right now. Open blog.msdevbuild.com in Safari, then follow these steps.