EC2 Metadata Endpoint Protection

The metadata endpoint can leak credentials via SSRF. The defenses that close it.

The threat

Server-side request forgery (SSRF) lets an attacker make the server fetch arbitrary URLs. The EC2 metadata endpoint at 169.254.169.254 is the high-value target because it returns IAM credentials, and once an attacker has IAM credentials they have whatever the instance role permits.

IMDSv2 enforcement

IMDSv2 requires a session token. The caller must first PUT to obtain a token, then GET with the token attached. Most SSRF vectors only support GET, which is what blocks the attack at the protocol layer.

Hop limit configuration

The metadata-token-response-hop-limit set to 1 stops containers from reaching the metadata endpoint through the host network because the response cannot traverse the extra hop. The setting specifically blocks containerised SSRF where the container would otherwise impersonate the host.

Network-layer defence

Network-layer defence is belt-and-braces protection. Pod egress policies and VPC security groups block 169.254.169.254 outbound from non-system workloads, and detection on egress attempts surfaces compromise indicators.

Operating with metadata protection

Operational discipline keeps the protection real. Standard launch templates enforce IMDSv2 and hop-limit-1; quarterly fleet audits surface non-compliant instances; the inventory of legacy IMDSv1 workloads is tracked as a migration backlog rather than indefinite deferral.