@@ -8,9 +8,8 @@ package unified
88
99import (
1010 "context"
11- "encoding/base64 "
11+ "crypto/tls "
1212 "fmt"
13- "os"
1413 "strings"
1514 "sync"
1615 "sync/atomic"
@@ -34,19 +33,11 @@ import (
3433// exceed the default truncation length.
3534const defaultMaxDocumentLen = 10_000
3635
37- var (
38- // Security-sensitive commands that should be ignored in command monitoring by default.
39- securitySensitiveCommands = []string {
40- "authenticate" , "saslStart" , "saslContinue" , "getnonce" ,
41- "createUser" , "updateUser" , "copydbgetnonce" , "copydbsaslstart" , "copydb" ,
42- }
43-
44- awsAccessKeyID = os .Getenv ("FLE_AWS_KEY" )
45- awsSecretAccessKey = os .Getenv ("FLE_AWS_SECRET" )
46- azureTenantID = os .Getenv ("FLE_AZURE_TENANTID" )
47- azureClientID = os .Getenv ("FLE_AZURE_CLIENTID" )
48- azureClientSecret = os .Getenv ("FLE_AZURE_CLIENTSECRET" )
49- )
36+ // Security-sensitive commands that should be ignored in command monitoring by default.
37+ var securitySensitiveCommands = []string {
38+ "authenticate" , "saslStart" , "saslContinue" , "getnonce" ,
39+ "createUser" , "updateUser" , "copydbgetnonce" , "copydbsaslstart" , "copydb" ,
40+ }
5041
5142// clientEntity is a wrapper for a mongo.Client object that also holds additional information required during test
5243// execution.
@@ -288,44 +279,49 @@ func createAutoEncryptionOptions(opts bson.Raw) (*options.AutoEncryptionOptions,
288279 return nil , err
289280 }
290281 for _ , elem := range elems {
291- provider := elem .Key ()
292- providerOpt := elem .Value ()
293- switch provider {
294- case "aws" :
295- providers ["aws" ] = map [string ]any {
296- "accessKeyId" : awsAccessKeyID ,
297- "secretAccessKey" : awsSecretAccessKey ,
298- }
299- case "azure" :
300- providers ["azure" ] = map [string ]any {
301- "tenantId" : azureTenantID ,
302- "clientId" : azureClientID ,
303- "clientSecret" : azureClientSecret ,
304- }
305- case "local" :
306- str := providerOpt .Document ().Lookup ("key" ).StringValue ()
307- key , err := base64 .StdEncoding .DecodeString (str )
282+ key := elem .Key ()
283+ opt := elem .Value ().Document ()
284+ provider , err := getKmsProvider (key , opt )
285+ if err != nil {
286+ return nil , err
287+ }
288+ if provider == nil {
289+ continue
290+ }
291+ providers [key ] = provider
292+ if key == "kmip" && tlsClientCertificateKeyFile != "" && tlsCAFile != "" {
293+ cfg , err := options .BuildTLSConfig (map [string ]any {
294+ "tlsCertificateKeyFile" : tlsClientCertificateKeyFile ,
295+ "tlsCAFile" : tlsCAFile ,
296+ })
308297 if err != nil {
309- return nil , err
310- }
311- providers ["local" ] = map [string ]any {
312- "key" : key ,
298+ return nil , fmt .Errorf ("error constructing tls config: %w" , err )
313299 }
314- default :
315- return nil , fmt .Errorf ("unrecognized KMS provider: %v" , provider )
300+ aeo .SetTLSConfig (map [string ]* tls.Config {
301+ "kmip" : cfg ,
302+ })
316303 }
317304 }
318305 aeo .SetKmsProviders (providers )
319306 case "schemaMap" :
320307 var schemaMap map [string ]any
321308 err := bson .Unmarshal (opt .Document (), & schemaMap )
322309 if err != nil {
323- return nil , err
310+ return nil , fmt . Errorf ( "error creating schema map: %v" , err )
324311 }
325312 aeo .SetSchemaMap (schemaMap )
326313 case "keyVaultNamespace" :
327314 kvnsFound = true
328315 aeo .SetKeyVaultNamespace (opt .StringValue ())
316+ case "bypassAutoEncryption" :
317+ aeo .SetBypassAutoEncryption (opt .Boolean ())
318+ case "encryptedFieldsMap" :
319+ var encryptedFieldsMap map [string ]any
320+ err := bson .Unmarshal (opt .Document (), & encryptedFieldsMap )
321+ if err != nil {
322+ return nil , fmt .Errorf ("error creating encryptedFieldsMap: %v" , err )
323+ }
324+ aeo .SetEncryptedFieldsMap (encryptedFieldsMap )
329325 case "bypassQueryAnalysis" :
330326 aeo .SetBypassQueryAnalysis (opt .Boolean ())
331327 default :
0 commit comments