Cloud instance metadata service
| Type | Local HTTP service attached to each cloud virtual machine |
|---|---|
| Also known as | IMDS (AWS, Azure), metadata server (Google Cloud) |
| Usual address | 169.254.169.254 |
| Hands out | Short-lived credentials for the role, service account or managed identity attached to the machine |
| MITRE ATT&CK | T1552.005 Unsecured Credentials: Cloud Instance Metadata API |
| Related | Server-side request forgery, Short-lived credentials and OIDC federation |
With default settings, a program on an Amazon EC2 server that sends a plain HTTP request to http://169.254.169.254/latest/meta-data/iam/security-credentials/ plus a role name gets back a JSON document with an access key ID, a secret access key, a session token and an expiry time.12 The instance metadata service answering that request is a small web service that AWS attaches to every EC2 instance; Google Cloud and Azure run one for their virtual machines too. It describes the machine to the software running on it and gives that software the credentials of the cloud role attached to the machine.34 The credentials work for whatever the role may use, so a flaw that lets an outsider make the server fetch the address can give the outsider that access.56
Addresses and requests
Most providers use the address 169.254.169.254.6 It is a link-local address, answered on the machine's own host, so only software on that machine can reach it and the traffic never crosses the wider network.34 The path, and the header a request must carry, differ by provider.
| Provider | Base URL | Required on each request | Credentials path |
|---|---|---|---|
| AWS EC2 | http://169.254.169.254/latest/meta-data/ | Nothing (IMDSv1) | iam/security-credentials/ + role name1 |
| AWS EC2 | Same | Session token (IMDSv2) | Same2 |
| Google Compute Engine | http://metadata.google.internal/computeMetadata/v1, also on 169.254.169.254 | Metadata-Flavor: Google | instance/service-accounts/default/token7 |
| Azure | http://169.254.169.254/metadata/ | Metadata: true, and no X-Forwarded-For | identity/ (managed identity)4 |
Apart from credentials, the service returns the machine's name, its security group and its user data scripts, which can hold further secrets.6
Why credentials live there
The service exists so that nobody has to copy a long-lived key onto a server. The administrator attaches an identity to the machine, and the provider's SDKs (the libraries programs use to call its services) and command-line tools read short-lived credentials for it from the metadata address.37 On AWS the credentials expire and are replaced on their own, with a new set available at least five minutes before the old set runs out.1 On Google Cloud the token endpoint returns a bearer token that lasts about an hour ("expires_in": 3599) and, unless the request narrows it, carries every scope granted to the machine's service account.7 The service has no login of its own: every process on the machine can read it.46
How outsiders reach it
Malware that already runs on a cloud server queries the address directly. The TeamTNT group read AWS metadata for credentials, its Hildegard malware queried the metadata service for cloud credentials, the Shai-Hulud worm queried the AWS and Google endpoints, and Peirates, a Kubernetes attack tool, reads both.6
An attacker outside the machine needs the server to make the request for them. In server-side request forgery the application fetches a URL that the attacker supplied. A Reverse proxy or web application firewall misconfigured to forward requests to whatever host they name will forward one for the metadata address too. An instance misconfigured as an open router, VPN or address-translation (NAT) device is a further route at the network level.3
In the Capital One breach, which the bank detected on 19 July 2019, a misconfigured ModSecurity firewall on AWS was made to relay requests to the metadata service. The firewall's role could list and read every file in any of the company's storage buckets, and the breach affected about 100 million people in the United States and 6 million in Canada.58 Amazon's statement put the cause on the firewall's configuration, not on the metadata service.5
Protections in the request format
Google and Azure refuse a request without their header, and Azure also refuses one carrying X-Forwarded-For, the header proxies add to name the original client.94 A fixed header stops an SSRF flaw in which the attacker controls only the URL. Many SSRF flaws also let the attacker set arbitrary headers, and a fixed header does not stop those.3
AWS released IMDSv2 in November 2019 as an extra layer of defence in depth, with a session step in front of every read.3 The caller first sends a PUT request that states the token's lifetime, from one second to six hours, then sends the returned token in a header with each read:2
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/Transparent firewalls and open proxies rarely forward PUT: of the third-party firewall products and open firewall misconfigurations AWS examined, the vast majority did not permit it.3 Proxies such as Apache httpd and Squid add X-Forwarded-For, and the service issues no token to a request that carries it.32 A token is valid only on the instance that issued it.2 By default the response with the token is sent with an IP time-to-live of 1, a packet setting that allows one network hop, so an instance acting as a router or NAT device discards the packet before it leaves.32 Once tokens are required, a read without one gets 401 Unauthorized.2 AWS accepts both versions by default, and an attacker can still use IMDSv1 until it is switched off.2
Hardening
On AWS, an instance that is already running is set to require IMDSv2 with one command:10
aws ec2 modify-instance-metadata-options \
--instance-id i-1234567890abcdef0 \
--http-tokens required \
--http-endpoint enabledFor new instances, the default is set per Region under EC2, Dashboard, Account attributes, Data protection and security, IMDS defaults, Manage, with Metadata version set to V2 only (token required), then Update. This default leaves existing instances unchanged.11 Container services on the instance can need a hop limit above 1, and the console suggests 2 for instances that host containers.211 Software on the instance needs a version of the AWS SDK that supports IMDSv2; the latest versions of all AWS SDKs do.2
A server that never reads metadata can have the service turned off.36 Where one system process needs it, a host firewall rule, for example in iptables, can keep every other process away from the address.46 The attached role should hold only what the server's work requires (Principle of least privilege); at Capital One, the stolen credentials reached every bucket because the firewall's role allowed it.5 Code that fetches URLs on a user's behalf should reject link-local addresses (see Server-side request forgery). Stolen instance credentials are used like any other cloud key: see Cloud discovery and Stolen cloud credentials.
In SecFlash
SecFlash reports SF-SEC-619 on the Security page when its ZAP scan sends a request with the Host header set to 169.254.169.254 and gets a success response, the sign of a proxy that forwards to any host it is given. SF-SEC-716, also on the Security page, marks code in which the address of an outgoing request comes from input.
See also
- Server-side request forgery
- Defence in depth
- Reverse proxy
- Principle of least privilege
- Short-lived credentials and OIDC federation
- Stolen cloud credentials
- Dynamic application security testing
- Host header attacks
- Category: Self-managed servers
References
- a b c Amazon Web Services. "Retrieve security credentials from instance metadata". Amazon EC2 User Guide.
- a b c d e f g h i j "Use the Instance Metadata Service to access instance metadata". Amazon EC2 User Guide. AWS.
- a b c d e f g h i j "Add defense in depth against open firewalls, reverse proxies, and SSRF vulnerabilities with enhancements to the EC2 Instance Metadata Service". AWS Security Blog. AWS (19 November 2019).
- a b c d e f Microsoft. "Azure Instance Metadata Service". Microsoft Learn.
- a b c d Krebs, Brian (2 August 2019). "What We Can Learn from the Capital One Hack". KrebsOnSecurity.
- a b c d e f g MITRE (version 1.4, 12 May 2026). "Unsecured Credentials: Cloud Instance Metadata API" (T1552.005). MITRE ATT&CK.
- a b c Google Cloud. "Authenticate workloads to Google Cloud APIs using service accounts". Compute Engine documentation.
- back Capital One. [Notice on the 2019 cybersecurity incident]. capitalone.com.
- back Google Cloud. "Access VM metadata". Compute Engine documentation.
- back [Transition to IMDSv2: modify instance metadata options for existing instances]. Amazon EC2 User Guide. AWS.
- a b Amazon Web Services. "Configure instance metadata options for new instances". Amazon EC2 User Guide.