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.

Suthahar Jegatheesan By Suthahar Jegatheesan Published

Azure 5 min read —views
Article banner. On the left, the eyebrow "Azure, Securing a Mobile App" above the title "One secret left over" and the line "The credential that opens the vault. A managed identity removes it.", with the MSDEVBUILD wordmark and the author name below. On the right, three stacked boxes joined by arrows: a grey box reading "Six secrets into Key Vault, the tutorial ends here", an arrow labelled "the leftover" to a red box reading "A ClientSecret opens the vault, one master secret", and an arrow labelled "the fix" to a green box reading "A managed identity, nothing left to leak".

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:

KindWhat it holdsCan the app read the raw value?
SecretsConnection strings, API keys — anything that’s just a stringYes
KeysCryptographic keysNo — you send data to be signed or wrapped
CertificatesTLS certs, with auto-renewal from an integrated CAYes, 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.

Two columns. Left, "The tutorial way: one secret left": appsettings.json still holds a ClientId and ClientSecret that open the vault, Key Vault opens for anyone holding that secret, and two years later the secret expires at 2am after its creator has left. Right, "With managed identity: zero secrets": your app starts up with an Azure identity like a staff badge, Azure vouches for it with a short-lived token it renews automatically, Key Vault checks the Key Vault Secrets User role, and the secrets arrive in config with nothing secret in your code or repo.

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

  1. 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.
  2. Diagnostic logging to Log Analytics. “Who read which secret, and when” is the whole reason to use a vault instead of an environment variable.
  3. A firewall or private endpoint, so the vault isn’t reachable from the internet.
  4. Expiry dates on secrets, plus the Event Grid near-expiry event wired to something that pages a human.

When a rotated secret does not take effect

That’s the exact scenario in what happens when a key has to be rotated fast.

Better still: no secret at all

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.

Official documentation: Azure Key Vault overview and managed identities.

Earlier in this series: Secure a Mobile API in Five Steps: The Order Is the Whole Point and The Blast Radius of a Hardcoded API Key in a Mobile App.

Test yourself · 5 questions

Check what you learned

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.

  1. SC-500 Manage identity, access, and governance

    1. Every secret has moved to Key Vault, but appsettings.json still holds a ClientId and ClientSecret to open the vault. What removes that last secret?
  2. SC-500 Manage identity, access, and governance

    2. Which Azure RBAC role should the application identity get on the vault?
  3. AI-200 Implement secure Azure solutions

    3. You rotate a secret in Key Vault, but the running ASP.NET Core app keeps using the old value. Why?
  4. SC-500 Secure storage, databases, and networking

    4. Which Key Vault setting stops a compromised identity from destroying your secrets permanently?
  5. AZ-305 Design identity, governance, and monitoring solutions

    5. Your API calls Azure SQL, Storage and Azure OpenAI. What is better than storing their keys in Key Vault?
0 of 5 answered

Your result

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.

Was this useful?

Share

Found a mistake or an outdated step? Edit this page on GitHub

Frequently asked questions

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.
Article banner. On the left, the eyebrow "Azure, Securing a Mobile App" above the title "8,000 tries a minute" and the line "Nobody is typing. Make speed the losing move.", with the MSDEVBUILD wordmark and the author name below. On the right, three stacked boxes joined by arrows: a grey box reading "A script at 3am, against your login API", an arrow labelled "the attack" to an amber box reading "Rate limit per user or IP, years, not hours", and an arrow labelled "the rest" to a green box reading "Lockout, MFA, an alert, Azure is awake instead".

Next in this series · Part 8 of 10

4 min

Bot Attacks on a Mobile App: A Script Is Hitting Your Login Endpoint

A script tries 8,000 passwords a minute against your login API at 3am. Rate limiting, smart lockout and Defender for Cloud make speed the losing move.

Continue the series
Part 6 of 10Secure a Mobile API in Five Steps: The Order Is the Whole Point

Get new posts by email

New technical articles, Azure AI and GitHub Copilot updates, and upcoming events. No spam, unsubscribe anytime.

Comments

Your turn

How did Suthahar's articles help you?

If something here saved you time or unblocked a real project, I'd love to hear about it. Submissions are reviewed before they appear on the site.

0/1500 · minimum 10 characters

Never published — used only to verify your feedback.

Your name, company, and role appear publicly if published. Nothing else is collected.

↑↓ navigate ↵ open