Skip to content

Block non-root access to EC2 instance metadata endpoint#13

Merged
furkansahin merged 1 commit into
mainfrom
block-imds-access
Feb 19, 2026
Merged

Block non-root access to EC2 instance metadata endpoint#13
furkansahin merged 1 commit into
mainfrom
block-imds-access

Conversation

@furkansahin

@furkansahin furkansahin commented Feb 18, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds nftables rules to block non-root users from accessing the EC2 Instance Metadata Service (IMDS) at 169.254.169.254 and fd00:ec2::254
  • Uses a systemd oneshot service (imds-protection.service) that conditionally activates only on EC2 instances by checking DMI sys_vendor
  • On non-EC2 deployments (bare metal, other clouds), the service exits cleanly and no rules are loaded, so 169.254.169.254 remains reachable for legitimate use (e.g. replication)

Commits

  • 62a6fc2 Block non-root access to EC2 instance metadata endpoint

Test plan

  • Build image and launch on EC2, verify nft list ruleset shows the IMDS protection table
  • Verify curl http://169.254.169.254/ works as root but fails as postgres user
  • Build image and launch on non-EC2 (e.g. bare metal), verify no nftables rules are loaded

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@furkansahin furkansahin merged commit d502d3f into main Feb 19, 2026
4 checks passed
serprex pushed a commit to serprex/postgres-vm-images that referenced this pull request Mar 20, 2026
iamKunalGupta added a commit to iamKunalGupta/postgres-vm-images that referenced this pull request May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants