Skip to content
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

Enable AWS check with IMDSv2 #391

Merged
merged 1 commit into from
Dec 4, 2023
Merged

Conversation

itcarroll
Copy link
Collaborator

Fixes #390 with a small change to the check for instance metadata query. For IMDSv2, the first request must be a PUT to "http://169.254.169.254/latest/api/token". A Response OK on that seems like a sufficient check.

Tests ... I would love to add a test. I have no idea how a test that depends on running on an EC2 instance could be set up. If you would like to provide guidance, happy to tackle.

Copy link

github-actions bot commented Dec 2, 2023

Binder 👈 Launch a binder notebook on this branch for commit 07417c1

I will automatically update this comment whenever this PR is modified

Copy link
Collaborator

@jrbourbeau jrbourbeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @itcarroll. This LGTM. My understanding is that IMDSv2 is broadly available and in some cases required for security reasons. There may be some super old instance types where only IMDSv1 is available, but I'm not certain about that, and it also seems like enough of an edge case that I'm okay with the changes you have here (would need to add extra logic to try IMDSv1 is IMDSv2 fails). That said, I'd appreciate an extra +1 from someone else who is familiar with this code path.

Re: testing, I've manually tested this locally and on us-west-2 using Coiled and confirmed it's working as expected. I don't think we have any automated AWS testing at the moment.

@MattF-NSIDC
Copy link

would need to add extra logic to try IMDSv1 is IMDSv2 fails

I was going to suggest using boto3 to check, because it must implement this, right? boto/boto3#313 :(

@jrbourbeau jrbourbeau changed the title update for Amazon EC2 IMDSv2 Enable AWS check with IMDSv2 Dec 4, 2023
@itcarroll
Copy link
Collaborator Author

itcarroll commented Dec 4, 2023

The ec2-metadata package mentioned in that boto3 feature request is possibly a better solution that making https requests. The AWS check should really be whether the instance is in us-west-2 anyways, right? Not just that it is an EC2 instance?

@jrbourbeau
Copy link
Collaborator

The ec2-metadata package mentioned in that boto3 feature request is possibly a better solution that making https requests.

Could you elaborate a bit here? I'm curious what advantages that package has over making a direct https request

The AWS check should really be whether the instance is in us-west-2 anyways, right? Not just that it is an EC2 instance?

Correct. See #395 for adding the region part to the check.

@itcarroll
Copy link
Collaborator Author

itcarroll commented Dec 4, 2023

Could you elaborate a bit here? I'm curious what advantages that package has over making a direct https request

Well, I thought one advantage is that it was aware of both IMDS versions, but I now see that the package docs actually say that it exclusively uses IMDSv2. In that case, the minor advantage is that the ec2-metadata may be more likely to stay current with future breaking changes. E.g. they updated to IMDSv2 in 2020. That's not really convincing though.

I will keep the requests package, but make the test be for us-west-2.

@itcarroll
Copy link
Collaborator Author

@jrbourbeau I guess #395 makes this obsolete?

@jrbourbeau
Copy link
Collaborator

We'll want both this PR (which makes us compatible with IMDSv2) and #395 (which adds the extra us-west-2 check, along with some other variable renames). These two PRs will conflict with each other a small amount, so I'd like to get this PR merged first and then I'll handle the merge conflicts over in #395 separately

Copy link
Collaborator

@jrbourbeau jrbourbeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @itcarroll. Let's go ahead without an additional +1 for the changes here. I'm happy with them and we can always follow-up as needed if others have thoughts

@jrbourbeau jrbourbeau merged commit bd6dce8 into nsidc:main Dec 4, 2023
7 checks passed
@jrbourbeau jrbourbeau mentioned this pull request Dec 5, 2023
3 tasks
@itcarroll itcarroll deleted the i-am-in-aws branch April 20, 2024 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

the module level Store does not know it IS in AWS
3 participants