Lesson 3 of 9 · 24m
Cloud Metadata: The Credential Machine Next Door
Why 169.254.169.254 matters across AWS, Azure, and GCP, how instance identity turns SSRF into account compromise, and what IMDSv2 changes.
The reason SSRF escalated from "weird network bug" to "cloud breach primitive" is a tiny link-local service listening beside your workload. Cloud metadata endpoints exist so instances can bootstrap identity and configuration. That convenience becomes catastrophic when arbitrary outbound requests can reach them.
The classic AWS path
The instance metadata service is reachable at 169.254.169.254 from the instance. With IMDSv1, a plain GET is enough:
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/app-roleThe second response can contain temporary credentials:
{"AccessKeyId":"ASIA...","SecretAccessKey":"...","Token":"...","Expiration":"2026-11-30T04:12:00Z"}Those credentials are not the server's shell password. They are the instance role. If that role can read production S3 buckets, publish to queues, or decrypt KMS data, the attacker inherits that power.
IMDSv2 helps, but it is not magic
IMDSv2 requires a session-oriented PUT first:
TOKEN=$(curl -sS -X PUT -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600' http://169.254.169.254/latest/api/token)
curl -sS -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/This stops many basic SSRF exploits because attackers often control only the URL, not method and headers. It does not help when the vulnerable feature can issue POST/PUT requests, proxy arbitrary headers, or reach a container-level metadata endpoint with different semantics. Enforce IMDSv2; do not declare victory because it exists.
Azure and GCP have their own flavors
Azure Instance Metadata Service:
curl -H 'Metadata: true' 'http://169.254.169.254/metadata/instance?api-version=2021-02-01'
curl -H 'Metadata: true' 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/'GCP metadata server:
curl -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/tokenThe exact URL differs; the architectural problem is identical: network-adjacent identity bootstrap data.
Containers blur the boundary
In Kubernetes, SSRF may reach pod metadata, the Kubernetes API using a mounted service account token, or a node metadata endpoint depending on cloud and network policy. A token mounted at /var/run/secrets/kubernetes.io/serviceaccount/token is not fetched over HTTP by SSRF, but the API server it unlocks may be reachable.
The questions that matter:
- Is the instance role attached at all?
- Are temporary credentials available through a network endpoint?
- Does the workload need those permissions for its normal job?
- Are hop limits and network policies configured so server-side requests cannot reach the endpoint?
Field notes
169.254.169.254is a target, not the whole target list; aliases, IPv6 forms, proxies, and vendor endpoints matter.- IMDSv2 is a speed bump, not a substitute for egress control and least privilege.
- The severity of metadata SSRF is bounded by the attached role's permissions, which is why broad instance roles are recurring breach multipliers.
- If a workload does not need instance credentials, remove the role or block metadata access at the network layer rather than trusting application validation.
Was this lesson helpful?