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

Add NoCredentialsCache that offers no caching ability #2720

Merged
merged 5 commits into from
May 24, 2023

Conversation

ysaito1001
Copy link
Contributor

@ysaito1001 ysaito1001 commented May 22, 2023

Motivation and Context

Related to awslabs/aws-sdk-rust#809

Description

It has been discovered that when AssumeRoleProvider is used, the Rust SDK emits credentials cache miss occurred twice per request. The reason why that log is shown twice is illustrated in the following diagram:

Screenshot 2023-05-19 at 4 10 20 PM

One of the cache miss messages is due to the fact AssumeRoleProvider internally uses an STS client, which, in turn, is wrapped by a LazyCredentialsCache by default. However, that use of LazyCredentialsCache is pointless because caching is already in effect with the outermost LazyCredentialsCache.

This PR adds a new kind of CredentialsCache, NoCredentialsCache. As its name suggests, it simplify delegates provide_cached_credentials to the underlying provider's provide_credentials with no caching functionality. We then update SsoCredentialsProvider, AssumeRoleProvider, and WebIdentityTokenCredentialsProvider to use NoCredentialsCache for their STS clients so the logs won't show credentials cache miss occurred twice per request.

Testing

  • Added unit tests for NoCredentialsCache
  • Updated unit test for AssumeRoleProvider to verify NoCredentialsCache is used by default

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.

This commit updates `SsoCredentialsProvider`, `AssumeRoleProvider`, and
`WebIdentityTokenCredentialsProvider` to use `NoCredentialsCache` for an
internal STS client to fetch credentials. They used `LazyCredentialsCache`
internally for STS, which caused double-caching when they were wrapped in
an outer `LazyCredentialsCache` when a service client was created.
@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 marked this pull request as ready for review May 23, 2023 00:30
@ysaito1001 ysaito1001 requested review from a team as code owners May 23, 2023 00:30
@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.

@rcoh
Copy link
Collaborator

rcoh commented May 23, 2023

did not closely review PR–I think I prefer something like Uncached or NotCached, NoCredentialsCache sounds like the absence of something?

@ysaito1001
Copy link
Contributor Author

ysaito1001 commented May 24, 2023

did not closely review PR–I think I prefer something like Uncached or NotCached, NoCredentialsCache sounds like the absence of something?

Yeah, naming is hard. I unnecessarily tried sticking to LazyCredentialsCache and only replaced Lazy with No. Although NoCredentialsCache is a pub(crate), I agree that it's worth giving it a proper name.

UPDATE:
Will need to sleep on it. We can merge the PR for now since renaming can be done later without breaking changes.

Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

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

Looks good!

@ysaito1001 ysaito1001 enabled auto-merge May 24, 2023 21:31
@ysaito1001 ysaito1001 added this pull request to the merge queue May 24, 2023
@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.

Merged via the queue into main with commit 7ccac06 May 24, 2023
@ysaito1001 ysaito1001 deleted the ysaito/add-no-credentials-cache branch May 24, 2023 22:15
hlbarber pushed a commit that referenced this pull request Jun 20, 2023
Related to awslabs/aws-sdk-rust#809
It has been discovered that when `AssumeRoleProvider` is used, the Rust
SDK emits `credentials cache miss occurred` twice per request. The
reason why that log is shown twice is illustrated in the following
diagram:

![Screenshot 2023-05-19 at 4 10 20
PM](https://github.com/awslabs/smithy-rs/assets/15333866/c6cce018-c821-4b46-8d47-b414af7b4d1e)

One of the cache miss messages is due to the fact `AssumeRoleProvider`
internally uses an STS client, which, in turn, is wrapped by a
`LazyCredentialsCache` by default. However, that use of
`LazyCredentialsCache` is pointless because caching is already in effect
with the outermost `LazyCredentialsCache`.

This PR adds a new kind of `CredentialsCache`, `NoCredentialsCache`. As
its name suggests, it simplify delegates `provide_cached_credentials` to
the underlying provider's `provide_credentials` with no caching
functionality. We then update `SsoCredentialsProvider`,
`AssumeRoleProvider`, and `WebIdentityTokenCredentialsProvider` to use
`NoCredentialsCache` for their STS clients so the logs won't show
`credentials cache miss occurred` twice per request.
- Added unit tests for `NoCredentialsCache`
- Updated unit test for `AssumeRoleProvider` to verify
`NoCredentialsCache` is used by default
- [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 <[email protected]>
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.

3 participants