Cloud security Instance metadata and credentials 4 min read
How can instance metadata expose cloud credentials?
A URL-fetching feature lets users choose a destination. What could happen if the server can also reach its own metadata endpoint?
-
The instance can ask a local metadata service
EC2 applications can query a link-local metadata endpoint for instance details and temporary credentials associated with the instance role. SDKs may retrieve these credentials automatically.
In short Metadata can be a credential source for code running on the instance.
-
SSRF can turn the application into the requester
If a server fetches user-controlled URLs without sufficient checks, an attacker may make it request an internal address. If the metadata endpoint is reachable through that path, the response may expose information or credentials.
In short A server-side request can cross a boundary the user cannot reach directly.
-
Add layers around metadata and role access
IMDSv2 requires the caller to obtain a session token before metadata requests, which helps defend against some SSRF patterns. Also block unnecessary access to link-local destinations, validate fetch targets, and restrict the instance role.
In short Use IMDSv2, SSRF defenses, and a narrowly scoped role together.
What IMDSv2 doesn’t guarantee
IMDSv2 is not a replacement for fixing SSRF, and it cannot protect credentials from code already running with the role’s authority. A compromised process can make authenticated requests as that workload.
Check application compatibility and provider guidance when changing metadata settings.
Keep this
Protect the metadata endpoint and give the instance role only limited permissions.
Require IMDSv2 where compatible, prevent untrusted input from reaching internal endpoints, and keep instance-role permissions narrow.- Metadata
- The local service can return instance details and role credentials.
- SSRF
- A vulnerable server may be tricked into making local requests.
- IMDSv2
- Requires a token obtained through a session-oriented request.
- Role scope
- Limit the value of credentials if they are exposed.