Skip to content

GODRIVER-3567 Add optional AWS SDK v2-based MONGODB-AWS authenticator submodule#2508

Open
qingyang-hu wants to merge 6 commits into
mongodb:masterfrom
qingyang-hu:godriver3567awsauth
Open

GODRIVER-3567 Add optional AWS SDK v2-based MONGODB-AWS authenticator submodule#2508
qingyang-hu wants to merge 6 commits into
mongodb:masterfrom
qingyang-hu:godriver3567awsauth

Conversation

@qingyang-hu

Copy link
Copy Markdown
Contributor

GODRIVER-3567
GODRIVER-3615

Summary

This PR allows users to plug a custom AWS SDK v2 credentials provider into the driver's MONGODB-AWS authentication mechanism without forcing the AWS SDK as a dependency on the core driver.

Additionally, EKS Pod Identity and other AWS SDK-native authentication are made possible by the ext/awsauth submodule as required in GODRIVER-3571.

The custom provider overrides environment variables and all automatic sources, superseded only by explicit URI credentials as required in GODRIVER-3615.

Background & Motivation

This PR contains two stacked commits.

881bc5f:

  • New public interface in mongo/options (clientoptions.go)

    • Adds AWSCredentialsProvider interface (Retrieve(ctx) (AWSCredentials, error)) and an AWSCredentials struct alias.
    • Wires a new AWSCredentialsProvider field into Credential, and into ClientEncryptionOptions / AutoEncryptionOptions.
  • New ext/awsauth sub module

    • NewCredentialsProvider(aws.CredentialsProvider) adapts an AWS SDK v2 provider to the driver's options.AWSCredentialsProvider interface. The adapter relies on AWSCredentials being a struct type alias so aws.Credentials converts directly.
  • Internal adapter (internal/credutil/aws_options_provider.go

    • AWSOptionsProvider bridges the public options.AWSCredentialsProvider to the driver's internal credentials.Provider type.

bbedca6:

Notes

Instead of the v1.0.0 specified in the original design, the ext/awsauth submodule depends on aws-sdk-go-v2 v1.28.0 in this PR. v1.28.0 is the earliest version that is compatible with the current Credentials struct.

@evergreen-ci-prod

Copy link
Copy Markdown

There is an existing patch(es) for this commit SHA:

Please note that the status that is posted is not in the context of this PR but rather the (latest) existing patch and that may affect some tests that may depend on the particular PR. If your tests do not rely on any PR-specific values (like base or head branch name) then your tests will report the same status. If you would like a patch to run in the context of this PR and abort the other(s), comment 'evergreen retry'.

@github-actions github-actions Bot added the review-priority-normal Medium Priority PR for Review: within 1 business day label Jul 23, 2026
@qingyang-hu
qingyang-hu marked this pull request as ready for review July 23, 2026 21:30
@qingyang-hu
qingyang-hu requested a review from a team as a code owner July 23, 2026 21:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reordered to align with aws.Credentials

Comment thread ext/awsauth/awsauth.go
Comment thread ext/awsauth/awsauth.go
Comment thread ext/awsauth/test/aws_test.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[nit] We should use github.com/stretchr/testify/require to match the rest of the driver test suite.

Comment thread ext/awsauth/doc.go
Comment thread ext/awsauth/go.mod

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[question] Why not use the latest version? 1.20 is EOL.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The rationale is to use a minimum requirement while supporting the earliest aws-sdk-go-v2 version that is compatible with the current aws.Credentials. Therefore, aws-sdk-go-v2 v1.28.0 is used and it requires golang 1.20.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@qingyang-hu Why do we need to do that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Under Minimal Version Selection, requiring aws-sdk-go-v2 v1.28.0 only means "at least v1.28.0." Any user who already depends on a newer SDK will have MVS select that higher version automatically. Pinning the minimum compatible version imposes the least constraint on downstream users.

go 1.20 is a minimum language level, not a build toolchain. The directive is inherited from aws-sdk-go-v2 v1.28.0's own go 1.20 and just declares the minimum language features the module uses. Users still build with their own (newer) toolchain. Declaring go 1.20 simply maximizes how broadly this submodule can be imported. It doesn't apply the way it would to actually compiling with an EOL compiler.

This is also consistent with the intent of splitting ext/awsauth into its own module (not forcing the AWS SDK onto core driver users) and with the driver's generally conservative Go-version policy.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The AWS version isn't tied to which version of Go we use. We should use a Go version that is currently being supported so that we don't have issues with dependabot trying to bump dependencies due to CVEs, etc. This is an experimental API, I would wait to see if we have a consumer complain about it first. Besides, the code is very copyable.

Comment thread ext/awsauth/doc.go
Comment on lines 37 to 39

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[question] This test intentionally skips assume-role and regular. We should update this comment to reflect that and also why we skip these cases.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@qingyang-hu This is an open question.

@mongodb-drivers-pr-bot

mongodb-drivers-pr-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

🧪 Performance Results

Commit SHA: e3d48e7

The following benchmark tests for version 6a63cfdcd669c7000763c54d had statistically significant changes (i.e., |z-score| > 1.96):

Benchmark Measurement % Change Patch Value Stable Region H-Score Z-Score
BenchmarkSingleRunCommand total_time_seconds 5.9878 1.1972 Avg: 1.1296
Med: 1.1301
Stdev: 0.0344
0.7260 1.9684
BenchmarkBSONFlatDocumentDecoding ops_per_second_max 3.1493 22031.2844 Avg: 21358.6330
Med: 21360.6750
Stdev: 326.4317
0.7278 2.0606
BenchmarkBSONDeepDocumentDecoding total_time_seconds -1.2168 1.1843 Avg: 1.1989
Med: 1.1989
Stdev: 0.0059
0.7936 -2.4848

For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch.

@mongodb-drivers-pr-bot

Copy link
Copy Markdown
Contributor

API Change Report

./v2/mongo/options

compatible changes

(*AutoEncryptionOptions).SetAWSCredentialsProvider: added
(*ClientEncryptionOptionsBuilder).SetAWSCredentialsProvider: added
AWSCredentials: added
AWSCredentialsProvider: added
AutoEncryptionOptions.AWSCredentialsProvider: added
ClientEncryptionOptions.AWSCredentialsProvider: added
Credential.AWSCredentialsProvider: added

./v2/x/mongo/driver/mongocrypt/options

compatible changes

MongoCryptOptions.AWSCredentialsProvider: added

Comment on lines 37 to 39

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@qingyang-hu This is an open question.

Comment thread ext/awsauth/awsauth.go
Comment on lines +50 to +51
provider := aws.CredentialsProviderFunc(func(context.Context) (aws.Credentials, error) {
return aws.Credentials{}, nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[blocking] It's unclear to me why we would need to go through the entire compile check with this separate option. We should revert these changes and simply rely on ext/awsauth/test and ext/awsauth/examples.

// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

package awsauthtest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[blocking] We should add a test/compilecheck/ package here and tie it into the compile-check evergreen task:

var _ options.AWSCredentialsProvider = (*awsauth.CredentialsProvider)(nil)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature review-priority-normal Medium Priority PR for Review: within 1 business day

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants