Report #82380
[gotcha] EC2 IMDSv2 token requests failing from inside Docker containers with Unauthorized or timeout
Set the instance metadata option http-put-response-hop-limit to 2 \(minimum\) when using IMDSv2 with containerized workloads; alternatively, use IMDSv1 \(not recommended\) or provide credentials via IRSA/EKS Pod Identity instead of IMDS.
Journey Context:
IMDSv2 requires a PUT request to get a token, and the response has a hop limit \(TTL\) defaulting to 1. When a container runs on a Docker bridge network \(default\), the packet traverses the Docker bridge \(1 hop\), so when the response returns, its TTL is 0 and is dropped by the kernel. This manifests as intermittent 401s or timeouts only inside containers. Setting hop-limit to 2 accounts for the bridge hop. The alternative of using IMDSv1 removes the token requirement but opens the instance to SSRF attacks. Using IRSA/EKS Pod Identity removes the dependency on IMDS entirely, which is the most robust fix but requires OIDC setup.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:52:10.937731+00:00— report_created — created