Skip to content

Commit f0563d0

Browse files
authored
DOCSP-23031 adds rewrapManyDataKey (#1253)
* DOCSP-23031 adds rewrapManyDataKey * returns * internal review feedback * review and updates * review and updates * rework; * internal review feedback * external review feedback * spacing example * pre-publish feedback; removes trailing comma from example
1 parent 541cf8a commit f0563d0

File tree

3 files changed

+169
-3
lines changed

3 files changed

+169
-3
lines changed

source/reference/method.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,11 @@ Client-Side Field Level Encryption
13921392

13931393
* - :method:`KeyVault.getKeyByAltName()`
13941394

1395-
- Retrieves a key with the specified key alternative name.
1395+
- Retrieves keys with the specified key alternative name.
1396+
1397+
* - :method:`KeyVault.rewrapManyDataKey()`
1398+
1399+
- Decrypts multiple data keys and re-encrypts them.
13961400

13971401
* - :method:`getClientEncryption()`
13981402

@@ -1405,8 +1409,7 @@ Client-Side Field Level Encryption
14051409
* - :method:`ClientEncryption.decrypt()`
14061410

14071411
- Decrypts a field using the associated data encryption key and encryption algorithm.
1408-
1409-
1412+
14101413
.. toctree::
14111414
:titlesonly:
14121415
:hidden:

source/reference/method/BulkWriteResult.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _server-bulkwriteresult-method:
2+
13
=================
24
BulkWriteResult()
35
=================
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
.. _server-keyvault-rewrap-manydatakey-method:
2+
3+
============================
4+
KeyVault.rewrapManyDataKey()
5+
============================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
.. method:: KeyVault.rewrapManyDataKey(filter, options)
16+
17+
``KeyVault.rewrapManyDataKey`` decrypts multiple data
18+
keys and re-encrypts them with a new ``masterKey``. If a new
19+
``masterKey`` is not given, the current ``masterKey`` is used.
20+
21+
``KeyVault.rewrapManyDataKey`` has the following syntax:
22+
23+
.. code-block:: javascript
24+
25+
let keyVault = db.getMongo().getKeyVault()
26+
27+
keyVault.rewrapManyDataKey(
28+
<filter>,
29+
<options>
30+
)
31+
32+
.. list-table::
33+
:header-rows: 1
34+
:widths: 20 20 80
35+
36+
* - Parameter
37+
38+
- Type
39+
40+
- Description
41+
42+
* - ``filter``
43+
44+
- :ref:`query filter document <document-query-filter>`
45+
46+
- The query filter for the keyvault collection.
47+
48+
* - ``options``
49+
50+
- document
51+
52+
-
53+
This document has two fields:
54+
55+
- ``provider``: A :ref:`KMS provider
56+
<qe-fundamentals-kms-providers>` (AWS KMS, Azure Key Vault,
57+
GCP KMS, the local provider, or KMIP)
58+
- ``masterKey``: A KMS-specific key used to encrypt the new
59+
data key.
60+
61+
:returns:
62+
63+
A :ref:`BulkWriteResult <server-bulkwriteresult-method>` object
64+
that reports how many data keys were affected.
65+
66+
Behavior
67+
--------
68+
69+
This operation is not atomic and should not be run in parallel with
70+
other key management operations.
71+
72+
Requires Configuring Client-Side Field Level Encryption on Database Connection
73+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74+
75+
.. include:: /includes/extracts/csfle-requires-enabling-encryption.rst
76+
77+
Example
78+
-------
79+
80+
These examples allow you to rapidly evaluate client-side field level
81+
encryption. For specific examples using each supported
82+
:abbr:`KMS (Key Management Service)` provider, see
83+
:ref:`field-level-encryption-data-key-manage`.
84+
85+
.. include:: /includes/extracts/csfle-connection-boilerplate.rst
86+
87+
Retrieve the :method:`KeyVault <getKeyVault()>` object and use the
88+
:method:`KeyVault.rewrapManyDataKey` method to re-wrap the existing
89+
keys in a new ``masterKey``. If no new ``masterKey`` is given, each
90+
data key retains its respective current ``masterKey``.
91+
92+
Re-wrap Data Keys with Current``masterKey``
93+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94+
95+
The following example show how you can re-wrap each data key with its
96+
respective current ``masterKey``:
97+
98+
.. code-block:: javascript
99+
100+
let keyVault = mongo.getKeyVault()
101+
102+
keyVault.rewrapManyDataKey()
103+
104+
Migrate to a New ``masterKey``
105+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106+
107+
The following example shows how you can use
108+
:method:KeyVault.rewrapManyDataKey()` to migrate to a new ``masterKey``:
109+
110+
.. code-block:: javascript
111+
112+
let keyVault = mongo.getKeyVault()
113+
114+
keyVault.rewrapManyDataKey({}, {
115+
provider: 'aws',
116+
masterKey: {
117+
region: 'us-east-2',
118+
key: 'arn:aws:kms:us-east-2:...'
119+
}
120+
})
121+
122+
Re-wrap Data Keys that have not been Re-wrapped Recently
123+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124+
125+
The following example shows how to re-wrap data keys that have not
126+
been re-wrapped in the previous thirty days.
127+
128+
.. code-block:: javascript
129+
130+
let keyVault = mongo.getKeyVault()
131+
132+
const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
133+
134+
keyVault.rewrapManyDataKey({ updateDate: { $lt: thirtyDaysAgo } });
135+
136+
Output
137+
~~~~~~
138+
139+
:method:`KeyVault.rewrapManyDataKey()` returns a ``BulkWriteResult``
140+
object detailing how many data keys were affected:
141+
142+
.. code-block:: json
143+
:copyable: false
144+
145+
{
146+
bulkWriteResult: BulkWriteResult {
147+
result: {
148+
ok: 1,
149+
writeErrors: [],
150+
writeConcernErrors: [],
151+
insertedIds: [],
152+
nInserted: 0,
153+
nUpserted: 0,
154+
nMatched: 3,
155+
nModified: 3,
156+
nRemoved: 0,
157+
upserted: [],
158+
opTime: { ts: Timestamp({ t: 1655840760, i: 3 }), t: 23 }
159+
}
160+
}
161+
}

0 commit comments

Comments
 (0)