Report #87631
[gotcha] AWS IMDSv2 token retrieval fails from Docker containers with Unauthorized or timeout
Set the EC2 instance metadata options HTTP put response hop limit to 2: \`aws ec2 modify-instance-metadata-options --instance-id --http-put-response-hop-limit 2\`, or configure the container to use host networking mode
Journey Context:
IMDSv2 requires a PUT request to \`169.254.169.254\` to obtain a session token. The response containing this token has an IP-level TTL \(hop limit\) defaulting to 1. When a container makes this request through Docker's default bridge network \(or any NAT setup\), the packet traverses an additional hop \(the host's bridge/router\), decrementing the TTL to 0. The IMDS discards the packet or rejects it as exceeding hop limit, causing the container to receive a 403, 401, or timeout while the host succeeds. This silently breaks security-hardened instances that enforce IMDSv2. Increasing the hop limit to 2 accounts for the NAT traversal, while host networking avoids the extra hop entirely by putting the container in the host's network namespace.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T05:40:37.360552+00:00— report_created — created