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

MONGOCRYPT-463 check the collMod command for validator.$jsonSchema #441

Merged
merged 5 commits into from
Aug 12, 2022

Conversation

kevinAlbs
Copy link
Contributor

@kevinAlbs kevinAlbs commented Aug 12, 2022

Summary

  • Check the collMod command for validator.$jsonSchema and send it to query analysis.

Background & Motivation

Checking collMod for validator.$jsonSchema

Since MONGOCRYPT-429, automatic encryption has supported the collMod command. Prior to MONGOCRYPT-429, it was always an error to automatically encrypt a collMod command. A collMod command is not bypassed because it may include sensitive plaintext in a validator field:

{
    "collMod": "encryptedCollection",
    "validator": {
        "encryptedField": "plaintext",
    }
}

A collMod command may also include a validator.$jsonSchema:

{
    "collMod": "encryptedCollection",
    "validator": {
        "$jsonSchema": {
            "encryptedField": {
                "encrypt": {
                    "bsonType": "string",
                    "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic",
                    "keyId": {
                        "$binary": {
                            "base64": "AAAAAAAAAAAAAAAAAAAAAA==",
                            "subType": "04"
                        }
                    }
                }
            }
        }
    }
}

If a collMod includes a validator.$jsonSchema, Query Analysis (mongocryptd or the mongo_crypt shared library) expects the jsonSchema field added by libmongocrypt to match. See MONGOCRYPT-463 for an example of this error.

A regression specification test is tested with the Go driver here

@kevinAlbs kevinAlbs changed the title M463 MONGOCRYPT-463 check the collMod command for validator.$jsonSchema Aug 12, 2022
Copy link
Contributor

@vector-of-bool vector-of-bool left a comment

Choose a reason for hiding this comment

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

LGTM, but one odd comment

@@ -1946,19 +1947,23 @@ _try_empty_schema_for_create (mongocrypt_ctx_t *ctx)
* }
* }
* If the "create" command does not include a JSON schema, an empty JSON schema
* is returned. This is to avoid an unnecessary 'listCollections' command for
* create. */
* is later. This is to avoid an unnecessary 'listCollections' command for
Copy link
Contributor

Choose a reason for hiding this comment

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

"is later"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

@eramongodb eramongodb left a comment

Choose a reason for hiding this comment

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

Minor suggestion; otherwise, LGTM.

* create.
*
* If the "collMod" command does not include a JSON schema, a schema is later
* requested from other sources. This is because a "collMod" command may have
Copy link
Contributor

Choose a reason for hiding this comment

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

Can "from other sources" be made more specific, e.g. mention the MONGOCRYPT_CTX_NEED_MONGO_COLLINFO state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@kevinAlbs kevinAlbs merged commit f87e575 into mongodb:master Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants