Upgrade to IMDSv2 from v1 when calling EC2 Instance Metadata.#24
Upgrade to IMDSv2 from v1 when calling EC2 Instance Metadata.#24mirelap-amazon merged 4 commits intomainfrom
Conversation
| httpretty.register_uri( | ||
| httpretty.GET, | ||
| EC2_API_TOKEN_URI, | ||
| body="PARIOq_FXbIyL0maE9RcmrsyWtylvFh1ZDt0NrRUyNxeV1-DlpFpA==") |
There was a problem hiding this comment.
not sure you need to provide a real token here, it may trigger some security scripts that search the code for those. Could you just put a fake string here?
There was a problem hiding this comment.
It's not real, it's based on a real one, but then I updates random characters from it.
There was a problem hiding this comment.
But I agree it still can trigger some security scripts, I will update.
There was a problem hiding this comment.
Just updated it, thanks.
| def __look_up_with_IMDSv2(cls, url): | ||
| return http_get(url=url, | ||
| headers={EC2_METADATA_TOKEN_HEADER_KEY: cls.__look_up_ec2_api_token()}) \ |
There was a problem hiding this comment.
if we call both __look_up_instance_type and __look_up_host_name successively, we are going to get 2 different tokens, can you maybe update the look_up_metadata function to get a token once and reuse it?
There was a problem hiding this comment.
Okay, updated; thanks!
Issue #, if available:
Description of changes:
Testing:
I tested one unit test on a specific host and here are the logs:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.