6.7 EC2 Instance Metadata Service (IMDSv2): Fetching Role Credentials
Right, let’s talk about the magic box inside your EC2 instance that holds all its secrets: the Instance Metadata Service (IMDS). Think of it as a highly specific, internal-only concierge service that only your instance can call. It answers questions like, “Who am I?”, “What’s my purpose?”, and most critically, “What are my temporary AWS credentials so I can actually do things?” The original version, now called IMDSv1, was a bit too simple. You could just curl a URL and get what you wanted, no questions asked. This became a problem. If some malicious code somehow got onto your instance, or if your web application was tricked into making a Server-Side Request Forgery (SSRF) attack, it could just as easily fetch those powerful credentials. Not great.