How do you block containers from reaching the AWS instance metadata service?
AdvancedProductionImage Security & Hardening
Answer
Enforce IMDSv2 with hop limit 1 so a container (one extra hop) cannot get tokens:
aws ec2 modify-instance-metadata-options --instance-id i-0abc --http-tokens required --http-put-response-hop-limit 1
Or add an iptables DROP for 169.254.169.254 in DOCKER-USER. On EKS use IRSA/Pod Identity instead of node roles.
More on Image Security & Hardening
Why should containers not run as root, and how do you enforce it?BeginnerWhat is a distroless image and what are the trade-offs?BeginnerHow do you scan an image with Trivy and fail a CI build on serious findings?BeginnerHow do you manage Trivy false positives and accepted risks?IntermediateWhich `docker run` flags make up a hardened runtime baseline?BeginnerWhat does `no-new-privileges` protect against?Beginner