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

Avoid extending IMDS credentials expiry unconditionally #2694

Merged

Conversation

ysaito1001
Copy link
Contributor

@ysaito1001 ysaito1001 commented May 10, 2023

Motivation and Context

Fixes #2687

Description

The implementation for IMDS static stability support introduced a bug where returned credentials from IMDS are extended unconditionally, even though the credentials are not stale. The amount by which credentials are extended is randomized and it can incorrectly extend the expiry beyond what's originally set. IMDS produces credentials that last 6 hours, and extending them by at most 25 minutes usually won't be an issue but when other tools such as Kube2iam and AWSVault are used, the expiry can be set much shorter than that, causing the issue to occur.

This PR will conditionally extend the credentials' expiry only when the returned credentials have been expired with respect to the current wall clock time. Also, the constant values have been adjusted according to our internal spec.

Testing

  • Added a new unit test for the IMDS credentials provider

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ysaito1001 ysaito1001 requested a review from a team as a code owner May 10, 2023 18:21
if new_expiry < expiration {
return expiration;
}
let refresh_offset = CREDENTIAL_EXPIRATION_INTERVAL + Duration::from_secs(rng.u64(0..=300));
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the reason for changing the expiration interval and rng range?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per our spec, 15-minute is the minimum amount of time credentials are valid for. Setting refresh_offset to something longer than that may have the risk of the credentials expiring before the next refresh (especially when the credentials expiry is set to the very minimum of 15 minutes from now).

Now that we've added the early return, however, it may not matter much because valid credentials will be used as they are without the extension. But just wanted to make this inline with the spec.

Added comment in c265e86.

aws/rust-runtime/aws-config/src/imds/credentials.rs Outdated Show resolved Hide resolved
aws/rust-runtime/aws-config/src/imds/credentials.rs Outdated Show resolved Hide resolved
@ysaito1001 ysaito1001 requested a review from jdisanti May 10, 2023 20:13
@github-actions
Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@ysaito1001 ysaito1001 added this pull request to the merge queue May 11, 2023
Merged via the queue into main with commit 91194e7 May 11, 2023
@ysaito1001 ysaito1001 deleted the ysaito/avoid-extending-imds-credentials-expiry-unconditionally branch May 11, 2023 01:12
david-perez pushed a commit that referenced this pull request May 18, 2023
## Motivation and Context
Fixes #2687

## Description
The implementation for IMDS static stability support introduced a bug
where returned credentials from IMDS are extended unconditionally, even
though the credentials are not stale. The amount by which credentials
are extended is randomized and it can incorrectly extend the expiry
beyond what's originally set. IMDS produces credentials that last 6
hours, and extending them by at most 25 minutes usually won't be an
issue but when other tools such as Kube2iam and AWSVault are used, the
expiry can be set much shorter than that, causing the issue to occur.

This PR will conditionally extend the credentials' expiry only when the
returned credentials have been expired with respect to the current wall
clock time. Also, the constant values have been adjusted according to
our internal spec.

## Testing
- Added a new unit test for the IMDS credentials provider

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: Yuki Saito <awsaito@amazon.com>
david-perez pushed a commit that referenced this pull request May 22, 2023
## Motivation and Context
Fixes #2687

## Description
The implementation for IMDS static stability support introduced a bug
where returned credentials from IMDS are extended unconditionally, even
though the credentials are not stale. The amount by which credentials
are extended is randomized and it can incorrectly extend the expiry
beyond what's originally set. IMDS produces credentials that last 6
hours, and extending them by at most 25 minutes usually won't be an
issue but when other tools such as Kube2iam and AWSVault are used, the
expiry can be set much shorter than that, causing the issue to occur.

This PR will conditionally extend the credentials' expiry only when the
returned credentials have been expired with respect to the current wall
clock time. Also, the constant values have been adjusted according to
our internal spec.

## Testing
- Added a new unit test for the IMDS credentials provider

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: Yuki Saito <awsaito@amazon.com>
david-perez pushed a commit that referenced this pull request May 22, 2023
## Motivation and Context
Fixes #2687

## Description
The implementation for IMDS static stability support introduced a bug
where returned credentials from IMDS are extended unconditionally, even
though the credentials are not stale. The amount by which credentials
are extended is randomized and it can incorrectly extend the expiry
beyond what's originally set. IMDS produces credentials that last 6
hours, and extending them by at most 25 minutes usually won't be an
issue but when other tools such as Kube2iam and AWSVault are used, the
expiry can be set much shorter than that, causing the issue to occur.

This PR will conditionally extend the credentials' expiry only when the
returned credentials have been expired with respect to the current wall
clock time. Also, the constant values have been adjusted according to
our internal spec.

## Testing
- Added a new unit test for the IMDS credentials provider

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: Yuki Saito <awsaito@amazon.com>
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.

Issues with static stability / expiration in IMDS client
3 participants