-
Notifications
You must be signed in to change notification settings - Fork 918
GODRIVER-3486 Support auto encryption in unified tests. #2240
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
Draft
qingyang-hu
wants to merge
3
commits into
mongodb:master
Choose a base branch
from
qingyang-hu:godriver3486
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+109
−35
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,9 @@ package unified | |||||
|
|
||||||
| import ( | ||||||
| "context" | ||||||
| "encoding/base64" | ||||||
| "fmt" | ||||||
| "os" | ||||||
| "strings" | ||||||
| "sync" | ||||||
| "sync/atomic" | ||||||
|
|
@@ -32,11 +34,19 @@ import ( | |||||
| // exceed the default truncation length. | ||||||
| const defaultMaxDocumentLen = 10_000 | ||||||
|
|
||||||
| // Security-sensitive commands that should be ignored in command monitoring by default. | ||||||
| var securitySensitiveCommands = []string{ | ||||||
| "authenticate", "saslStart", "saslContinue", "getnonce", | ||||||
| "createUser", "updateUser", "copydbgetnonce", "copydbsaslstart", "copydb", | ||||||
| } | ||||||
| var ( | ||||||
| // Security-sensitive commands that should be ignored in command monitoring by default. | ||||||
| securitySensitiveCommands = []string{ | ||||||
| "authenticate", "saslStart", "saslContinue", "getnonce", | ||||||
| "createUser", "updateUser", "copydbgetnonce", "copydbsaslstart", "copydb", | ||||||
| } | ||||||
|
|
||||||
| awsAccessKeyID = os.Getenv("FLE_AWS_KEY") | ||||||
| awsSecretAccessKey = os.Getenv("FLE_AWS_SECRET") | ||||||
| azureTenantID = os.Getenv("FLE_AZURE_TENANTID") | ||||||
| azureClientID = os.Getenv("FLE_AZURE_CLIENTID") | ||||||
| azureClientSecret = os.Getenv("FLE_AZURE_CLIENTSECRET") | ||||||
| ) | ||||||
|
|
||||||
| // clientEntity is a wrapper for a mongo.Client object that also holds additional information required during test | ||||||
| // execution. | ||||||
|
|
@@ -217,6 +227,13 @@ func newClientEntity(ctx context.Context, em *EntityMap, entityOptions *entityOp | |||||
| } else { | ||||||
| integtest.AddTestServerAPIVersion(clientOpts) | ||||||
| } | ||||||
| if entityOptions.AutoEncryptOpts != nil { | ||||||
| aeo, err := createAutoEncryptionOptions(entityOptions.AutoEncryptOpts) | ||||||
| if err != nil { | ||||||
| return nil, fmt.Errorf("error parsing auto encryption options: %w", err) | ||||||
| } | ||||||
| clientOpts.SetAutoEncryptionOptions(aeo) | ||||||
| } | ||||||
| for _, cmd := range entityOptions.IgnoredCommands { | ||||||
| entity.ignoredCommands[cmd] = struct{}{} | ||||||
| } | ||||||
|
|
@@ -251,6 +268,77 @@ func getURIForClient(opts *entityOptions) string { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| func createAutoEncryptionOptions(opts bson.Raw) (*options.AutoEncryptionOptions, error) { | ||||||
| aeo := options.AutoEncryption() | ||||||
| var kvnsFound bool | ||||||
| elems, err := opts.Elements() | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| for _, elem := range elems { | ||||||
| name := elem.Key() | ||||||
| opt := elem.Value() | ||||||
|
|
||||||
| switch name { | ||||||
| case "kmsProviders": | ||||||
| providers := make(map[string]map[string]any) | ||||||
| elems, err := opt.Document().Elements() | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| for _, elem := range elems { | ||||||
| provider := elem.Key() | ||||||
| providerOpt := elem.Value() | ||||||
| switch provider { | ||||||
| case "aws": | ||||||
| providers["aws"] = map[string]any{ | ||||||
| "accessKeyId": awsAccessKeyID, | ||||||
| "secretAccessKey": awsSecretAccessKey, | ||||||
| } | ||||||
| case "azure": | ||||||
| providers["azure"] = map[string]any{ | ||||||
| "tenantId": azureTenantID, | ||||||
| "clientId": azureClientID, | ||||||
| "clientSecret": azureClientSecret, | ||||||
| } | ||||||
| case "local": | ||||||
| str := providerOpt.Document().Lookup("key").StringValue() | ||||||
| key, err := base64.StdEncoding.DecodeString(str) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| providers["local"] = map[string]any{ | ||||||
| "key": key, | ||||||
| } | ||||||
| default: | ||||||
| return nil, fmt.Errorf("unrecognized KMS provider: %v", provider) | ||||||
| } | ||||||
| } | ||||||
| aeo.SetKmsProviders(providers) | ||||||
| case "schemaMap": | ||||||
| var schemaMap map[string]any | ||||||
| err := bson.Unmarshal(opt.Document(), &schemaMap) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
|
||||||
| return nil, err | |
| return nil, fmt.Errorf("error creating schema map: %w", err) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coded AWS credentials from environment variables may fail if the credentials are not set or if placeholder documents are used in tests. The existing pattern in
entity.gouses thegetKmsCredentialhelper function to handle both string values and placeholder documents (e.g.,{"$$placeholder": 1}). Consider refactoring to usegetKmsCredentialfor consistency and to properly support test specifications that use placeholders.