Disabled metadata protections: IMDSv2 and why it blunts SSRF
Cloud instance metadata services hand out credentials to code on the machine. How IMDSv2 session tokens on AWS and required headers on other clouds stop simple SSRF from reaching them, and how to enforce it.
Diagram
Version 1 versus version 2 metadata access
Step 1 of 4
v1
A single GET from the instance returns metadata, so a server-side request forgery bug can reach it.
# v1 # A single GET from the instance returns metadata, so a # server-side request forgery bug can reach it.
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Optional tokens
- What fails
- Instances that still accept version 1 requests.
- Who is affected
- Credentials of the instance role.
- What you would notice
- HttpTokens set to optional.
- What you change
- Set required, after checking SDK versions.
Hop limit
- What fails
- A hop limit above 1 lets containers on the host reach the metadata service.
- Who is affected
- Pods sharing the node’s role.
- What you would notice
- Hop limit 2 or more on nodes that do not need it.
- What you change
- Use 1 unless a workload needs more, and give pods their own identity.
Role scope
- What fails
- Even with IMDSv2, the instance role decides the damage.
- Who is affected
- Data the role can reach.
- What you would notice
- Instance roles with broad permissions.
- What you change
- Scope instance roles tightly.
The version 2 exchange on your own instance
Run this on a lab instance to see the two steps. Once tokens are required, the last request, a plain GET without the token header, returns 401.
$ TOKEN=$(curl -sX PUT http://169.254.169.254/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 300")
$ curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id
i-0abc123
$ curl -s -o /dev/null -w "%{http_code}\n" http://169.254.169.254/latest/meta-data/instance-id
401Finding instances still accepting version 1
Query metadata options across instances, and use the CloudWatch MetadataNoToken metric to see whether anything still calls version 1 before you enforce.
$ aws ec2 describe-instances --query "Reservations[].Instances[?MetadataOptions.HttpTokens=='optional'].InstanceId" --output text i-0abc123 i-0def456
Other providers
Azure IMDS requires a Metadata: true header and GCP requires Metadata-Flavor: Google. Those headers stop many simple SSRF bugs, because the attacker usually cannot set custom headers. The fixed link-local metadata address is the same on all three; block it from application egress where workloads do not need it.
Check yourself
Recognition and the fix. Nothing here is a procedure.
Why does IMDSv2 stop many SSRF bugs?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.
- 01Cloud security fundamentals: shared responsibility, identity, and the audit trailWhat the provider secures and what you do, why identity is the cloud perimeter, and the first read-only commands to understand an AWS, Azure, or Google Cloud account you are responsible for.
- 02Cloud accounts and container environmentsCloud failure is usually identity and exposure.
- 03Workload identity instead of static keysA long-lived access key on a laptop or in a repository is a session that does not expire.
- 04Open security groups: SSH, RDP, and databases reachable from anywhereFirewall rules that allow 0.0.0.0/0 to management or database ports expose servers to constant scanning.
- 05Public object storage: finding and closing open buckets and containersBuckets made public by mistake remain one of the most common cloud leaks.