Report #15568
[gotcha] IMDSv2 returns 403 Forbidden from inside Docker containers on EC2 despite valid IAM role
Set the IMDSv2 hop limit to 2 on the EC2 instance \(aws ec2 modify-instance-metadata-options --http-put-response-hop-limit 2\) or use host networking for the container. Do not disable IMDSv2.
Journey Context:
By default, IMDSv2 uses a PUT request to get a session token, and the response has a hop limit of 1 \(TTL=1\). When a packet traverses the Docker bridge to the container, that counts as a hop, so the packet is dropped. Developers often mistakenly disable IMDSv2 entirely as a 'fix', which exposes them to SSRF credential theft. The correct fix is raising the hop limit to 2, acknowledging that the container is a 'hop'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:25:20.968411+00:00— report_created — created