AWS vs GCP vs Azure metadata services: what an SSRF can reach
AWS, Google Cloud and Azure all serve instance metadata at 169.254.169.254, but they guard credentials very differently. A side-by-side of eight credential endpoints, including ECS, EKS Pod Identity, GKE, Lambda and App Service, mapped against the SSRF shapes that actually turn up, with the hardening that closes each gap.
By The Xalgorix Team
Three clouds put their instance metadata service on the same link-local address, and an SSRF bug that can reach 169.254.169.254 is reaching all of them. What it gets back is very different. Here are three requests for a credential, one per cloud:
# AWS EC2, IMDSv1 (if still enabled): a bare GET is enough GET http://169.254.169.254/latest/meta-data/iam/security-credentials/<role> # Google Cloud: same address, but the request must carry a header GET http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token Metadata-Flavor: Google # Azure: same address, a different header and a mandatory api-version GET http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/ Metadata: true
The first one works from almost any SSRF. The other two only work if the bug lets the attacker add a header. That single difference decides whether a server-side request forgery finding is a cloud-credential compromise or an internal port scan, and it is often reported wrong in both directions. This article compares the credential endpoints on AWS, Google Cloud and Azure — including the container and serverless ones people forget — against the kinds of SSRF that actually turn up, so you can tell which combination you are looking at and which controls close it.
Eight credential endpoints side by side
Every entry below is taken from the provider's own documentation, linked in the sections that follow. “URL-only” means an SSRF where the attacker controls the URL of a plain GET and nothing else, which is the most common shape: link previews, image importers, PDF renderers, “fetch from URL” fields.
| Endpoint | Address | What a request must carry | URL-only GET gets credentials? |
|---|---|---|---|
| EC2 IMDSv1 | 169.254.169.254 | Nothing beyond a GET | Yes |
| EC2 IMDSv2 | 169.254.169.254 | PUT for a session token, then a token header; PUT rejected if X-Forwarded-For is present | No |
| ECS task role | 169.254.170.2 | The per-task path from AWS_CONTAINER_CREDENTIALS_RELATIVE_URI | Only if the path leaks |
| EKS Pod Identity | 169.254.170.23 | Pod's service-account token in the Authorization header | No |
| AWS Lambda | No endpoint: keys sit in environment variables | Read access to the process environment | No (file read is the risk) |
| Compute Engine / GKE metadata server | 169.254.169.254, metadata.google.internal | Metadata-Flavor: Google; rejected if X-Forwarded-For is present | No |
| Azure IMDS | 169.254.169.254 | Metadata: true, an api-version parameter; rejected if X-Forwarded-For is present | No |
| App Service / Functions identity | Local URL in IDENTITY_ENDPOINT | X-IDENTITY-HEADER carrying a platform-rotated secret | No |
Read down the last column and one row stands out. IMDSv1 is the only endpoint in the table that hands out credentials to an unauthenticated, header-less GET. Everything else asks for something a URL-only SSRF cannot supply: a header, a method other than GET, or a secret that lives in the process environment.
Classify the SSRF before you look at the cloud
The table is only half the answer. The other half is what the vulnerable feature lets an attacker control. Five shapes cover most real findings:
- URL-only GET. No header or method control. The only credential source it can read directly is IMDSv1.
- GET with attacker-chosen headers. Webhook builders with a “custom headers” field, API-proxy endpoints that copy request headers upstream, or CRLF injection into an outbound request. Adding
Metadata-Flavor: GoogleorMetadata: trueis trivial here. - Method and headers. Workflow tools with a generic “HTTP request” step. These can do the IMDSv2 PUT-then-GET dance like any local client.
- Local file read. A
file://URL accepted by the fetcher, or path traversal elsewhere in the app. Not an SSRF in the narrow sense, but it is how the secrets that guard container and serverless endpoints leak, usually through/proc/self/environ. - Proxied requests. If the SSRF request passes through a forward or reverse proxy that adds
X-Forwarded-For, all three providers refuse it at the points described below. That is an accident of the architecture worth noticing, not a control to rely on.
AWS: one metadata service, four ways to hand out keys
EC2 instance metadata, v1 and v2
IMDSv2 was designed around exactly the SSRF classification above. The AWS Security Blog post that introduced it on November 19, 2019 explains that a session has to start with a PUT, that IMDSv2 “will also not issue session tokens to any caller with an X-Forwarded-For header”, and that the token response leaves with an IP TTL of 1. The same post is candid that “many SSRF vulnerabilities” let attackers set arbitrary headers, which is why the method requirement matters more than the header.
# Step 1: a PUT, with a TTL header, to open a session (max 21600 s) PUT http://169.254.169.254/latest/api/token X-aws-ec2-metadata-token-ttl-seconds: 21600 # Step 2: every GET replays the token GET http://169.254.169.254/latest/meta-data/iam/security-credentials/<role> X-aws-ec2-metadata-token: <token from step 1>
The EC2 user guide adds the details: the TTL header is mandatory with a six-hour maximum, GETs without a valid token get 401 Unauthorized, and PUT requests carrying X-Forwarded-For are rejected. The catch is that IMDSv2 only helps where IMDSv1 has actually been switched off for the instance, so on AWS the first question about any SSRF is whether the instance still answers v1. Our IMDSv2 enforcement guide covers switching it off across an organization; this piece does not repeat it.
Containers: ECS and EKS have their own endpoints
Workloads on ECS and EKS do not normally get their role from the instance metadata service at all. They talk to a separate link-local endpoint, and both are shaped differently from IMDS:
# Amazon ECS task role: the path comes from an env var the agent sets GET http://169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI # EKS Pod Identity: the agent wants the pod's projected service-account token GET http://169.254.170.23/v1/credentials Authorization: <contents of $AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE> # Azure App Service / Functions: a platform-rotated secret in a header GET $IDENTITY_ENDPOINT?resource=https://vault.azure.net&api-version=2019-08-01 X-IDENTITY-HEADER: <value of $IDENTITY_HEADER>
For ECS, the SDK container-credential reference says the value of AWS_CONTAINER_CREDENTIALS_RELATIVE_URI “is appended to the default Amazon ECS hostname of 169.254.170.2”, and the ECS IAM best-practices page says the agent populates that variable with the URI of the task's credential ID. No header is needed, so a URL-only SSRF works if the attacker knows the path. That path is not something you guess; it leaks through the environment, which makes ECS a file-read-plus-SSRF chain rather than a one-shot SSRF.
EKS Pod Identity raises the bar further. The EKS documentation shows the injected AWS_CONTAINER_CREDENTIALS_FULL_URI pointing at http://169.254.170.23/v1/credentials and a projected service-account token with a 24-hour expiry. Datadog Security Labs' deep dive (Christophe Tafani-Dereeper, November 28, 2023) shows the agent accepting that token in the Authorization header and running with host networking on port 80. An SSRF therefore needs both header control and the token's contents.
Two cautions apply. First, a task on an EC2-backed ECS cluster may still be able to reach the node's instance metadata unless you block it; the ECS best-practices page “strongly recommend[s]” doing so, with ECS_AWSVPC_BLOCK_IMDS=true for awsvpc tasks, an iptables drop for bridge mode and ECS_ENABLE_TASK_IAM_ROLE_NETWORK_HOST=false for host networking. Second, the endpoint answers anything in the pod or task that can reach it, so these designs limit remote request forgery, not code running inside the workload.
Lambda: no endpoint, just environment variables
Lambda has no credential endpoint to forge requests against. The reserved environment variables include AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN, “obtained from the function's execution role”. An SSRF in a function that only fetches HTTP URLs has no metadata service to hit. One that also accepts file:// can read /proc/self/environ and walk away with the keys.
Google Cloud: a header the server will not do without
The Compute Engine metadata documentation is explicit about why the Metadata-Flavor: Google header exists: it “indicates that the request was sent with the intention of retrieving metadata values, rather than unintentionally from an insecure source”, and “if you don't provide this header, the metadata server denies your request.” The same page says requests that contain X-Forwarded-For “are automatically rejected”, because the header “generally indicates that the request was proxied”. The service-account token lives at /computeMetadata/v1/instance/service-accounts/default/token, reachable as metadata.google.internal or 169.254.169.254.
Older SSRF writeups sometimes target the v0.1 or v1beta1 paths. Google shut those endpoints down on September 30, 2020, so on current Google Cloud a URL-only SSRF does not get a token. With header control it does, and there is no Google Cloud equivalent of the IMDSv2 method requirement to stop it. On Google Cloud the real lever is what the token is allowed to do.
On GKE, that lever has a name. Workload Identity Federation for GKE deploys a GKE metadata server that “intercepts HTTP requests to http://metadata.google.internal (169.254.169.254:80)” from pods and answers a token request with a token for the IAM service account that pod is configured to impersonate. Without it, Google's cluster-metadata page is plain that “each node's service account credentials continue to be exposed to workloads”: an SSRF with header control in any pod gets the node's identity.
Azure: a header, an api-version, and a rotating secret for App Service
The Azure IMDS documentation sets two rules: a request “must contain the header Metadata: true” and “must not contain an X-Forwarded-For header”, and requests that fail either are rejected. An api-version parameter is mandatory too, and the only HTTP verb listed is GET. The managed-identity token guide states the purpose of the header directly: it is “used as a mitigation against server side request forgery (SSRF) attacks.” It also sets the boundary that matters for impact: “all code/scripts running on a virtual machine can request and retrieve tokens for any managed identities available on it.”
App Service and Azure Functions hand out managed-identity tokens through a different, local endpoint. Per Microsoft's App Service guide, the platform sets IDENTITY_ENDPOINT, “the URL to the local token service”, and IDENTITY_HEADER, a value the caller must send as X-IDENTITY-HEADER, which the platform rotates and which “can help mitigate server-side request forgery (SSRF) attacks.” This is the strongest design in the table against remote forgery, because the gate is a secret rather than a constant. It is also only as strong as the secrecy of the process environment.
What gets through anyway
Put the providers next to each other and the pattern is clear. Constant headers (Google, Azure IMDS) stop URL-only and proxied SSRF and little else. A method requirement (IMDSv2) also stops header-only SSRF. Secrets in the environment (ECS path, EKS token, App Service header, Lambda keys) stop remote forgery until something reads the environment. Three failure modes defeat every row:
- Features that are SSRF by design. Webhooks and workflow “HTTP request” steps that let users pick method, URL and headers will send any of the requests above on request. Treat link-local destinations as forbidden in the egress layer of those features, not in a URL regex.
- File read anywhere in the app.
/proc/self/environholds the ECS relative URI, the App Service identity header and Lambda's keys; the EKS token sits at a well-known file path. A low-severity path traversal plus a header-capable SSRF adds up to credentials. - Code execution. Once an attacker runs code on the workload, every endpoint here is just a local call. None of these designs is meant to stop that; scoped roles are.
Hardening each cloud
- AWS. Require IMDSv2 and keep the hop limit at 1 unless containers genuinely need the node's role; block container access to the node's IMDS on ECS with the settings above; prefer EKS Pod Identity or per-task roles to a broad instance profile.
- Google Cloud. The header is always enforced, so spend effort on scope: enable Workload Identity Federation for GKE, give node and VM service accounts minimal roles, and avoid the default Compute Engine service account for application workloads.
- Azure. Assign managed identities only to resources that need them and scope their role assignments narrowly, since any code on the VM can request any identity attached to it. On VMs, Microsoft also suggests local firewall rules to limit which processes can reach IMDS.
- Everywhere. Deny
169.254.0.0/16(and the IPv6 metadata addresses your platform uses) at the HTTP client that fetches user-supplied URLs, after DNS resolution and on every redirect — our piece on resolve-and-pin SSRF filtering shows how. Rejectfile://and other non-HTTP schemes, and never let user input choose outbound headers or methods unless the feature truly requires it.
Testing it without pulling credentials
On an authorised test you rarely need a live token to show impact, and you should not take one from an environment you do not control. Work out the SSRF's shape first by pointing it at a server you own: an out-of-band callback tells you which method arrived, which headers you managed to inject, whether redirects are followed and whether a proxy added X-Forwarded-For. Then identify the cloud from response headers, DNS or error pages, and read the answer off the table. If you do touch the metadata service, ask for a non-secret value such as the instance zone and stop there.
That reasoning is also where automated tools, Xalgorix included, need care. A scanner that sees a 200 from 169.254.169.254 and calls it critical will be wrong on Google Cloud and Azure about as often as one that treats every header-gated endpoint as safe will be wrong on a webhook feature. The useful report states the SSRF shape, the endpoint, and the identity behind it.
Ready to see it prove a bug?
Start scanning on Cloud →