microsegment.io

segment all the things

Your application cannot reach the database management port. Good.

Can its process reach the credentials for the instance role?

That belongs in the same containment review. On EC2, the metadata service can expose temporary credentials for the IAM role associated with an instance. AWS documents this under the iam/security-credentials/role-name metadata category in its metadata reference.

The engineering question is not simply whether the host needs an identity. It is which software on that host should be able to obtain it.

Harden the Protocol, Then Restrict the Caller

OWASP’s SSRF prevention guidance identifies cloud metadata as a target for credential and token theft through server-side request forgery. It describes IMDSv2 as defense in depth against some SSRF cases, not a replacement for application protections.

AWS documents IMDSv2 as a session-oriented protocol: a PUT obtains a token, and subsequent requests carry it. Requiring tokens rejects requests without a valid token. That is a protocol safeguard, not an application-specific authorization decision.

My proposed baseline has three separate decisions:

  1. Require IMDSv2 for instances that need metadata access.
  2. Permit metadata access only from the execution contexts that actually need it.
  3. Review the instance role’s permissions independently.

Do not record the first control as evidence that the other two are complete.

Put Enforcement Where the Traffic Actually Goes

AWS provides local firewall examples for restricting metadata access by operating-system principal, including Linux user-based rules and Windows firewall rules. Its Linux examples cover both IMDS versions. AWS also cautions that the examples need adaptation and that ordinary iptables rules are not persistent across reboot by default.

This is a useful starting point for host-level containment, not a universal ruleset to paste into production.

For each workload, I would document:

  • The process or execution context that requires metadata.
  • The reason it needs access and the owner approving it.
  • The enforcement mechanism and where it evaluates the request.
  • The configuration that survives replacement and reboot.
  • The negative test proving an unrelated process cannot reach metadata.

Treat containers, host processes, and shared-user services as separate test cases. Do not assume a user-based host rule distinguishes every workload sharing that user. Likewise, do not assume an application-tier network policy covers a locally reached platform endpoint. Require evidence from the deployed implementation.

AWS identifies 169.254.169.254 as the IPv4 metadata endpoint and fd00:ec2::254 as its optional IPv6 endpoint, with platform and subnet requirements for IPv6. Its documentation also explains that the token-response hop limit may need adjustment for container compatibility. Record the actual configuration rather than treating a hop-limit value as a complete workload authorization policy.

Test Without Harvesting Credentials

Use a disposable EC2 test instance with a deliberately restricted test role. The following is my suggested acceptance procedure, not an AWS-prescribed certification test.

First, test protocol enforcement. From an approved context, confirm that a tokenless metadata request fails when tokens are required, then verify the supported IMDSv2 flow against a non-secret metadata item such as the instance ID.

Second, test caller isolation. From an application context that should have no access, attempt the token request itself. A subsequent tokenless request returning HTTP 401 is not enough: it shows protocol enforcement, not a network deny. Correlate the result with firewall or policy evidence. An unexplained timeout is not conclusive either.

Third, test lifecycle changes. Repeat the positive and negative cases after reboot, image replacement, and the container networking changes you actually support. Include IPv6 if that endpoint is enabled.

Do not fetch credential documents into build logs or incident tickets. The test should establish whether the access boundary works, not create another copy of a secret.

Keep the IAM Boundary Separate

A metadata deny test answers whether a particular caller can reach that endpoint under the tested policy. It does not answer what an already issued credential can do.

I would therefore maintain two distinct review records: metadata reachability by execution context, and authorized cloud operations for the associated identity. During an incident, assess credential exposure and cloud authorization alongside network isolation rather than assuming a host rule resolves both.

For an application with no justified metadata dependency, make denial the proposed steady state and validate that the application still works. For an approved dependency, name the caller instead of granting every process on the machine an implicit exception.

The instance needs an identity. That does not mean every process needs access to it.

Sources