Skip to content

Commit

Permalink
feat(NODE-5004): dont create or drop ecc collections (#3660)
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed May 5, 2023
1 parent c69b0b1 commit 2264fbb
Show file tree
Hide file tree
Showing 129 changed files with 1,837 additions and 2,269 deletions.
2 changes: 2 additions & 0 deletions src/cmap/wire_protocol/constants.ts
Expand Up @@ -2,6 +2,8 @@ export const MIN_SUPPORTED_SERVER_VERSION = '3.6';
export const MAX_SUPPORTED_SERVER_VERSION = '7.0';
export const MIN_SUPPORTED_WIRE_VERSION = 6;
export const MAX_SUPPORTED_WIRE_VERSION = 21;
export const MIN_SUPPORTED_QE_WIRE_VERSION = 21;
export const MIN_SUPPORTED_QE_SERVER_VERSION = '7.0';
export const OP_REPLY = 1;
export const OP_UPDATE = 2001;
export const OP_INSERT = 2002;
Expand Down
18 changes: 16 additions & 2 deletions src/operations/create_collection.ts
@@ -1,6 +1,11 @@
import type { Document } from '../bson';
import {
MIN_SUPPORTED_QE_SERVER_VERSION,
MIN_SUPPORTED_QE_WIRE_VERSION
} from '../cmap/wire_protocol/constants';
import { Collection } from '../collection';
import type { Db } from '../db';
import { MongoCompatibilityError } from '../error';
import type { PkFactory } from '../mongo_client';
import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
Expand Down Expand Up @@ -98,6 +103,10 @@ export interface CreateCollectionOptions extends CommandOperationOptions {
changeStreamPreAndPostImages?: { enabled: boolean };
}

/* @internal */
const INVALID_QE_VERSION =
'Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption.';

/** @internal */
export class CreateCollectionOperation extends CommandOperation<Collection> {
override options: CreateCollectionOptions;
Expand Down Expand Up @@ -127,12 +136,17 @@ export class CreateCollectionOperation extends CommandOperation<Collection> {
db.s.client.options.autoEncryption?.encryptedFieldsMap?.[`${db.databaseName}.${name}`];

if (encryptedFields) {
// Creating a QE collection required min server of 7.0.0
if (server.description.maxWireVersion < MIN_SUPPORTED_QE_WIRE_VERSION) {
throw new MongoCompatibilityError(
`${INVALID_QE_VERSION} The minimum server version required is ${MIN_SUPPORTED_QE_SERVER_VERSION}`
);
}
// Create auxilliary collections for queryable encryption support.
const escCollection = encryptedFields.escCollection ?? `enxcol_.${name}.esc`;
const eccCollection = encryptedFields.eccCollection ?? `enxcol_.${name}.ecc`;
const ecocCollection = encryptedFields.ecocCollection ?? `enxcol_.${name}.ecoc`;

for (const collectionName of [escCollection, eccCollection, ecocCollection]) {
for (const collectionName of [escCollection, ecocCollection]) {
const createOp = new CreateCollectionOperation(db, collectionName, {
clusteredIndex: {
key: { _id: 1 },
Expand Down
3 changes: 1 addition & 2 deletions src/operations/drop.ts
Expand Up @@ -53,10 +53,9 @@ export class DropCollectionOperation extends CommandOperation<boolean> {

if (encryptedFields) {
const escCollection = encryptedFields.escCollection || `enxcol_.${name}.esc`;
const eccCollection = encryptedFields.eccCollection || `enxcol_.${name}.ecc`;
const ecocCollection = encryptedFields.ecocCollection || `enxcol_.${name}.ecoc`;

for (const collectionName of [escCollection, eccCollection, ecocCollection]) {
for (const collectionName of [escCollection, ecocCollection]) {
// Drop auxilliary collections, ignoring potential NamespaceNotFound errors.
const dropOp = new DropCollectionOperation(db, collectionName);
try {
Expand Down
Expand Up @@ -6,7 +6,7 @@ import { installNodeDNSWorkaroundHooks } from '../../tools/runner/hooks/configur
const metadata: MongoDBMetadataUI = {
requires: {
clientSideEncryption: true,
mongodb: '>=6.0.0',
mongodb: '>=7.0.0',
topology: '!single'
}
} as const;
Expand Down
@@ -1,7 +1,4 @@
{
"escCollection": "enxcol_.default.esc",
"eccCollection": "enxcol_.default.ecc",
"ecocCollection": "enxcol_.default.ecoc",
"fields": [
{
"keyId": {
Expand Down Expand Up @@ -30,4 +27,4 @@
"bsonType": "string"
}
]
}
}
@@ -1,30 +1,33 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"contention": {
"$numberLong": "0"
},
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"sparsity": {
"$numberLong": "1"
},
"min": {
"$date": {
"$numberLong": "0"
}
},
"max": {
"$date": {
"$numberLong": "200"
"sparsity": {
"$numberLong": "1"
},
"min": {
"$date": {
"$numberLong": "0"
}
},
"max": {
"$date": {
"$numberLong": "200"
}
}
}
]
}
]
}
@@ -1,21 +1,23 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedDecimalNoPrecision",
"bsonType": "decimal",
"queries": {
"queryType": "rangePreview",
"contention": {
"$numberLong": "0"
},
"path": "encryptedDecimalNoPrecision",
"bsonType": "decimal",
"queries": {
"queryType": "rangePreview",
"sparsity": {
"$numberInt": "1"
}
"sparsity": {
"$numberLong": "1"
}
}
]
}
}
]
}
Expand Up @@ -11,8 +11,11 @@
"bsonType": "decimal",
"queries": {
"queryType": "rangePreview",
"contention": {
"$numberLong": "0"
},
"sparsity": {
"$numberInt": "1"
"$numberLong": "1"
},
"min": {
"$numberDecimal": "0.0"
Expand Down
@@ -1,21 +1,23 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedDoubleNoPrecision",
"bsonType": "double",
"queries": {
"queryType": "rangePreview",
"contention": {
"$numberLong": "0"
},
"path": "encryptedDoubleNoPrecision",
"bsonType": "double",
"queries": {
"queryType": "rangePreview",
"sparsity": {
"$numberLong": "1"
}
"sparsity": {
"$numberLong": "1"
}
}
]
}
}
]
}
@@ -1,30 +1,32 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedDoublePrecision",
"bsonType": "double",
"queries": {
"queryType": "rangePreview",
"contention": {
"$numberLong": "0"
},
"sparsity": {
"$numberLong": "1"
},
"min": {
"$numberDouble": "0.0"
},
"max": {
"$numberDouble": "200.0"
},
"path": "encryptedDoublePrecision",
"bsonType": "double",
"queries": {
"queryType": "rangePreview",
"sparsity": {
"$numberLong": "1"
},
"min": {
"$numberDouble": "0.0"
},
"max": {
"$numberDouble": "200.0"
},
"precision": {
"$numberInt": "2"
}
"precision": {
"$numberInt": "2"
}
}
]
}
}
]
}
@@ -1,27 +1,29 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedInt",
"bsonType": "int",
"queries": {
"queryType": "rangePreview",
"contention": {
"$numberLong": "0"
},
"sparsity": {
"$numberLong": "1"
},
"min": {
"$numberInt": "0"
},
"path": "encryptedInt",
"bsonType": "int",
"queries": {
"queryType": "rangePreview",
"sparsity": {
"$numberLong": "1"
},
"min": {
"$numberInt": "0"
},
"max": {
"$numberInt": "200"
}
"max": {
"$numberInt": "200"
}
}
]
}
}
]
}

0 comments on commit 2264fbb

Please sign in to comment.