Skip to content

RUST-1529 Use AWS SDK to get credentials #1435

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

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

JamieTsai1024
Copy link
Collaborator

@JamieTsai1024 JamieTsai1024 commented Jul 24, 2025

Replace existing implementation for getting AWS credentials by using the AWS SDK.

Currently, we have 5 places where we search for AWS credentials:

  1. The MongoDB URI
  2. Environment variables
  3. A custom AWS credential provider if the driver supports it
  4. STS AssumeRole or AssumeRoleWithWebIdentity
  5. The ECS or EC2 endpoint

For the sake of testing, the existing implementation was replaced instead of being hidden behind a feature flag.

./.evergreen/run-aws-auth.sh

cd .evergreen/auth_aws
# run this script to reconfigure the type of AWS authentication to use
# copy the block of unset and export commands output by the script and run them in the terminal window you're using to run the driver tests
./aws_setup.sh (regular | env-creds | assume-role | session-creds | web-identity)

cd ~/mongo-rust-driver 
# Run the unset and set export commands printed by `./aws_setup.sh` for environment variables 
cargo nextest run auth_aws --features aws-auth

Work to be done

  • Generate signature using AWS SDK (compute_authorization_header(...))
  • Determine feature flags required
    • May restore deleted implementation from this PR, depending on whether we want to keep the AWS SDK as an optional dependency
    • Will clean up commented out code + notes with "RUST-1529"

@JamieTsai1024 JamieTsai1024 marked this pull request as ready for review July 25, 2025 20:45
@JamieTsai1024 JamieTsai1024 requested a review from a team as a code owner July 25, 2025 20:45
Copy link
Contributor

@isabelatkinson isabelatkinson left a comment

Choose a reason for hiding this comment

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

I forgot to mention this regarding the testing commit I provided, but we should leave line 226 (patchable: false) in config.yml commented out while this PR is being worked on. patchable: false disables tests from running on every commit to a pull request branch - normally, we don't need to run the AWS authentication tests that frequently, but since we're making AWS-related changes we should be running the tests on this PR.

let aws_credential = {
// Limit scope of this variable to avoid holding onto the lock for the duration of
// authenticate_stream.
let cached_credential = CACHED_CREDENTIAL.lock().await;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the SDK handle credential caching? We should make sure the new implementation still caches credentials as outlined in the spec

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Following up on this — as we discussed, the SDK does implement credential caching. I’ve linked the relevant documentation here in case it's helpful for future reference!

@@ -246,6 +297,20 @@ impl AwsCredential {
}
}

fn from_sdk_creds(
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be feasible to replace AwsCredential in the code with aws_credential_types::Credentials (i.e. the type returned from provide_credentials)? That could remove some of the type translation we're doing here; it looks like they have very similar fields.

Copy link
Collaborator Author

@JamieTsai1024 JamieTsai1024 Jul 26, 2025

Choose a reason for hiding this comment

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

I think it makes sense to keep AwsCredential for now since we’re still using compute_authorization_header(...), which relies on it. Once that method is removed in the next PR, I can look into fully switching over to aws_credential_types::Credentials.

To make the transition easier later, I’ll update this PR to type creds as aws_credential_types::Credentials and then map it into AwsCredential before using compute_authorization_header(...). That should make it easier to remove from_sdk_creds(...) and AwsCredential in the follow-up.

Also, I missed that another file uses AwsCredential::get, so I’ve moved the credential-fetching logic into a public method to support that use case!

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