Skip to content

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_ENDPOINT plus an IDENTITY_HEADER secret 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?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.