Credential Exposure via IMDS
What you'll learn: How instance roles automatically deliver temporary credentials through IMDS, turning metadata access into a powerful attack vector with cascading permissions.
The Credential Delivery Mechanism
When you attach an IAM role (AWS) or service account (GCP) to a cloud instance, the cloud provider automatically delivers temporary credentials through IMDS. These aren't static API keys—they're short-lived tokens that rotate automatically, typically valid for 1-6 hours.
The instance retrieves these credentials by querying a special IMDS endpoint:
# AWS example endpoint
http://169.254.169.254/latest/meta-data/iam/security-credentials/[role-name]
The response contains an access key, secret key, session token, and expiration time—everything needed to make authenticated API calls as that role.
The Blast Radius Problem
Here's the critical security issue: any code running on that instance can retrieve these credentials. This includes:
- Your application code (intended)
- Vulnerable dependencies with SSRF flaws (unintended)
- Malware or attacker shells (catastrophic)
Think of it like leaving a master keycard on every employee's desk. If someone compromises one desk, they get the keycard.
The blast radius is determined by the IAM role's permissions. If the role has s3:* permissions across all buckets, a compromised instance means the attacker can access every S3 bucket in your account. The instance becomes a pivot point for lateral movement.
Real-World Impact
A single SSRF vulnerability that can reach IMDS transforms into full cloud account compromise if the instance role is overly permissive. Attackers extract credentials, then use them from their own infrastructure until they expire (and often set up persistence before then).
Key Takeaway: IMDS credential exposure turns infrastructure access into identity compromise—the permissions of the instance role become the attacker's permissions, making role scoping and IMDSv2 adoption critical defenses.