Skip to content

Commit

Permalink
DRIVERS-2927 Make trimFactor and sparsity optional (mongodb#1613)
Browse files Browse the repository at this point in the history
* add test for default `trimFactor` and `sparsity` in auto encryption payload

* add prose test for explicit encryption

* specify `trimFactor` and `sparsity` as optional

* briefly describe `trimFactor` and `sparsity`, `min`, `max`, `precision`, and `contentionFactor`

More detailed description is deferred to mongodb.com docs.

---------

Co-authored-by: Ezra Chung <[email protected]>
Co-authored-by: Noah Stapp <[email protected]>
  • Loading branch information
3 people authored Jul 24, 2024
1 parent 82be6f2 commit 38162ec
Show file tree
Hide file tree
Showing 5 changed files with 796 additions and 11 deletions.
27 changes: 16 additions & 11 deletions source/client-side-encryption/client-side-encryption.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- Status: Accepted
- Minimum Server Version: 4.2 (CSFLE), 6.0 (Queryable Encryption)
- Version: 1.13.0
- Version: 1.14.0

______________________________________________________________________

Expand Down Expand Up @@ -1168,13 +1168,15 @@ class EncryptOpts {
// min, max, trimFactor, sparsity, and precision must match the values set in the encryptedFields of the destination collection.
// For double and decimal128, min/max/precision must all be set, or all be unset.
class RangeOpts {
// min is required if precision is set.
// min is the minimum value for the encrypted index. Required if precision is set.
min: Optional<BSONValue>,
// max is required if precision is set.
// max is the maximum value for the encrypted index. Required if precision is set.
max: Optional<BSONValue>,
trimFactor: Int32,
sparsity: Int64,
// precision may only be set for double or decimal128.
// trimFactor may be used to tune performance. When omitted, a default value is used.
trimFactor: Optional<Int32>,
// sparsity may be used to tune performance. When omitted, a default value is used.
sparsity: Optional<Int64>,
// precision determines the number of significant digits after the decimal point. May only be set for double or decimal128.
precision: Optional<Int32>
}
```
Expand Down Expand Up @@ -1212,8 +1214,8 @@ query. Drivers MUST document the following behavior:

#### contentionFactor

contentionFactor only applies when algorithm is "Indexed" or "Range". It is an error to set contentionFactor when
algorithm is not "Indexed" or "Range".
contentionFactor may be used to tune performance. Only applies when algorithm is "Indexed" or "Range". libmongocrypt
returns an error if contentionFactor is set for a non-applicable algorithm.

#### queryType

Expand All @@ -1222,15 +1224,16 @@ One of the strings:
- "equality"
- "range"

queryType only applies when algorithm is "Indexed" or "Range". It is an error to set queryType when algorithm is not
"Indexed" or "Range".
queryType only applies when algorithm is "Indexed" or "Range". libmongocrypt returns an error if queryType is set for a
non-applicable queryType.

> [!NOTE]
> The "range" queryType is currently unstable API and subject to backwards breaking changes.

#### rangeOpts

rangeOpts only applies when algorithm is "range". It is an error to set rangeOpts when algorithm is not "range".
rangeOpts only applies when algorithm is "range". libmongocrypt returns an error if rangeOpts is set for a
non-applicable algorithm.

> [!NOTE]
> rangeOpts is currently unstable API and subject to backwards breaking changes.
Expand Down Expand Up @@ -2380,6 +2383,8 @@ explicit session parameter as described in the [Drivers Sessions Specification](

## Changelog

- 2024-07-22: Make `trimFactor` and `sparsity` optional.

- 2024-06-13: Document range as unstable.

- 2024-05-31: Replace rangePreview with range.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Test "range" field with defaults for `trimFactor` and `sparsity`.
# Test requires libmongocrypt with changes in 14ccd9ce (MONGOCRYPT-698).
runOn:
- minServerVersion: "8.0.0" # Requires 8.0.0-rc13.
topology: [ "replicaset", "sharded", "load-balanced" ] # Exclude "standalone". QE collections are not supported on standalone.
database_name: &database_name "default"
collection_name: &collection_name "default"
data: []
encrypted_fields: &encrypted_fields {
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedInt",
"bsonType": "int",
"queries": {
"queryType": "range",
# Exclude `trimFactor` and `sparsity`
"contention": { "$numberLong": "0" },
"min": { "$numberInt": "0" },
"max": { "$numberInt": "200" }
}
}
]
}
key_vault_data: [ {{ yamlfile("keys/key1-document.json") }} ]
tests:
- description: "FLE2 Range applies defaults for trimFactor and sparsity"
clientOptions:
autoEncryptOpts:
kmsProviders:
local: {{ local_provider() }}
operations:
- name: insertOne
arguments:
document: &doc0 { _id: 0, encryptedInt: { $numberInt: "0" } }
- name: insertOne
arguments:
document: &doc1 { _id: 1, encryptedInt: { $numberInt: "1" } }
- name: find
arguments:
filter: { encryptedInt: { $gt: { $numberInt: "0" } } }
result: [*doc1]
expectations:
- command_started_event:
command:
listCollections: 1
filter:
name: *collection_name
command_name: listCollections
- command_started_event:
command:
find: datakeys
filter: {
"$or": [
{
"_id": {
"$in": [
{{ yamlfile("keys/key1-id.json") }}
]
}
},
{
"keyAltNames": {
"$in": []
}
}
]
}
$db: keyvault
readConcern: { level: "majority" }
command_name: find
- command_started_event:
command:
insert: *collection_name
documents:
- &doc0_encrypted { "_id": 0, "encryptedInt": { $$type: "binData" } }
ordered: true
encryptionInformation: &encryptionInformation
type: 1
schema:
default.default:
# libmongocrypt applies escCollection and ecocCollection to outgoing command.
escCollection: "enxcol_.default.esc"
ecocCollection: "enxcol_.default.ecoc"
<<: *encrypted_fields
command_name: insert
- command_started_event:
command:
insert: *collection_name
documents:
- &doc1_encrypted { "_id": 1, "encryptedInt": { $$type: "binData" } }
ordered: true
encryptionInformation: *encryptionInformation
command_name: insert
- command_started_event:
command:
find: *collection_name
filter:
"encryptedInt": {
"$gt": {
"$binary": {
"base64": "DfQaAAADcGF5bG9hZADEGgAABGcAsBoAAAMwAH0AAAAFZAAgAAAAALGGQ/CRD+pGLD53BZzWcCcYbuGLVEyjzXIx7b+ux/q2BXMAIAAAAACOC6mXEZL27P9hethZbtKYsTXKK+FpgQ9Axxmn9N/cCwVsACAAAAAA+MFEd8XfZSpbXKqqPC2L3TEFswkaG5Ff6aSgf8p+XVIAAzEAfQAAAAVkACAAAAAA30oqY6NKy1KWDWf6Z36DtA2QsL9JRALvHX6smxz8cb4FcwAgAAAAADIhM0hCHwFGH+k7kPGuZlO+v5TjV6RRwA5FqUKM60o0BWwAIAAAAABTMPNUweBKrILSCxc5gcgjn9pTkkKX7KqWXgNMk4q7XgADMgB9AAAABWQAIAAAAACnCDvYEbgR9fWeQ8SatKNX43p0XIXTyFfzc7/395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3ImoA7p8ujAZIfvIDo6QVsACAAAAAA+W0+zgLr85/PD7P9a94wk6MgNgrizx/XU9aCxAkp1IwAABJjbQAAAAAAAAAAAAAQcGF5bG9hZElkAAAAAAAQZmlyc3RPcGVyYXRvcgABAAAAAA==",
"subType": "06"
}
}
}
encryptionInformation: *encryptionInformation
command_name: find
outcome:
collection:
data:
-
{
"_id": 0,
"encryptedInt": { $$type: "binData" },
# Expected contents of `__safeContent__` require MONGOCRYPT-698 to apply expected `trimFactor`.
"__safeContent__": [
{
"$binary": {
"base64": "RjBYT2h3ZAoHxhf8DU6/dFbDkEBZp0IxREcsRTu2MXs=",
"subType": "00"
}
},
{
"$binary": {
"base64": "+vC6araOEo+fpW7PSIP40/EnzBCj1d2N10Jr3rrXJJM=",
"subType": "00"
}
}
]
}
-
{
"_id": {
"$numberInt": "1"
},
"encryptedInt": { $$type: "binData" },
"__safeContent__": [
{
"$binary": {
"base64": "25j9sQXZCihCmHKvTHgaBsAVZFcGPn7JjHdrCGlwyyw=",
"subType": "00"
}
},
{
"$binary": {
"base64": "SlNHXyqVFGDPrX/2ppwog6l4pwj3PKda2TkZbqgfSfA=",
"subType": "00"
}
}
]
}
85 changes: 85 additions & 0 deletions source/client-side-encryption/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3210,3 +3210,88 @@ class EncryptOpts {
```
Assert that an error was raised.
### 22. Range Explicit Encryption applies defaults
This test requires libmongocrypt with changes in
[14ccd9ce](https://github.com/mongodb/libmongocrypt/commit/14ccd9ce8a030158aec07f63e8139d34b95d88e6)
([MONGOCRYPT-698](https://jira.mongodb.org/browse/MONGOCRYPT-698)).
#### Test Setup
Create a MongoClient named `keyVaultClient`.
Create a ClientEncryption object named `clientEncryption` with these options:
```typescript
class ClientEncryptionOpts {
keyVaultClient: keyVaultClient,
keyVaultNamespace: "keyvault.datakeys",
kmsProviders: { "local": { "key": "<base64 decoding of LOCAL_MASTERKEY>" } },
}
```
Create a key with `clientEncryption.createDataKey`. Store the returned key ID in a variable named `keyId`.
Call `clientEncryption.encrypt` to encrypt the int32 value `123` with these options:
```typescript
class EncryptOpts {
keyId : keyId,
algorithm: "Range",
contentionFactor: 0,
rangeOpts: RangeOpts {
min: 0,
max: 1000
}
}
```
Store the result in a variable named `payload_defaults`.
#### Case 1: Uses libmongocrypt defaults
Call `clientEncryption.encrypt` to encrypt the int32 value `123` with these options:
```typescript
class EncryptOpts {
keyId : keyId,
algorithm: "Range",
contentionFactor: 0,
rangeOpts: RangeOpts {
min: 0,
max: 1000,
sparsity: 2,
trimFactor: 6
}
}
```
Assert the returned payload size equals the size of `payload_defaults`.
> [!NOTE]
> Do not compare the payload contents. The payloads include random data. The `trimFactor` and `sparsity` directly affect
> the payload size.
#### Case 2: Accepts `trimFactor` 0
Call `clientEncryption.encrypt` to encrypt the int32 value `123` with these options:
```typescript
class EncryptOpts {
keyId : keyId,
algorithm: "Range",
contentionFactor: 0,
rangeOpts: RangeOpts {
min: 0,
max: 1000,
trimFactor: 0
}
}
```
Assert the returned payload size is greater than the size of `payload_defaults`.
> [!NOTE]
> Do not compare the payload contents. The payloads include random data. The `trimFactor` and `sparsity` directly affect
> the payload size.
Loading

0 comments on commit 38162ec

Please sign in to comment.