Interview Prep/DevSecOps/Cloud Security, CIS and Compliance

What is IMDSv2 and why should it be enforced?

IntermediateConceptCloud Security, CIS and Compliance
Answer

The EC2 instance metadata service at 169.254.169.254 hands out the instance role's temporary credentials. IMDSv1 answers any GET, so an SSRF bug turns into credential theft (the Capital One breach pattern). IMDSv2 requires a session token obtained with a PUT and a custom header, which most SSRF vectors cannot send, and the hop limit stops the token leaving the host.

aws ec2 modify-instance-metadata-options --instance-id i-0abc \
  --http-tokens required --http-put-response-hop-limit 1

On EKS nodes, hop limit 1 also blocks pods from reaching node credentials, which is what we want when pods use IRSA or Pod Identity. Enforce with an SCP or the account-level IMDS default setting.

All DevSecOps questions Roadmap: Policy as code

More on Cloud Security, CIS and Compliance