AWS Certified Security - Specialty free question 4 / 10 · Domain 3: Infrastructure Security
On an EC2 instance that accepts only IMDSv2, the application's reverse proxy forwards requests to the IMDS with an X-Forwarded-For header added. What happens on this path?
- GET and HEAD requests are rejected when they have an X-Forwarded-For header, while the PUT succeeds
- Both the PUT to get a token and the GET with the token succeed, so the metadata can be retrieved through the proxy
- The PUT to get a token is rejected because of the X-Forwarded-For header, so the later GET cannot proceed
- The PUT to get a token succeeds, and the GET with the X-Forwarded-For header is rejected with a 401
Show the answer and explanation
Answer: C
Why this is correct
IMDSv2 is session-oriented: you first create a token with a PUT, and then attach that token to later GET requests. A token is required to retrieve metadata with IMDSv2. In IMDSv2, a PUT request that contains an X-Forwarded-For header is rejected. On a path where a reverse proxy forwards requests with this header, the PUT that creates the token does not go through, so the metadata cannot be retrieved.
Why the other options are wrong
"Both the PUT to get a token and the GET with the token succeed, so the metadata can be retrieved through the proxy" … A PUT that contains an X-Forwarded-For header is rejected, so through the proxy you cannot get a token and you cannot proceed to the later GET.
"The PUT to get a token succeeds, and the GET with the X-Forwarded-For header is rejected with a 401" … What is rejected is the PUT that contains X-Forwarded-For. A 401 is returned when token use is required and a request has no valid token or has an expired token.
"GET and HEAD requests are rejected when they have an X-Forwarded-For header, while the PUT succeeds" … The requests used for IMDSv2 metadata requests are GET and HEAD, and it is the PUT that is rejected when it contains an X-Forwarded-For header.
Key point
If you restrict the IMDS to IMDSv2 only, IMDSv1 calls fail. The token's time-to-live (TTL) is given in seconds in a header of the PUT, and the maximum is 6 hours (21,600 seconds). A token is specific to the instance and is rejected on other instances. When token use is required, a request with no valid token or with an expired token gets a 401.