Skip to content

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

Open
qingyang-hu wants to merge 9 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 9 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 Outdated
Comment thread ext/awsauth/doc.go
Comment thread ext/awsauth/test/aws_test.go Outdated
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: 55baa9d

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

Benchmark Measurement % Change Patch Value Stable Region H-Score Z-Score
BenchmarkBSONFullDocumentDecoding ops_per_second_min -96.4323 71.8067 Avg: 2012.6735
Med: 2046.6472
Stdev: 222.6903
0.9448 -8.7155
BenchmarkMultiInsertSmallDocument total_mem_allocs -23.6015 1905067.0000 Avg: 2493591.4286
Med: 2609995.0000
Stdev: 190544.3439
0.8253 -3.0886
BenchmarkMultiInsertSmallDocument ns_per_op 16.3682 7355.0000 Avg: 6320.4563
Med: 6311.5000
Stdev: 168.8305
0.9126 6.1277
BenchmarkMultiInsertSmallDocument total_bytes_allocated -14.8869 405017520.0000 Avg: 475857947.0476
Med: 472535128.0000
Stdev: 21664117.1745
0.8298 -3.2699
BenchmarkMultiInsertSmallDocument allocated_bytes_per_op 11.1218 2976.0000 Avg: 2678.1429
Med: 2657.0000
Stdev: 104.2455
0.8093 2.8573
BenchmarkSingleFindOneByID total_time_seconds 10.8534 1.2724 Avg: 1.1478
Med: 1.1536
Stdev: 0.0467
0.7899 2.6701
BenchmarkSmallDocInsertOne total_time_seconds 9.8305 1.2998 Avg: 1.1834
Med: 1.1842
Stdev: 0.0243
0.8877 4.7878
BenchmarkMultiInsertLargeDocument ns_per_op 9.8170 32398356.0000 Avg: 29502137.0755
Med: 29462782.0000
Stdev: 877791.0199
0.8355 3.2994
BenchmarkSmallDocInsertOne ops_per_second_med -8.0034 5397.8339 Avg: 5867.4298
Med: 5876.5032
Stdev: 118.1217
0.8574 -3.9755
BenchmarkSmallDocInsertOne ns_per_op 7.9144 193301.0000 Avg: 179124.4153
Med: 178835.5000
Stdev: 3698.3671
0.8537 3.8332
BenchmarkSingleFindOneByID ns_per_op 6.7697 258190.0000 Avg: 241819.4870
Med: 241883.0000
Stdev: 6912.4325
0.7758 2.3683
BenchmarkSingleFindOneByID ops_per_second_med -6.3432 3985.0243 Avg: 4254.9231
Med: 4250.5621
Stdev: 113.2243
0.7768 -2.3838
BenchmarkBSONDeepDocumentDecoding total_time_seconds -1.3213 1.1830 Avg: 1.1989
Med: 1.1989
Stdev: 0.0059
0.8083 -2.6874
BenchmarkSingleRunCommand allocated_bytes_per_op -0.1010 12195.0000 Avg: 12207.3333
Med: 12207.5000
Stdev: 6.2591
0.7456 -1.9705

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 thread ext/awsauth/test/aws_test.go Outdated
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.

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.

It was used to check compatibility for higher Go versions. Reverted since we bumped the version to 1.25.

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.

It was used to check compatibility for higher Go versions. Reverted since we bumped the version to 1.25.

I thought we decided to keep 1.20 as the first go runtime for awsauth? In any event, we don't need to include this in the compile check here. We should add ext/awsauth/test/compilecheck/compile_check_test.go and just assert this:

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

awsauth will pass this use case if it implements options.AWSCredentialsProvider , per the original compile check test.

@qingyang-hu qingyang-hu Jul 28, 2026

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.

It was a sensible suggestion.

I've updated the version to 1.25 in cf91914.

The assertions have also been added to ‎ext/awsauth/test/aws_test.go‎ while I revert compile_check_test.go.

Let me know if we need any more adjustments.

// 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)

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 issue is outstanding.

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.

I've added them at L24-L27.

@qingyang-hu
qingyang-hu force-pushed the godriver3567awsauth branch from 5b6adba to 55baa9d Compare July 28, 2026 14:11
// 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.

@qingyang-hu This issue is outstanding.

}, nil
}

func TestClientSideEncryptionProse_26_custom_aws_credentials(t *testing.T) {

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.

[suggestion] Give how large the CSFLE test suite has become, I suggest that we move this to it's own file (just like prose test 27): internal/integration/client_side_encryption_prose_26_test.go. Additionally, IMO subtests make it harder to read the code. Consider doing 1 test per case:

 TestCSE_26_CustomAWS_Case1_CE_WithCredProvidersAndIncorrectKMSProviders(t *testing.T) {}
 TestCSE_26_CustomAWS_Case2_CE_WithCredProviders(t *testing.T) {}
 TestCSE_26_CustomAWS_Case3_AE_WithCredProvidersAndIncorrectKMSProviders(t *testing.T) {}
 TestCSE_26_CustomAWS_Case4_CE_WithCredProvidersAndEnvVars(t *testing.T) {}

opts := options.Client().ApplyURI(mtest.ClusterURI())
integtest.AddTestServerAPIVersion(opts)
keyVaultClient, err := mongo.Connect(opts)
assert.NoErrorf(mt, err, "error on Connect: %v", err)

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 the require package instead of assert. See GODRIVER-3708 for more info

})
_, err = clientEncryption.CreateDataKey(context.Background(), "aws", dkOpts)
assert.NoErrorf(mt, err, "unexpected error %v", err)
assert.Equal(mt, 1, provider.cnt, "expected credential provider to be called once")

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] This should be >= 1 per the spec:

Assert the datakey was created and that the custom credential provider was called at least once.

})
_, err = clientEncryption.CreateDataKey(context.Background(), "aws", dkOpts)
assert.NoErrorf(mt, err, "unexpected error %v", err)
assert.Equal(mt, 1, provider.cnt, "expected credential provider to be called once")

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] This should be >= 1 per the spec:

Assert the datakey was created and that the custom credential provider was called at least once.

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