-
Notifications
You must be signed in to change notification settings - Fork 11
Upgrade to IMDSv2 from v1 when calling EC2 Instance Metadata. #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
httpretty.register_uri( | ||
httpretty.GET, | ||
EC2_API_TOKEN_URI, | ||
body="PARIOq_FXbIyL0maE9RcmrsyWtylvFh1ZDt0NrRUyNxeV1-DlpFpA==") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I agree it still can trigger some security scripts, I will update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.