Hop Limit and Network-Level IMDS Protection
You'll learn how to use HTTP hop limits to block forwarded requests from containers and nested systems attempting to access the host instance's metadata service.
The Problem: Nested Network Attacks
Even with IMDSv2's session token requirement, attackers who compromise a container or nested VM on your cloud instance can still potentially access IMDS if network routing allows it. The metadata endpoint (169.254.169.254) is typically reachable from any process on the instance—including containers running inside Docker, nested virtualization layers, or application servers that might be tricked via SSRF.
How Hop Limit Protection Works
The hop limit (also called TTL—Time To Live) is a network packet field that decrements by 1 at each routing hop. By configuring IMDS to require TTL=1, you ensure that only processes running directly on the host instance can reach the metadata service. Any request that passes through even one network hop (like from a container through Docker's network bridge) will have its TTL decremented and be rejected by IMDS.
Think of it like a movie ticket that expires after passing through one doorway—containers behind an additional network layer can't use it.
Implementation Strategy
On AWS EC2, you can configure the hop limit when modifying instance metadata options:
--http-put-response-hop-limit 1
This ensures packets must originate from the host's primary network interface. Containers using bridge networking or NAT will find their requests blocked because the packet traverses at least one additional hop.
Key Takeaway: Configure HTTP hop limit to 1 on IMDS to create a network-level barrier that prevents containers, nested VMs, and proxied requests from reaching instance credentials—even if IMDSv2 tokens are obtained.