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

feat: add support for IMDSv2 #27

Merged
merged 2 commits into from
Jul 9, 2024
Merged

Conversation

Thunderbottom
Copy link
Contributor

@Thunderbottom Thunderbottom commented Jun 28, 2024

Currently, IMDSv2 is not supported by simples3's NewUsingIAM method, causing it to fail on EC2 instances with IMDSv2 enabled in the EC2 metadata configuration.

This patch adds a failsafe method that executes PUT request on the IMDSv2 token endpoint, and based on the response decides whether IMDSv2 support needs to be enabled. Doing so will not break or require any code-level changes to existing deployments, and allows the same binaries to run on both IMDSv2 enabled and optional instances.

ref: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-metadata-v2-how-it-works.html

Currently, IMDSv2 is not supported by simple-s3's `NewUsingIAM` method, causing it
to fail on EC2 instances with IMDSv2 enabled in the EC2 metadata configuration.

This patch adds a failsafe method that executes PUT request on the IMDSv2 token endpoint,
and based on the response decides whether IMDSv2 support needs to be enabled. Doing so
will not break or require any code-level changes to existing deployments, and allows the
same binaries to run on both IMDSv2 enabled and optional instances.

ref: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-metadata-v2-how-it-works.html

Signed-off-by: Chinmay D. Pai <[email protected]>
simples3.go Outdated Show resolved Hide resolved
simples3.go Outdated Show resolved Hide resolved
Instead of using the errors to figure out whether IMDSv2 needs to be used,
we return a boolean value for useIMDSv2 from the function itself, and
propagate the error to upstream function calls in the library.

IMDSv2 tokens can be used in all cases, even when IMDSv2 is set to `Optional`
in the EC2 Instance configuration. As such, calls with token will not fail and
we should be able to send IMDSv2 requests with token even when using IMDSv1.

Signed-off-by: Chinmay D. Pai <[email protected]>
@rhnvrm rhnvrm merged commit 430bffb into rhnvrm:master Jul 9, 2024
1 check failed
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.

2 participants