-
Notifications
You must be signed in to change notification settings - Fork 917
GODRIVER-2352 Add clientEncryption entity to unified test format #920
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
Conversation
ClientEncryption.Close() calls Disconnect on the keyVaultClient. Track IDs of clients used as keyVaultClient.
skip 1.7
mongo/integration/unified/entity.go
Outdated
return newEntityNotFoundError("client", ceo.KeyVaultClient) | ||
} | ||
|
||
ce, err := mongo.NewClientEncryption(keyVaultClient.Client, options.ClientEncryption().SetKeyVaultNamespace(ceo.KeyVaultNamespace).SetKmsProviders(kmsProviders)) |
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.
Optional: Consider wrapping this line to make it easier to read.
E.g.
ce, err := mongo.NewClientEncryption(
keyVaultClient.Client,
options.ClientEncryption().
SetKeyVaultNamespace(ceo.KeyVaultNamespace).
SetKmsProviders(kmsProviders))
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.
Done.
mongo/integration/unified/entity.go
Outdated
// getKmsCredential processes a value of an input KMS provider credential. | ||
// An empty document returns from the environment. | ||
// A string is returned as-is. | ||
func getKmsCredential(kmsDocument bson.Raw, credentialName string, defaultValue string) (*string, error) { |
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.
Unless there's a specific reason to return a *string
, it's typically more idiomatic to return a string
and use the string zero-value (""
) as the return value in case of an error.
E.g.
func getKmsCredential(kmsDocument bson.Raw, credentialName string, defaultValue string) (string, error) {
// ...
return "", err
// ...
}
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.
Done. That is good to know. My instinct is to use pointer for optional.
mongo/integration/unified/entity.go
Outdated
// getKmsCredential processes a value of an input KMS provider credential. | ||
// An empty document returns from the environment. | ||
// A string is returned as-is. | ||
func getKmsCredential(kmsDocument bson.Raw, credentialName string, defaultValue string) (*string, error) { |
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.
Optional: If all defaultValue
s come from environment variables, consider replacing the defaultValue
parameter with an environment variable name parameter and perform the env var lookup in getKmsCredential
. That would allow more specific messaging about any missing environment variables rather than the less specific "Please set CSFLE environment variables" message.
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.
Great idea. Some credentials have default values and no environment variable. Updated to separate the defaultValue
from the environment variable, and print the environment variable in the error message.
|
||
// CSFLEEnabled returns true if driver is built with Client Side Field Level Encryption support. | ||
// Client Side Field Level Encryption support is enabled with the cse build tag. | ||
func CSFLEEnabled() bool { |
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.
Optional: Functions that don't modify anything and return only a bool
conventionally have "is" or "has" in the name. Consider updating to the slightly more conventional IsCSFLEEnabled()
.
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.
Done.
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.
Very cool!
mongo/integration/mtest/mongotest.go
Outdated
if rob.CSFLE != nil { | ||
if *rob.CSFLE != IsCSFLEEnabled() { |
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.
if rob.CSFLE != nil { | |
if *rob.CSFLE != IsCSFLEEnabled() { | |
if rob.CSFLE != nil && *rob.CSFLE != IsCSFLEEnabled() { |
Suggestion to combine the two if lines into one to lower cyclomatic complexity.
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.
Done.
if local, ok := ceo.KmsProviders["local"]; ok { | ||
kmsProviders["local"] = make(map[string]interface{}) | ||
|
||
defaultLocalKeyBase64 := "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk" |
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.
Should this be exposed in the repository?
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.
Yes, this local master key is used to encrypt test data. It is not sensitive, and is included in the specification test README.
if kmip, ok := ceo.KmsProviders["kmip"]; ok { | ||
kmsProviders["kmip"] = make(map[string]interface{}) | ||
|
||
kmipEndpoint, err := getKmsCredential(kmip, "endpoint", "", "localhost:5698") |
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.
Is the port always 5698
or could this change?
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.
This is expected to be 5698 from the specification test README
Start a KMIP test server on port 5698 by running drivers-evergreen-tools/.evergreen/csfle/kms_kmip_server.py.
gosec reports a false positive "Hardcoded credentials". See: https://securego.io/docs/rules/g101.html
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.
Looks good 👍
mongo/integration/unified/entity.go
Outdated
// A string is returned as-is. | ||
func getKmsCredential(kmsDocument bson.Raw, credentialName string, envVar string, defaultValue string) (string, error) { | ||
credentialVal, err := kmsDocument.LookupErr(credentialName) | ||
if err == nil { |
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.
Optional: Consider inverting this error check to return early so you can un-indent the rest of the function code.
E.g.
credentialVal, err := kmsDocument.LookupErr(credentialName)
if err == bsoncore.ErrElementNotFound {
return "", nil
}
if err != nil {
return "", err
}
// ...
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.
Done.
mongo/integration/unified/entity.go
Outdated
return str, nil | ||
} | ||
|
||
if doc, ok := credentialVal.DocumentOK(); ok { |
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.
Optional: Similar to above, consider inverting this check to return early.
E.g.
doc, ok := credentialVal.DocumentOK()
if !ok {
return "", fmt.Errorf("expected String or Document for %v, got: %v", credentialName, credentialVal)
}
// ...
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.
Done.
GODRIVER-2352
Add Unified Test Format support for 1.8. This is a prerequisite for the Go implementation of the CSFLE Key Management API.
Background & Motivation
See mongodb/specifications@e91f0ec and mongodb/specifications@0f65908 for the Unified Test Format changes.
Notes
ClientEncryption.Close()
callsDisconnect
on the keyVaultClient. Client entities used as keyVaultClients are tracked to prevent the test runner from callingDisconnect
twice.