Skip to content

CDRIVER-4317 Add support for rewrapManyDataKey and keyMaterial #991

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

Merged
merged 38 commits into from
May 18, 2022

Conversation

eramongodb
Copy link
Contributor

This PR is a part of CDRIVER-4317. It is being reviewed as the PoC implementation of changes proposed in mongodb/specifications#1213.

This PR:

  1. Moves existing CSE tests into a legacy subdirectory.
  2. Adds new unified tests added in DRIVERS-2017 Add spec and tests for rewrapManyDataKey and custom keyMaterial specifications#1213 under new unified subdirectory.
  3. Adds support for the new rewrapManyDataKey() function to C Driver API.
  4. Adds support for the new keyMaterial field to C Driver API.
  5. Adds support for testing both new features in the unified test runner.

As drive-by improvements, const was added to the parameters of some helper functions in result.h and a new result_from_bulk_write() helper function was added to result.h for reusability of bulkWriteResult result comparisons.

@eramongodb eramongodb requested review from jmikola and kevinAlbs May 10, 2022 20:48
@eramongodb eramongodb self-assigned this May 10, 2022
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

Turning in for the night, but wanted to dump my partial review with some comments on mongoc-client-side-encryption.c while it was fresh in my head.

Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

Looking good. Before merging, please add documentation for the new functions.

To report leaks locally, build with -fsanitize=leak -fsanitize=address and use the environment variables:

export ASAN_OPTIONS='detect_leaks=1'
export LSAN_OPTIONS='suppressions=.lsan-suppressions'

The test failure on ASAN for /client_side_encryption/legacy/explain may be resolved by updating skip-tests.txt with the new path to /client_side_encryption/legacy/explain.

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

One remaining suggestion to number the prose test and an optional change (to your preference). I think that's about as far as I can reasonably review in this PR :)

@kevinAlbs kevinAlbs self-requested a review May 17, 2022 18:28
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

LGTM with addition of majority write concern to insert in prose test.

}

/* Create a ClientEncryption object (referred to as client_encryption) with
* keyvault.datakeys as the keyVaultClient. */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* keyvault.datakeys as the keyVaultClient. */
* keyvault.datakeys as the keyVaultNamespace. */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 783 to 797
mongoc_collection_t *const datakeys =
mongoc_client_get_collection (client, "keyvault", "datakeys");
bson_t modified_datakey = BSON_INITIALIZER;
uint8_t bytes[16] = {0};

bson_copy_to_excluding_noinit (&datakey, &modified_datakey, "_id", NULL);
BSON_ASSERT (BSON_APPEND_BINARY (
&modified_datakey, "_id", BSON_SUBTYPE_UUID, bytes, sizeof (bytes)));

ASSERT_OR_PRINT (mongoc_collection_insert_one (
datakeys, &modified_datakey, NULL, NULL, &error),
error);

mongoc_collection_destroy (datakeys);
bson_destroy (&modified_datakey);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use majority write concern to insert. Majority read concern is used to find keys. If majority write concern is not used, the find may not see the inserted document if it has not replicated to a majority of nodes in a replica set. Also suggested on the specification https://github.com/mongodb/specifications/pull/1213/files#r875179801

Here is a sample of setting majority write concern:

      mongoc_write_concern_t *wc;
      bson_t insert_opts = BSON_INITIALIZER;

      wc = mongoc_write_concern_new ();
      mongoc_write_concern_set_w (wc, MONGOC_WRITE_CONCERN_W_MAJORITY);
      mongoc_write_concern_append (wc, &insert_opts);

      ASSERT_OR_PRINT (
         mongoc_collection_insert_one (
            datakeys, &modified_datakey, NULL, &insert_opts, &error),
         error);

      mongoc_write_concern_destroy (wc);
      bson_destroy (&insert_opts);

@kevinAlbs
Copy link
Collaborator

Before merging, try merging changes from #995 to get past the system failures.

@eramongodb
Copy link
Contributor Author

Spec tests updated to account for "no additional keys" requirement of non-root document matching in expectResult. Documentation for new API functions also added.

@eramongodb eramongodb merged commit 958b871 into mongodb:master May 18, 2022
@eramongodb eramongodb deleted the createKey-and-rewrapManyDataKey branch May 18, 2022 20:22
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