Lesson 6 of 14 · 15m
Managed Identity: The Credential That Isn't a Credential
Azure IMDS mints tokens for the identity attached to the VM — which moves the attack surface to whatever can reach 169.254.169.254.
There is no secret to steal
A managed identity is an Entra service principal that Azure creates and manages. System-assigned is bound to the resource lifecycle — delete the VM and the principal dies with it. User-assigned is a standalone Azure resource (az identity create) attachable to as many workloads as you want, carrying its own RBAC story and its own attack surface. Either way: no client secret, no certificate, nothing to rotate, nothing to leak from a repo. That is the design goal.
The mechanism:
curl -H 'Metadata: true' 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://vault.azure.net/'The Instance Metadata Service returns plain JSON — access_token, expires_in, token_type — for every identity attached to the VM, scoped to the resource audience you asked for. Cache it for expires_in; re-minting per request is a latency tax nobody needs to pay. Metadata: true is not decoration — it is the SSRF tripwire. A blind request-forgery bug that can only fire a bare GET can't set the header, so naive SSRF hits a wall. AWS's original IMDSv1 had no such requirement; Capital One, disclosed July 2019, was SSRF → IMDS credentials → S3 exfiltration of ~100 million records. Azure learned the lesson AWS paid for. GCP's metadata.google.internal requires Metadata-Flavor: Google for the same reason — same dispenser, different clothes.
The boundary moved, it didn't vanish
The wrong mental model: "the VM has no credential, so token theft is gone." The VM has a token dispenser. Anything executing on the box — your app, a dependency's code path, an attacker's webshell — can reach 169.254.169.254 and mint. Two refinements matter:
- SSRF that proxies through your own application still works when the app sets headers. App Service doesn't use IMDS at all — it exposes
IDENTITY_ENDPOINTplus anIDENTITY_HEADERsecret in env vars, which keeps the token endpoint reachable to anything that can read the environment. - On AKS the modern path is Workload Identity: OIDC-federated credentials on a managed identity, projected into the pod as a token file — no IMDS hop at all, and the federation subject is the Kubernetes service account.
Two details the docs bury. The resource parameter is the token's audience — https://management.azure.com/ for ARM, https://vault.azure.net for vaults, https://storage.azure.com/ for storage — and each minted token works only for its audience; there is no omnibus token. For inventory, az identity list shows user-assigned identities and .identity on az vm show / az webapp show shows what's attached where — the attach graph is the blast-radius map, so audit it like an IAM policy.
The question is never "does the box have an identity" but "what is the blast radius of arbitrary code on this box." Managed identity sharpens that: RCE equals the identity's RBAC scope.
And there's a path that needs no code exec on the box at all: Microsoft.Compute/virtualMachines/runCommand/action, included in Contributor, runs a script as root on the VM (SYSTEM on Windows) — az vm run-command invoke --command-id RunShellScript --scripts 'curl ...'. Root curls IMDS. Whatever the managed identity can do — Key Vault Secrets User, Storage Blob Data Contributor — Contributor now does, holding the token only as long as the command output window. No SSH, no exploit chain, one documented permission.
Land it
Use managed identities everywhere you would have registered an app with a client secret. Scope the identity's RBAC to the resource it actually needs — Storage Blob Data Reader on one account, not Contributor on the subscription. Don't share one user-assigned identity across trust boundaries to save a resource. Alert on runCommand invocations in the Activity Log; they are privilege-escalation-shaped. And treat allowSharedKeyAccess/listKeys-adjacent paths the same way — any route that hands out ambient credentials is the same dispenser with a different address.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
AWS Emulator Puts AWS on Your Laptop. Keep Your IAM Tests Off It.
AWS released AWS Emulator on November 11, a free local server that answers AWS API calls on 127.0.0.1 with per-run keys and fresh certificates.
Big Tech Plans to Work with the Public Sector for Cybersecurity
Both Microsoft, Inc. and Alphabet, Inc. will put a combined $30 billion dollars into cybersecurity over the next five years and work with the public sector on several initiatives to help improve cybersecurity.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.
What is SSRF? Server-Side Request Forgery and the Attack That Breached Capital One
SSRF tricks your server into making requests to internal systems — cloud metadata services, internal APIs, AWS credentials endpoints. It turned a WAF misconfiguration into 100 million stolen Capital One records