Comment 1 for bug 1870244

Revision history for this message
Noah Meyerhans (noahm) wrote :

I've attached a patch the implements IMDSv2 support. Flake8 reports no issues. Tested on EC2 with the following configurations:

1. IMDSv1 support enabled (token optional).
2. IMDSv2 support enabled (token required).
3. IMDS endpoint disabled (raises an exception due to a 403 response from the metadata endpoint).

In the attached patch, if the token retrieval endpoint returns a 404, we assume we're running on some other cloud (not EC2) that presents an EC2-compatible IMDS. In that case, we continue operation as normal, but without using the token. So essentially we've fallen back to IMDSv1 mode, and functionality is not impacted. In theory, some implementation may return something other than a 404, and we should handle its response in a similar way. I don't specifically know of any implementation where this happens.