Skip to content

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

Merged
prestonvasquez merged 3 commits into
mongodb:masterfrom
qingyang-hu:godriver3567awsauth
Jul 23, 2026
Merged

GODRIVER-3567 Add optional AWS SDK v2-based MONGODB-AWS authenticator submodule#2494
prestonvasquez merged 3 commits into
mongodb:masterfrom
qingyang-hu:godriver3567awsauth

Conversation

@qingyang-hu

@qingyang-hu qingyang-hu commented Jul 17, 2026

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.

@github-actions github-actions Bot added the review-priority-normal Medium Priority PR for Review: within 1 business day label Jul 17, 2026
@mongodb-drivers-pr-bot

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

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

@mongodb-drivers-pr-bot

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

Copy link
Copy Markdown
Contributor

🧪 Performance Results

Commit SHA: 61ace3a

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

Benchmark Measurement % Change Patch Value Stable Region H-Score Z-Score
BenchmarkMultiFindMany ops_per_second_min -83.0040 6531.4227 Avg: 38429.2075
Med: 40661.1686
Stdev: 15001.1272
0.7346 -2.1264
BenchmarkLargeDocInsertOne ops_per_second_min -50.7258 692.8710 Avg: 1406.1542
Med: 1375.7902
Stdev: 257.9479
0.8021 -2.7652
BenchmarkMultiInsertLargeDocument total_bytes_allocated -10.4237 907558112.0000 Avg: 1013167933.9099
Med: 1025988984.0000
Stdev: 45928746.6761
0.7573 -2.2994
BenchmarkBSONFlatDocumentDecoding ns_per_op 5.8228 55004.0000 Avg: 51977.4417
Med: 51859.5000
Stdev: 1131.6993
0.7930 2.6743
BenchmarkBSONFlatDocumentDecoding total_mem_allocs -5.5302 9955076.0000 Avg: 10537834.2143
Med: 10571035.0000
Stdev: 234809.6520
0.7768 -2.4818
BenchmarkBSONFlatDocumentDecoding total_bytes_allocated -5.5178 391561960.0000 Avg: 414429184.9286
Med: 415729248.0000
Stdev: 9222076.2249
0.7767 -2.4796
BenchmarkBSONFlatDocumentDecoding ops_per_second_med -4.8424 19563.7288 Avg: 20559.2977
Med: 20596.4740
Stdev: 416.7818
0.7693 -2.3887
BenchmarkBSONDeepDocumentDecoding ns_per_op 4.2820 65934.0000 Avg: 63226.6602
Med: 63311.0000
Stdev: 1081.5342
0.7776 2.5032
BenchmarkBSONFullDocumentDecoding ns_per_op 4.1434 76956.0000 Avg: 73894.2476
Med: 73612.0000
Stdev: 1554.6688
0.7320 1.9694
BenchmarkBSONFullDocumentDecoding ops_per_second_med -3.8910 13994.4302 Avg: 14560.9966
Med: 14595.5040
Stdev: 270.3473
0.7459 -2.0957
BenchmarkBSONFullDocumentEncoding ns_per_op 3.8864 24096.0000 Avg: 23194.5728
Med: 23201.5000
Stdev: 397.0000
0.7587 2.2706
BenchmarkBSONDeepDocumentDecoding total_mem_allocs -3.7940 12678674.0000 Avg: 13178666.0146
Med: 13172121.0000
Stdev: 218235.3562
0.7569 -2.2911
BenchmarkBSONDeepDocumentDecoding total_bytes_allocated -3.7861 275471952.0000 Avg: 286311946.6019
Med: 286168292.0000
Stdev: 4730234.4058
0.7570 -2.2916
BenchmarkBSONDeepDocumentDecoding ops_per_second_med -3.4926 16137.1008 Avg: 16721.1041
Med: 16678.7589
Stdev: 268.2608
0.7447 -2.1770
BenchmarkBSONFullDocumentEncoding total_mem_allocs -3.3778 1495558.0000 Avg: 1547841.3350
Med: 1549221.5000
Stdev: 26148.2794
0.7229 -1.9995
BenchmarkBSONFullDocumentEncoding total_bytes_allocated -3.3247 258873144.0000 Avg: 267775834.7961
Med: 268013752.0000
Stdev: 4491157.5926
0.7205 -1.9823
BenchmarkBSONFlatDocumentDecoding allocated_bytes_per_op 0.0154 18055.0000 Avg: 18052.2136
Med: 18052.0000
Stdev: 0.9438
0.8396 2.9524

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

