Skip to content
cloudgrip

$ man instance-metadata-service

//Cloud and identity

What is the instance metadata service (IMDS)?

The instance metadata service (IMDS) is a local HTTP endpoint, usually at 169.254.169.254, that a cloud virtual machine calls to learn about itself and to fetch temporary credentials for its attached role. That makes it a prime target for server-side request forgery.

  • Cloud and identity
  • 3 min read
  • updated Nov 11, 2026

What the instance metadata service is

A cloud virtual machine uses the metadata service to find out who it is. Software on the machine sends an HTTP request to a fixed address, 169.254.169.254, and receives details such as the instance ID, region, network settings and startup scripts.

It also hands out credentials. When a machine has a cloud role attached, the endpoint returns short-lived access keys for it. This is a good design: applications get credentials without anyone storing a secret on disk, and the keys rotate on their own.

The address is link-local, which means it is reachable only from the machine itself. The weakness is that any process on the machine can call it, including a web application that can be tricked into making requests for someone else.

Why attackers target it

The metadata service turns a modest web flaw into cloud access. If an application fetches a URL supplied by a user, an attacker can point it at the metadata address. This is server-side request forgery, or SSRF.

Suppose an application has a link-preview feature:

output
GET /preview?url=http://169.254.169.254/latest/meta-data/iam/security-credentials/acme-web-role HTTP/1.1
Host: app.acme.test

On a machine that accepts simple metadata requests, the application fetches that address and shows the result: an access key, a secret key and a session token. The attacker can use them from anywhere until they expire, with every permission the role holds. From there the path often continues to privilege escalation inside the cloud account.

How the cloud providers protect it

Each provider adds a requirement that a simple forged GET request cannot meet.

Provider Protection
AWS IMDSv2 requires a session token, obtained with a PUT request and sent back in a header
Google Cloud Every request must carry the header Metadata-Flavor: Google
Azure Every request must carry the header Metadata: true

AWS has two versions. Version 1 (IMDSv1) answers any plain GET. Version 2 (IMDSv2) uses two steps. First the client asks for a token:

output
PUT /latest/api/token HTTP/1.1
Host: 169.254.169.254
X-aws-ec2-metadata-token-ttl-seconds: 300

Then it sends the token with each request for data:

output
GET /latest/meta-data/instance-id HTTP/1.1
Host: 169.254.169.254
X-aws-ec2-metadata-token: <token from the first response>

Most SSRF flaws let the attacker choose a URL and nothing else. They cannot change the method to PUT or add a custom header, so the token step stops them. IMDSv2 also limits how many network hops the token response may travel, which keeps it from leaving through an extra layer such as a container network.

An instance can allow both versions at once. Protection only applies when version 2 is required and version 1 is refused.

How to test for it

  1. Look for SSRF entry points. Any feature that fetches a URL: webhooks, importers, link previews, PDF generators.
  2. Request the metadata address through each one and see whether anything comes back.
  3. Check the configuration directly. With read access to the cloud account, list the instances that still allow IMDSv1. This is quicker and more complete than probing from outside.

A tester proves the issue by retrieving the role name or a credential, then stops unless the scope explicitly allows more.

How to fix it

On AWS, require IMDSv2 on every instance:

output
aws ec2 modify-instance-metadata-options \
  --instance-id i-0123456789abcdef0 \
  --http-tokens required \
  --http-put-response-hop-limit 1

Set the same options in launch templates and infrastructure code, such as the metadata_options block in Terraform, so new machines start out protected.

Beyond that setting:

  • Fix the SSRF. Validate destinations on the server and block link-local and private address ranges, including after redirects.
  • Give roles the minimum. A web server role that can read one bucket is a contained incident. A role with administrator access exposes the whole account.
  • Watch for misuse. Alert when instance credentials are used from outside your cloud environment.

IMDSv2 blocks the most common path to credentials. It does not fix the SSRF flaw, which can still reach other internal services.

Finding instances that still accept IMDSv1 is a standard check in cloud security posture management (CSPM), and part of a wider cloud security program.

See what an attacker would find.

Give us a URL and two test logins. If there’s something to find, your first exploited findings land within 24 hours.

You talk to the people who build Hydra and Cerberus. No sales script.

or write to founders@cloudgrip.ai