What is IMDSv2 and why enforce it?
IntermediateConceptEC2, Auto Scaling and Load Balancing
Answer
IMDSv2 is the session-oriented instance metadata service: you first PUT to get a token, then pass it as a header. It blocks SSRF-style attacks that trick an app into making a simple GET (the 2019 Capital One breach pattern) and rejects requests with X-Forwarded-For.
TOKEN=$(curl -sX PUT http://169.254.169.254/latest/api/token \
-H "X-aws-ec2-metadata-token-ttl-seconds: 300")
curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id
Enforce with --metadata-options HttpTokens=required; set HttpPutResponseHopLimit=2 for containers on the host.