Course contentsShow
← Security
Lesson 1927 of 3,05239. Cloud Security - Compute and ServerlessFree lesson

Instance Metadata Service (IMDS) Security

Understanding IMDS versions, SSRF risks, and enforcing IMDSv2 with hop limits and token requirements.

Instance Metadata Service (IMDS) Security

You'll learn how to protect cloud instances from metadata-based attacks by understanding IMDS versions and enforcing secure access controls.

What Is IMDS?

The Instance Metadata Service is like a private information desk inside each cloud VM. Your instance can query http://169.254.169.254/latest/meta-data/ to retrieve its own configuration—IAM role credentials, network settings, user data scripts, and more. This is incredibly useful for automation, but also a prime target for attackers.

The SSRF Risk

If an attacker finds a Server-Side Request Forgery (SSRF) vulnerability in your application, they can trick your server into making requests to the metadata service. Think of it as manipulating a trusted employee to retrieve sensitive files they shouldn't access. The attacker could steal temporary IAM credentials and escalate their access across your cloud environment.

IMDSv1 vs IMDSv2

IMDSv1 uses simple HTTP GET requests—no authentication required. Any code running on the instance can access metadata freely.

IMDSv2 adds defense-in-depth through a session-oriented approach. The instance must first request a session token using a PUT request, then include that token in subsequent metadata queries. This blocks most SSRF attacks because attackers typically can't control HTTP methods through vulnerable applications.

Enforcing IMDSv2

Set the hop limit to 1, which prevents forwarded requests from containers or proxies. Configure instances to require IMDSv2 (reject IMDSv1 requests entirely). These settings ensure only direct, authenticated requests from the instance itself succeed.

Key Takeaway: Enforce IMDSv2 with hop limit 1 and disable IMDSv1 to protect instance credentials from SSRF attacks—treating metadata access like any other privileged operation requiring authentication.