@qingyang-hu
qingyang-hu force-pushed the godriver3567awsauth branch 16 times, most recently from 84bc726 to 88dbbf2 Compare July 22, 2026 22:54
@qingyang-hu
qingyang-hu force-pushed the godriver3567awsauth branch from 88dbbf2 to bbedca6 Compare July 22, 2026 23:50

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

@qingyang-hu qingyang-hu changed the title GODRIVER-3567 GODRIVER-3567 Add optional AWS SDK v2-based MONGODB-AWS authenticator submodule Jul 23, 2026
@qingyang-hu
qingyang-hu marked this pull request as ready for review July 23, 2026 12:38
@qingyang-hu
qingyang-hu requested a review from a team as a code owner July 23, 2026 12:38

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.

Pull request overview

This PR introduces an optional, AWS SDK v2-compatible way to supply custom AWS credentials into the driver’s MONGODB-AWS authentication flow (including CSFLE’s automatic KMS credential fetching), without making the AWS SDK a dependency of the core go.mongodb.org/mongo-driver/v2 module.

Changes:

  • Adds a new public options.AWSCredentialsProvider API (plus AWSCredentials alias) and plumbs it through client auth + client-side encryption option types.
  • Implements internal adapters to bridge public providers to the driver’s internal AWS credentials provider interface, and wires provider precedence (URI creds > custom provider > env/default chain).
  • Adds a new ext/awsauth submodule (adapter for AWS SDK v2 providers), along with integration/tests/examples and compilecheck/CI plumbing.

Reviewed changes

