Most engineers think…
Most engineers first hear "Key Vault" and think it's just "a fancy place to paste my passwords, then I copy them into my app's config." So they store the secret in the vault AND in appsettings.json, and call it secure.
Wrong — copying the secret back into your config defeats the entire point. Key Vault's actual move is identity, not a shared password: your app gets a managed identity that Microsoft Entra ID trusts, you grant that identity a least-privilege role (Key Vault Secrets User, read-only), and the app fetches the secret at runtime over TLS. The secret never touches your code, image, repo or logs — and when you rotate it, nothing redeploys. The locker is the easy part; the no-credential access is the whole idea.
① The secrets-in-code problem — and what Key Vault actually is
Meet Sneha, an L1 cloud engineer at Infosys. On her second day she opens a teammate's web app and finds this in appsettings.json: "ConnectionString": "Server=...;Password=Sup3r!". That one line is the most common security mistake in the cloud. The moment it is committed, the password lives in Git history forever, gets baked into the container image, and shows up in stack traces and CI logs. Rotating it means a code change and a redeploy across every environment.
This is not a hypothetical. Public Git scanners find tens of thousands of live cloud credentials a year, and most real breaches start not with a clever exploit but with a leaked key sitting in a repo or a log file. A hard-coded secret is a single shared password — once anyone sees it, everyone who can reach your database does too.
Azure Key Vault is the managed locker that fixes this. It stores three object types, and knowing the difference matters because the exam and the job both test it. A secret is any sensitive string — a DB password, an API key, a connection string. A key is a cryptographic key (RSA or EC) used for encrypt/decrypt, sign/verify or wrap/unwrap; in the Premium tier these are HSM-backed so the private key never leaves the hardware. A certificate is an X.509 cert plus its private key, with lifecycle management on top (auto-renewal from an integrated CA).
The four leak paths a hard-coded secret rides
Tap each card — these are the exact paths a password in code escapes to people who shouldn't have it.
Commit it once and it's in history forever; a later 'delete' commit doesn't remove it. So: anyone who clones the repo has it.
A config secret becomes a permanent image layer. So: every pull of that image — including from a public registry — leaks it.
Connection strings get printed in stack traces and CI output. So: your log store quietly becomes a password store.
Changing a hard-coded secret needs a code change + redeploy everywhere. So: nobody rotates, and old secrets live for years.
A hard-coded password is like writing your flat's door key number on the society gate-pass register that every visitor signs. Anyone who flips back a few pages has it. Key Vault is the building's access-card system instead: the gate doesn't hold a shared key, it checks who you are against a list and opens only for you. Lose your card and the guard revokes just that card — nobody has to re-key every door.
Rahul at TCS says: "I moved the DB password into Key Vault, but I also left a copy in appsettings.json so the app still works." What's wrong with this?
Pause & Predict
Predict: if a secret is committed to Git, then deleted in the very next commit, is it safe? Why or why not? Type your guess.
② Access models — RBAC vs access policy, managed identity & network controls
Now the part that decides whether your vault is actually secure: who can read what. Key Vault separates two distinct surfaces. The control plane manages the vault resource (create it, set firewall rules). The data plane is the data inside — reading a secret, using a key. Mixing these up is the #1 confusion on AZ-500, so keep them separate in your head: control plane = the locker; data plane = what's inside it.
For the data plane, Key Vault gives you two authorisation models, and the choice is not cosmetic. Vault access policies are the legacy model: a flat list on the vault granting operations like get/list secrets. Azure RBAC is the modern, recommended model — and starting with Key Vault API version 2026-02-01 it is the default for new vaults, matching the portal. The reason to prefer RBAC is concrete: with access policies, anyone holding Microsoft.KeyVault/vaults/write (such as a Contributor) can add themselves to the policy and read every secret. That is privilege escalation by design.
RBAC fixes that with granular built-in roles you scope at the vault or even a single secret: Key Vault Secrets User (read secret values — what an app needs), Key Vault Secrets Officer (manage secrets), Key Vault Crypto User/Officer (keys), Key Vault Certificate Officer (certs), and Key Vault Administrator (everything — give it to almost nobody). Crucially, granting access now requires Owner or User Access Administrator, so reading and granting are different powers. RBAC also plugs into PIM for time-limited access.
So how does an app authenticate without a credential to store? With a managed identity. Azure gives your App Service or VM its own identity in Entra ID; you grant that identity the Key Vault Secrets User role; at runtime the platform fetches a short-lived token for it. There is no password, no certificate, nothing for you to keep safe — the credential you would otherwise leak simply does not exist.
▶ Watch an app read a secret with zero stored credentials
An App Service at Flipkart needs the DB password. Follow the token and the authorisation decision step by step — notice no password is ever sent. Press Play for the healthy path, then Break it to see the failure.
# get the app's managed-identity principal id PID=$(az webapp identity show -g rg-shop -n shop-api --query principalId -o tsv) # scope the role to THIS vault only (least privilege) az role assignment create \ --assignee "$PID" \ --role "Key Vault Secrets User" \ --scope "/subscriptions/aaaa1111-2222-3333-4444-bbbb55556666/resourceGroups/rg-shop/providers/Microsoft.KeyVault/vaults/kv-shop-prod"
{
"principalId": "7f3c9d2e-1a4b-4c8e-9f0a-2b6d1e8c4a90",
"roleDefinitionId": ".../4633458b-17de-408a-b874-0445c86b69e6",
"roleDefinitionName": "Key Vault Secrets User",
"scope": ".../vaults/kv-shop-prod"
}Symptom: your code reads the secret fine locally (you're signed in as yourself) but in App Service you get 403 (Forbidden) ForbiddenByRbac or AKV10032 invalid issuer. Cause: the App Service's managed identity is turned on but has no role on the vault — your laptop succeeded because your account had access, not the app's. Fix: enable the system-assigned identity (Portal → App Service → Identity → System assigned → On) and assign it Key Vault Secrets User scoped to the vault. The role can take a few minutes to propagate.
Identity is half the story; the other half is the network. A vault on the public internet, even with perfect RBAC, is still reachable by every IP on earth to attempt access. Lock the door with the vault firewall, a private endpoint (so traffic stays on your VNet), or service endpoints, and then set public network access = Disabled. One real gotcha: disabling public access also locks you out of the portal unless you keep a management IP allowed or route through the private endpoint.
Priya at Wipro must give a new web app read-only access to one secret, and ensure a Contributor on the resource group can't quietly grant themselves the same access. Which approach fits?
Pause & Predict
Predict: under Vault access policies, why is a user with the 'Key Vault Contributor' role a privilege-escalation risk even if they were never granted data access? Type your guess.
③ Keys, certs & lifecycle — HSM, rotation, soft-delete, purge & logging
Secrets are just strings; keys and certificates are where Key Vault earns the 'vault' in its name. A key in the Standard tier is software-protected (types RSA, EC, oct). In the Premium tier you get HSM-backed keys (RSA-HSM, EC-HSM, oct-HSM) — the private key is created inside, and never leaves, the hardware module. You'd pick HSM keys for customer-managed encryption keys, compliance mandates, or anything where 'the key can't be exported, even by an admin' is a hard requirement.
Long-lived secrets are a liability, so Key Vault automates rotation. Keys support an automatic rotation policy (rotate N days after creation or before expiry; minimum interval 7 days), and you can also rotate on demand with az keyvault key rotate. Microsoft's baseline is to rotate encryption keys at least every two years, more often for sensitive workloads. Key Vault versions every object automatically, so a new version doesn't break data already encrypted with the old one.
Certificates get the most automation. Create a cert with an integrated CA (DigiCert or GlobalSign) and Key Vault handles end-to-end renewal — by default it auto-renews at 80% of the certificate's lifetime, configurable in the Issuance Policy as a 'Lifetime Action Type'. Services like App Service, Application Gateway and Front Door then pick up the new version automatically (usually within 24 hours, no restart). The classic outage this prevents: a TLS cert silently expiring on a Friday and taking the site down.
Two safety nets you must understand cold for AZ-500. Soft-delete is ON by default and cannot be disabled; the retention window is 7–90 days (default 90) and is fixed at vault creation. Purge protection is the stronger sibling: with it on, a soft-deleted object cannot be purged early by anyone — admin or attacker — until retention elapses. Purge protection is not on by default, and once you enable it you can't turn it back off. That irreversibility is the point: it stops a 'delete then purge' ransom/destruction attack.
# soft-delete is already ON by default; recover a vault someone deleted
az keyvault recover --name kv-shop-prod
# make destruction impossible until retention elapses (one-way switch)
az keyvault update --name kv-shop-prod -g rg-shop --enable-purge-protection true
# stream every secret/key/cert access to Log Analytics for Sentinel
az monitor diagnostic-settings create --name kv-audit \
--resource $(az keyvault show -n kv-shop-prod --query id -o tsv) \
--logs '[{"category":"AuditEvent","enabled":true}]' \
--workspace law-soc-prod{
"name": "kv-shop-prod",
"properties": {
"enableSoftDelete": true,
"softDeleteRetentionInDays": 90,
"enablePurgeProtection": true
}
}Three quick checks before you call a vault production-ready. 1) az keyvault show -n <vault> --query "properties.enablePurgeProtection" returns true. 2) --query "properties.enableRbacAuthorization" returns true (RBAC, not legacy policies). 3) A diagnostic setting with category AuditEvent exists and points at your Log Analytics workspace — without it, you have no record of who read which secret when, and Sentinel sees nothing.
Karthik at ICICI faces this
Karthik, an L1 on the cloud SOC, gets an alert: a production Key Vault was deleted at 02:14. Panic — it held the certs for the payments API.
A misfired Terraform destroy removed the vault. But soft-delete is ON by default (90-day retention), so the vault and its contents are not actually gone — they're in a soft-deleted state, recoverable.
He confirms the vault is recoverable rather than purged, and checks whether purge protection would have blocked an attacker from finishing the job.
Azure Portal → Key Vaults → Manage deleted vaults (or CLI: az keyvault list-deleted)Recover the vault with az keyvault recover --name kv-pay-prod; the certificates and their versions come back intact. Then turn ON purge protection so a future delete can't be followed by an early purge.
az keyvault show -n kv-pay-prod returns the vault; the payments cert versions are listable again; enablePurgeProtection is now true, so the same incident can't end in permanent loss.
Meera is asked: "An attacker with admin rights deletes our vault AND tries to purge it so we can't recover. Which single setting stops the permanent destruction?"
Pause & Predict
Predict: you enabled purge protection on a test vault, then want to delete the vault and immediately reuse its exact name for a new one. Why might that fail? Type your guess.
④ App integration done right — managed identity, references, gotchas & the cheat-sheet
Time to put it together the way you'll actually ship it. A web app needs a database password. The wrong way you've now seen. The right way has three moves: (1) store the password as a secret in Key Vault, (2) give the App Service a managed identity with the Key Vault Secrets User role, and (3) point the app's config at the vault with a Key Vault reference. The app code reads the same app setting it always did — but the value now comes from the vault.
The reference syntax is the one string to memorise: @Microsoft.KeyVault(SecretUri=https://kv-shop-prod.vault.azure.net/secrets/db-password/). Drop that as the value of an app setting (say DB_PASSWORD) and App Service resolves it from the vault using the app's managed identity — your code just reads DB_PASSWORD like any environment variable, never knowing it came from Key Vault. The big payoff: rotate the secret in the vault and the app picks up the new value with no redeploy (leave off the version in the URI so it always tracks 'latest').
# 1) put the password in the vault az keyvault secret set --vault-name kv-shop-prod \ --name db-password --value 'P@ss-from-secure-source' # 2) app reads it via a Key Vault reference (resolved by managed identity) az webapp config appsettings set -g rg-shop -n shop-api --settings \ DB_PASSWORD='@Microsoft.KeyVault(SecretUri=https://kv-shop-prod.vault.azure.net/secrets/db-password/)'
[
{
"name": "DB_PASSWORD",
"value": "@Microsoft.KeyVault(SecretUri=https://kv-shop-prod.vault.azure.net/secrets/db-password/)",
"slotSetting": false
}
]
# Portal shows a green 'Key Vault Reference' resolved tick once the role propagatesSymptom: in App Service → Configuration the setting shows Key Vault Reference with a red error, and the app falls back to an empty value. Three usual causes, in order: (1) the managed identity isn't turned on; (2) it has no Key Vault Secrets User role on that vault; (3) the vault firewall blocks App Service (you set public access = Disabled but never added the app's outbound IPs or a private endpoint / 'trusted services' exception). Fix them in that order and the tick goes green.
For your certification path, this lesson maps straight onto AZ-500 (Microsoft Azure Security Technologies) — specifically the 'Secure data and applications' area, objective 'configure and manage Azure Key Vault': access (RBAC vs access policies), managing secrets/keys/certificates, key rotation, soft-delete and purge protection, and backup/recovery. Nail the RBAC-vs-policy distinction and the soft-delete/purge pair and you've covered the highest-frequency Key Vault questions on the exam. Career-wise, this is daily bread for any Azure security or cloud-support role in India.
RBAC role vs the job it does — match them fast
Tap each card — interviewers love asking 'which role would you give X?' Least privilege means picking the smallest one that works.
Read secret VALUES — exactly what an app's managed identity needs. So: the default for workloads, nothing more.
Create/update/delete secrets. So: for the human or pipeline that MANAGES secrets, not the app that reads them.
Use keys (sign/wrap/decrypt) but not manage them. So: for an app doing crypto, not key administration.
Full data-plane control over everything. So: give to almost nobody — it's the broadest blast radius.
Cold, in 45 seconds: name the three object types (secrets, keys, certs); say why RBAC beats access policies (granular, per-secret scope, read≠grant, PIM, no Contributor self-grant); explain how an app reads a secret with no stored credential (managed identity + Key Vault reference); and state what soft-delete vs purge protection each guarantee. If you can do that without notes, you're ready for the next lesson and the AZ-500 Key Vault objective.
An interviewer asks Arjun: "How does your web app get its DB password at runtime without any secret in the code or pipeline?" Best answer?
🤖 Ask the AI Tutor
Tap any question — instant, scoped to this lesson. No login, no waiting.
Pre-curated from Azure docs + community Q&A, scoped to this lesson. For a live prod issue, paste your export into chat.techclick.in.
📝 Wrap-up assessment — six more
You've answered 4 inline. Six left. 70% (7 of 10) marks the lesson complete on your profile. Tap Submit all answers at the end.
🧠 In your own words
Type one line: In one line, how does a web app read a database password from Key Vault without any secret living in its code, image or pipeline? Then compare to the expert version.
🗣 Teach a friend
Best way to lock it in — explain it in one line to a teammate. Tap to generate a paste-ready summary.
📖 Glossary
- Azure Key Vault
- Managed store for secrets, keys and certificates, with access governed by Microsoft Entra identity rather than a shared password.
- Secret
- Any sensitive string an app needs at runtime — DB password, API key, connection string. Stored and versioned in Key Vault.
- Key
- A cryptographic key (RSA/EC/oct) for encrypt, sign or wrap operations. HSM-backed in the Premium tier.
- Certificate
- An X.509 certificate plus its private key, with lifecycle management (auto-renewal from an integrated CA) on top.
- Managed identity
- An identity Azure creates and manages for a resource; its credential is auto-rotated and never stored by you. Used to authenticate to Key Vault with no password.
- Azure RBAC
- Role-based access control: granular built-in roles assigned at a scope. The recommended Key Vault data-plane model; default for new vaults from API 2026-02-01.
- Vault access policy
- Legacy authorization model — a flat per-vault permission list. Carries a privilege-escalation risk because a Contributor can self-grant data access.
- Key Vault Secrets User
- Built-in RBAC role that grants read access to secret values — the least-privilege role an app's managed identity should hold.
- Key Vault reference
- An app-setting value @Microsoft.KeyVault(SecretUri=...) that App Service/Functions resolves from Key Vault at runtime, so the real value never sits in config.
- Soft-delete
- Deleting an object/vault only marks it deleted; it stays recoverable for 7–90 days (default 90). ON by default, can't be disabled.
- Purge protection
- While on, a soft-deleted object/vault can't be purged early by anyone — admin or attacker — until retention elapses. Optional and irreversible once enabled.
- HSM-backed key
- A key generated and held inside a FIPS 140-3 Level 3 hardware module (Premium tier); the private key never leaves the hardware in plaintext.
- Integrated CA
- A Certificate Authority (DigiCert or GlobalSign) partnered with Key Vault so it can request and auto-renew TLS certs for you.
- Private endpoint
- A private IP for the vault inside your VNet so data-plane traffic never crosses the public internet — the strongest network control.
📚 Sources
- Microsoft Learn — "Azure RBAC vs. access policies" (RBAC is the recommended Key Vault authorization model; access-policy escalation risk via Microsoft.KeyVault/vaults/write; granting needs Owner/User Access Administrator; PIM integration). learn.microsoft.com/azure/key-vault/general/rbac-access-policy
- Microsoft Learn — "Prepare for Key Vault API version 2026-02-01 and later — Azure RBAC as default" + "Azure Key Vault soft-delete" (RBAC default for new vaults; soft-delete ON by default, 7–90 day retention default 90, set at creation; purge protection optional, not default, irreversible). learn.microsoft.com/azure/key-vault/general/access-control-default · learn.microsoft.com/azure/key-vault/general/soft-delete-overview
- Microsoft Learn — "Use Key Vault references as app settings (App Service)" + "Authenticate to Azure Key Vault" (reference syntax @Microsoft.KeyVault(SecretUri=...); managed identity needs Key Vault Secrets User; no credential stored; rotation without redeploy). learn.microsoft.com/azure/app-service/app-service-key-vault-references
- Microsoft Learn — "About Azure Key Vault" + "Configure cryptographic key auto-rotation" + "Configure certificate autorotation" (Standard software vs Premium HSM keys RSA-HSM/EC-HSM, FIPS 140-3 Level 3; key rotation policy min 7 days; cert auto-renew at 80% lifetime via DigiCert/GlobalSign Issuance Policy). learn.microsoft.com/azure/key-vault/general/overview · learn.microsoft.com/azure/key-vault/certificates/tutorial-rotate-certificates
- Microsoft Community Hub / Microsoft Defender for Cloud blog — "Protecting Your Azure Key Vault: Why Azure RBAC Is Critical for Security" + "Cloud forensics: why enabling Azure Key Vault logs matters" (real-world access-policy self-grant escalation, identity-chaining via over-broad managed-identity roles, AuditEvent diagnostic logs to Log Analytics/Sentinel). techcommunity.microsoft.com/blog/microsoftdefendercloudblog/protecting-your-azure-key-vault-why-azure-rbac-is-critical-for-security/4407848
- Microsoft Learn — Exam AZ-500: Microsoft Azure Security Technologies study guide ("Secure data and applications" → configure and manage Azure Key Vault: access RBAC vs policies, secrets/keys/certs, key rotation, soft-delete, purge protection, backup/recovery). learn.microsoft.com/credentials/certifications/resources/study-guides/az-500
What's next?
You've seen how Azure proves WHO an app is and gives it least-privilege access to secrets. Google Cloud solves the same problem with a different mental model — members, roles and resource-hierarchy inheritance. Next we translate least privilege into GCP IAM, where a single over-broad role on a project can quietly expose everything beneath it.