Skip to content
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

GODRIVER-3289 Add option to configure DEK cache lifetime. #1922

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

qingyang-hu
Copy link
Collaborator

@qingyang-hu qingyang-hu commented Jan 16, 2025

GODRIVER-3289

Summary

  • Add option to configure DEK cache lifetime.
  • Add support for keyExpirationMS and decrypt in the spec tests.
  • Cleanup (*Client) configureAutoEncryption().

Background & Motivation

Add an option to configure DEK cache lifetime.

Specs updates:

@mongodb-drivers-pr-bot mongodb-drivers-pr-bot bot added the priority-3-low Low Priority PR for Review label Jan 16, 2025
Copy link
Contributor

API Change Report

./v2/mongo/options

compatible changes

(*AutoEncryptionOptions).SetKeyExpiration: added
(*ClientEncryptionOptionsBuilder).SetKeyExpiration: added
AutoEncryptionOptions.KeyExpiration: added
ClientEncryptionOptions.KeyExpiration: added

./v2/x/mongo/driver/mongocrypt/options

compatible changes

(*MongoCryptOptions).SetKeyExpiration: added
MongoCryptOptions.KeyExpiration: added

@qingyang-hu qingyang-hu force-pushed the godriver3289 branch 7 times, most recently from 50eee42 to 6319ce0 Compare January 17, 2025 19:46
@qingyang-hu qingyang-hu marked this pull request as ready for review January 21, 2025 15:43
@@ -164,3 +166,10 @@ func (a *AutoEncryptionOptions) SetBypassQueryAnalysis(bypass bool) *AutoEncrypt

return a
}

// SetKeyExpiration specifies duration for the key expiration. 0 or negative value means "never expire".
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are negative values interpreted by libmongocrypt as "never expire" or are we enforcing that behavior in the Go Driver? I can't find documentation on the negative case. The C and Rust implementations use uint64.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Negative values are handled in x/mongo/driver/mongocrypt/mongocrypt.go by passing 0 to libmongocrypt. I'm open to using uint64 to align the API with other drivers.

@@ -193,7 +193,7 @@ func newClient(opts ...*options.ClientOptions) (*Client, error) {
}
// AutoEncryptionOptions
if clientOpts.AutoEncryptionOptions != nil {
if err := client.configureAutoEncryption(clientOpts); err != nil {
if err = client.configureAutoEncryption(clientOpts); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a particular scoping or style reason for migrating from the variable declaration to assignment?

Comment on lines +493 to +515
kr := keyRetriever{coll: c.keyVaultCollFLE}
var cir collInfoRetriever
bypass := aeOpts.BypassAutoEncryption != nil && *aeOpts.BypassAutoEncryption
if !bypass {
if args.MaxPoolSize != nil && *args.MaxPoolSize == 0 {
c.metadataClientFLE = c
} else {
c.metadataClientFLE, err = c.getOrCreateInternalClient(args)
if err != nil {
return err
}
}
cir.client = c.metadataClientFLE
}

c.cryptFLE = driver.NewCrypt(&driver.CryptOptions{
MongoCrypt: mc,
CollInfoFn: cir.cryptCollInfo,
KeyFn: kr.cryptKeys,
MarkFn: c.mongocryptdFLE.markCommand,
TLSConfig: aeOpts.TLSConfig,
BypassAutoEncryption: bypass,
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactor seems unrelated to DEK cache lifetime. I think this should be reverted to avoid confusing the scope of this PR.

keyExpirationMs = uint64(expirationMs)
}
}
C.mongocrypt_setopt_key_expiration(crypt.wrapped, C.uint64_t(keyExpirationMs))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we expose this type as a uint64 instead of a time.Duration in the options API? That is the convention for both C and Rust:

Rust: https://github.com/mongodb/libmongocrypt-rust/pull/38/files
C: mongodb/mongo-c-driver@b0edf30#diff-782e2ab0e9ed19e1fc3e8e7bb5587e57805d5c816b85ab4b606da41de292bc77R137

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, time.Duration is more expressive. We also use it for duration values in other option structs. However, I'm open to using uint64 if it simplifies the API and improves consistency with other drivers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-3-low Low Priority PR for Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants