-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
CSFLE support #15390
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
CSFLE support #15390
Changes from all commits
3fbefcc
19c0132
db8eef7
f1c986c
682fb11
cda0e26
edfbdfa
1a48b98
065bc99
a8f37eb
53d31a6
888c0a8
5d3b51f
2c02d45
ecb3f7c
b7016de
14a40ff
59af7cf
2fc58da
b739793
db05164
6c9b5f6
aee89e8
8a2c374
08169cd
92bb79b
a0e4bdd
a66b479
d3bed74
d53600e
a9ace50
25ee432
523fdd3
ff411c1
da9f98e
db72dbf
3777b5b
1e342ff
7634218
eab7e49
460626a
f9e7684
411a655
699c82d
6fc22b6
df21dee
d2c1820
02f2521
387c957
a7e7ce5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,8 @@ module.exports = { | |
'!.*', | ||
'node_modules', | ||
'.git', | ||
'data' | ||
'data', | ||
'.config' | ||
], | ||
overrides: [ | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,4 +72,4 @@ notes.md | |
list.out | ||
|
||
data | ||
*.pid | ||
fle-cluster-config.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,51 @@ const CUSTOMIZABLE_DISCRIMINATOR_OPTIONS = { | |
methods: true | ||
}; | ||
|
||
/** | ||
* Validate fields declared on the child schema when either schema is configured for encryption. Specifically, this function ensures that: | ||
* | ||
* - any encrypted fields are declared on exactly one of the schemas (not both) | ||
* - encrypted fields cannot be declared on either the parent or child schema, where the other schema declares the same field without encryption. | ||
* | ||
* @param {Schema} parentSchema | ||
* @param {Schema} childSchema | ||
*/ | ||
function validateDiscriminatorSchemasForEncryption(parentSchema, childSchema) { | ||
if (parentSchema.encryptionType() == null && childSchema.encryptionType() == null) return; | ||
|
||
const allSharedNestedPaths = setIntersection( | ||
allNestedPaths(parentSchema), | ||
allNestedPaths(childSchema) | ||
); | ||
|
||
for (const path of allSharedNestedPaths) { | ||
if (parentSchema._hasEncryptedField(path) && childSchema._hasEncryptedField(path)) { | ||
throw new Error(`encrypted fields cannot be declared on both the base schema and the child schema in a discriminator. path=${path}`); | ||
} | ||
|
||
if (parentSchema._hasEncryptedField(path) || childSchema._hasEncryptedField(path)) { | ||
throw new Error(`encrypted fields cannot have the same path as a non-encrypted field for discriminators. path=${path}`); | ||
} | ||
} | ||
|
||
function allNestedPaths(schema) { | ||
return [...Object.keys(schema.paths), ...Object.keys(schema.singleNestedPaths)]; | ||
} | ||
|
||
/** | ||
* @param {Iterable<string>} i1 | ||
* @param {Iterable<string>} i2 | ||
*/ | ||
function* setIntersection(i1, i2) { | ||
const s1 = new Set(i1); | ||
for (const item of i2) { | ||
if (s1.has(item)) { | ||
yield item; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/*! | ||
* ignore | ||
*/ | ||
|
@@ -80,6 +125,8 @@ module.exports = function discriminator(model, name, schema, tiedValue, applyPlu | |
value = tiedValue; | ||
} | ||
|
||
validateDiscriminatorSchemasForEncryption(model.schema, schema); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not quite sure where this is in the discriminator chain, but if for example a child schema is passed-in that is already a clone of the parent, like typegoose currently does, wouldnt this also throw "duplicate encryption field" errors? Is this a case that should be supported? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you elaborate on what exactly you mean by "a child discriminator that is a clone of the parent"? Do you mean that the child already has all fields from the parent added to it as well? Or is there something else you're referring to here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @baileympearson some devs prefer to pass a schema with the parent parents included in
Can you add a test case for that please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added tests in #15407. Just to be clear though - the implementation does not support this pattern and the tests I added demonstrate that this code throws |
||
|
||
function merge(schema, baseSchema) { | ||
// Retain original schema before merging base schema | ||
schema._baseSchema = baseSchema; | ||
|
Uh oh!
There was an error while loading. Please reload this page.