@@ -4,7 +4,7 @@ Client Side Encryption
4
4
5
5
:Status: Accepted
6
6
:Minimum Server Version: 4.2 (CSFLE), 6.0 (Queryable Encryption)
7
- :Last Modified: 2022-11-04
7
+ :Last Modified: 2022-11-10
8
8
:Version: 1.11.0
9
9
10
10
.. _lmc-c-api : https://github.com/mongodb/libmongocrypt/blob/master/src/mongocrypt.h.in
@@ -837,9 +837,13 @@ encryptedFieldsMap
837
837
838
838
``encryptedFieldsMap `` only applies to Queryable Encryption.
839
839
840
- If a collection is present on both the ``encryptedFieldsMap `` and ``schemaMap ``, libmongocrypt _ will error on initialization. See :ref: `fle2-and-fle1-error `.
840
+ If a collection is present on both the ``encryptedFieldsMap `` and ``schemaMap ``,
841
+ libmongocrypt _ will error on initialization. See :ref: `fle2-and-fle1-error `.
841
842
842
- If a collection is present on the ``encryptedFieldsMap ``, the behavior of ``CreateCollection() `` and ``Collection.Drop() `` is altered. See :ref: `fle2-createcollection-drop `.
843
+ If a collection has a set of encrypted fields, the behavior of
844
+ ``CreateCollection() `` and ``Collection.Drop() `` is altered. An additional
845
+ helper, ``CreateEncryptedCollection() `` has been defined as a convenience
846
+ wrapper around ``CreateCollection() ``. See :ref: `fle2-createcollection-drop `.
843
847
844
848
Automatic encryption in Queryable Encryption is configured with the ``encryptedFields ``.
845
849
@@ -864,6 +868,42 @@ A collection supporting Queryable Encryption requires an index and three additio
864
868
.. _create : https://www.mongodb.com/docs/manual/reference/command/create
865
869
.. _drop : https://www.mongodb.com/docs/manual/reference/command/drop
866
870
871
+
872
+ .. _GetEncryptedFields :
873
+
874
+ Collection ``encryptedFields `` Lookup (GetEncryptedFields)
875
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
876
+
877
+ The convenience methods support the following lookup process for finding the
878
+ ``encryptedFields `` associated with a collection.
879
+
880
+ .. default-role :: math
881
+
882
+ Assume an exposition-only function
883
+ `GetEncryptedFields(opts, collName, dbName, askDb) `, where `opts ` is a set of
884
+ options, `collName ` is the name of the collection, `dbName ` is the name of the
885
+ database associated with that collection, and `askDb ` is a boolean value. The
886
+ resulting ``encryptedFields `` `EF ` is found by:
887
+
888
+ 1. Let `QualName ` be the string formed by joining `dbName ` and `collName ` with
889
+ an ASCII dot ``"." ``.
890
+ 2. If `opts ` contains an ``"encryptedFields" `` property, then `EF ` is the value
891
+ of that property.
892
+ 3. Otherwise, if ``AutoEncryptionOptions.encryptedFieldsMap `` contains an
893
+ element named by `QualName `, then `EF ` is the value of that element.
894
+ 4. Otherwise, if `askDb ` is `true `:
895
+
896
+ 1. Issue a ``listCollections `` command against the database named by
897
+ `dbName `, filtered by ``{name: <collName>} ``. Let the result be the
898
+ document `L `.
899
+ 2. If `L ` contains an ``options `` document element, and that element contains
900
+ an ``encryptedFields `` document element, `EF ` is `L `\
901
+ ``["options"]["encryptedFields"] ``.
902
+ 3. Otherwise, `EF ` is *not-found *
903
+
904
+ 5. Otherwise, `EF ` is considered *not-found *.
905
+
906
+
867
907
Create Collection Helper
868
908
^^^^^^^^^^^^^^^^^^^^^^^^
869
909
@@ -891,6 +931,45 @@ If the collection namespace has an associated ``encryptedFields``, then do the f
891
931
- Create the collection ``collectionName `` with ``collectionOptions `` and the option ``encryptedFields `` set to the ``encryptedFields ``.
892
932
- Create the the index ``{"__safeContent__": 1} `` on collection ``collectionName ``.
893
933
934
+
935
+ Create Encrypted Collection Helper
936
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
937
+
938
+ To support automatic generation of encryption data keys, a helper
939
+ `CreateEncryptedCollection(CE, database, collName, collOpts, kmsProvider, dkOpts) `
940
+ is defined, where `CE ` is a ClientEncryption _ object, `kmsProvider ` is a
941
+ KMSProviderName _ and `dkOpts ` is a DataKeyOpts _. It has the following behavior:
942
+
943
+ - Let `dbName ` be the name of `database `. Look up the encrypted fields `EF ` for
944
+ the new collection as `GetEncryptedFields(collOpts, collName, dbName, false) `
945
+ (`See here <GetEncryptedFields _>`_).
946
+ - If `EF ` is *not-found *, report an error that there are no ``encryptedFields ``
947
+ defined for the collection.
948
+ - Let `EF' ` be a copy of `EF `. Update `EF' ` in the following manner:
949
+
950
+ - Let `Fields ` be the ``"fields" `` element within `EF' `.
951
+ - If `Fields ` is present and is an array value, then for each element `F ` of
952
+ `Fields `:
953
+
954
+ - If `F ` is not a document element, skip it.
955
+ - Otherwise, if `F ` has a ``"keyId" `` named element `K ` and `K ` is a
956
+ ``null `` value:
957
+
958
+ - Let `D ` be the result of ``CE.createDataKey(kmsProvider, dkOpts) ``.
959
+ - If generating `D ` resulted in an error `E `, the entire
960
+ `CreateEncryptedCollection ` must now fail with error `E `. Return the
961
+ partially-formed `EF' ` with the error so that the caller may know what
962
+ datakeys have already been created by the helper.
963
+ - Replace `K ` in `F ` with `D `.
964
+
965
+ - Create a new set of options `collOpts' ` duplicating `collOpts `. Set the
966
+ ``"encryptedFields" `` named element of `collOpts' ` to `EF' `.
967
+
968
+ - Invoke the ``CreateCollection `` helper as
969
+ `CreateCollection(database, collName, collOpts') `. Return the resulting
970
+ collection and the generated `EF' `.
971
+
972
+
894
973
Drop Collection Helper
895
974
^^^^^^^^^^^^^^^^^^^^^^
896
975
@@ -915,6 +994,8 @@ If the collection namespace has an associated ``encryptedFields``, then do the f
915
994
If ``encryptedFields["ecocCollection"] `` is not set, use the collection name ``enxcol_.<collectionName>.ecoc ``.
916
995
- Drop the collection ``collectionName ``.
917
996
997
+ .. default-role :: literal
998
+ .. _ClientEncryption :
918
999
919
1000
ClientEncryption
920
1001
----------------
@@ -924,6 +1005,12 @@ ClientEncryption
924
1005
class ClientEncryption {
925
1006
ClientEncryption(opts : ClientEncryptionOpts );
926
1007
1008
+ // The "Create Encrypted Collection" helper is a convenience function wrapping CreateCollection. It will
1009
+ // create a collection with encrypted fields, automatically allocating and assigning new data encryption
1010
+ // keys. It returns a handle to the new collection, as well as a document consisting of the generated
1011
+ // "encryptedFields" options. Refer to "Create Encrypted Collection Helper"
1012
+ createEncryptedCollection(database : Database , collName : string , collOpts , kmsProvider : KMSProviderName , dkOpts : DataKeyOpts ): [Collection , Document ];
1013
+
927
1014
// Creates a new key document and inserts into the key vault collection.
928
1015
// Returns the _id of the created document as a UUID (BSON binary subtype 0x04).
929
1016
createDataKey(kmsProvider : KMSProviderName , opts : DataKeyOpts | null ): Binary ;
@@ -2515,6 +2602,9 @@ explicit session parameter as described in the
2515
2602
Changelog
2516
2603
======== =
2517
2604
2605
+ :2022 - 11 - 10 : Defined a `` CreateEncryptedCollection`` helper for creating new
2606
+ encryption keys automatically for the queryable encrypted fields in
2607
+ a new collection.
2518
2608
:2022 - 11 - 07 : Reformat changelog.
2519
2609
:2022 - 11 - 04 : Permit global cache for Azure credentials.
2520
2610
:2022 - 10 - 26 : Do not connect to `` mongocryptd`` if shared library is loaded.
0 commit comments