Copilot reviewed 28 out of 31 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
x/mongo/driver/topology/topology_options.go Bridges options.Credential into internal auth creds; now wires AWS credentials providers via internal adapter.
x/mongo/driver/mongocrypt/options/mongocrypt_options.go Adds AWS credentials provider field to mongocrypt options for CSFLE KMS fetching.
x/mongo/driver/mongocrypt/mongocrypt.go Passes custom AWS provider into CSFLE KMS credential fetching; errors if provider is set but automatic fetching isn’t configured.
x/mongo/driver/auth/mongodbaws_test.go Adds unit-level coverage for provider precedence vs explicit creds.
Taskfile.yml Updates compilecheck subtest regex target name.
mongo/options/clientoptions.go Adds public AWSCredentialsProvider interface and AWSCredentials type alias; adds field to Credential.
mongo/options/clientencryptionoptions.go Adds AWS provider to ClientEncryption options and builder setter.
mongo/options/autoencryptionoptions.go Adds AWS provider to AutoEncryption options and setter.
mongo/client.go Plumbs auto-encryption AWS provider into mongocrypt via internal adapter.
mongo/client_examples_test.go Documents custom AWS credential provider precedence and adds a usage example.
mongo/client_encryption.go Plumbs ClientEncryption AWS provider into mongocrypt via internal adapter.
internal/test/compilecheck/compile_check_test.go Adds compilecheck case for ext/awsauth usage and reduces redundant compilation via shared GOCACHE volume.
internal/test/aws/aws_test.go Adds integration tests validating custom provider auth + precedence over environment variables.
internal/integration/client_side_encryption_prose_test.go Adds prose tests validating CSFLE behavior with custom AWS providers and error cases.
internal/credutil/aws_options_provider.go New internal adapter from public options.AWSCredentialsProvider to internal AWS credentials provider interface.
internal/aws/credentials/credentials.go Reorders credentials.Value fields to support direct struct conversions with AWS SDK credentials shapes.
go.work Adds new ext/awsauth modules to the workspace.
ext/awsauth/test/go.sum Adds dependency checksums for the ext module integration tests.
ext/awsauth/test/go.mod Defines integration-test module for ext/awsauth using AWS SDK default chain.
ext/awsauth/test/aws_test.go Adds ext-module integration test covering non-inline-URI scenarios via AWS SDK default credential chain.
ext/awsauth/go.sum Adds checksums for the ext module dependencies.
ext/awsauth/go.mod Defines new ext/awsauth module pinned to aws-sdk-go-v2 v1.28.0.
ext/awsauth/examples/go.sum Adds checksums for the examples module dependencies.
ext/awsauth/examples/go.mod Defines examples module for ext/awsauth.
ext/awsauth/examples/example_test.go Adds example showing how to adapt AWS SDK default config credentials into the driver.
ext/awsauth/doc.go Adds package documentation for the new ext/awsauth module.
ext/awsauth/awsauth.go Implements the AWS SDK v2 credentials-provider adapter.
etc/run-mongodb-aws-test.sh Extends AWS auth test runner to include ext/awsauth/test.
Dockerfile Pre-downloads Go toolchains used by compilecheck to reduce runtime overhead.
.github/workflows/codeql.yml Updates compilecheck subtest regex target name in CodeQL workflow.
.evergreen/config.yml Ensures AWS ECS auth test task has appropriate AWS_TEST env.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 103 to 116
var oidcMachineCallback auth.OIDCCallback
if cred.OIDCMachineCallback != nil {
if credOpts.OIDCMachineCallback != nil {
oidcMachineCallback = func(ctx context.Context, args *driver.OIDCArgs) (*driver.OIDCCredential, error) {
cred, err := cred.OIDCMachineCallback(ctx, convertOIDCArgs(args))
return (*driver.OIDCCredential)(cred), err
credOpts, err := credOpts.OIDCMachineCallback(ctx, convertOIDCArgs(args))
return (*driver.OIDCCredential)(credOpts), err
}
}

var oidcHumanCallback auth.OIDCCallback
if cred.OIDCHumanCallback != nil {
if credOpts.OIDCHumanCallback != nil {
oidcHumanCallback = func(ctx context.Context, args *driver.OIDCArgs) (*driver.OIDCCredential, error) {
cred, err := cred.OIDCHumanCallback(ctx, convertOIDCArgs(args))
return (*driver.OIDCCredential)(cred), err
credOpts, err := credOpts.OIDCHumanCallback(ctx, convertOIDCArgs(args))
return (*driver.OIDCCredential)(credOpts), err
}
Comment thread ext/awsauth/doc.go Outdated
Comment on lines +7 to +22
// This package allows credential providers and signers in AWS SDK v2 to be
// supplied to the MongoDB Go Driver for use with the MONGODB-AWS authentication
// mechanism.
//
// This package is a separate module to avoid adding the AWS SDK as a dependency
// of the main driver. Users who don't need AWS authentication won't need to
// import the AWS SDK.
//
// NewCredentialsProvider() adapts an AWS CredentialsProvider to be used in:
//
// ClientOptions
// ClientEncryptionOptions
// AutoEncryptionOptions
//
// ClientOptions
package awsauth
Comment thread ext/awsauth/awsauth.go Outdated
Comment on lines +27 to +33
// NewCredentialsProvider returns a CredentialsProvider that wraps AWS
// CredentialsProvider. CredentialsProvider is expected to not be nil.
func NewCredentialsProvider(credentialsProvider aws.CredentialsProvider) *CredentialsProvider {
return &CredentialsProvider{
provider: credentialsProvider,
}
}
@prestonvasquez
prestonvasquez enabled auto-merge (squash) July 23, 2026 21:19
@prestonvasquez
prestonvasquez merged commit 2d33ee8 into mongodb:master Jul 23, 2026
24 of 35 checks passed
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