-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathKeyVault.rewrapManyDataKey.txt
196 lines (133 loc) · 5.11 KB
/
KeyVault.rewrapManyDataKey.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
.. _server-keyvault-rewrap-manydatakey-method:
============================
KeyVault.rewrapManyDataKey()
============================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
.. method:: KeyVault.rewrapManyDataKey(filter, options)
Decrypts multiple {+dek-long+}s ({+dek-abbr-no-hover+})
and re-encrypts them with a new {+cmk-long+} ({+cmk-abbr-no-hover+}).
Use this method to rotate the {+cmk-abbr-no-hover+} that encrypts your
{+dek-abbr-no-hover+}s. To learn more about {+cmk-abbr-no-hover+}s
and {+dek-abbr-no-hover+}s, see :ref:`<qe-reference-keys-key-vaults>`.
You specify a {+cmk-abbr-no-hover+} through the ``masterKey`` parameter.
If you do not include a ``masterKey`` argument, the method decrypts
and encrypts each {+dek-abbr-no-hover+} with the {+cmk-abbr-no-hover+}
referenced in that {+dek-abbr-no-hover+}'s metadata. To learn more about
the metadata of {+dek-abbr-no-hover+}s, see
:ref:`<csfle-reference-decryption-metadata>`.
:returns:
A :ref:`BulkWriteResult <server-bulkwriteresult-method>` object
that reports how many data keys were affected.
.. warning:: Back-Up Your {+key-vault-long+}
Before you rotate your {+dek-long+}s, ensure you create
a backup of your {+key-vault-long+}. If you lose access to your
{+dek-long+}s, you will lose all your encrypted data.
To learn how to create a backup of a collection,
see :ref:`<manual-tutorial-backup-and-restore>`.
Compatibility
-------------
This command is available in deployments hosted in the following
environments:
.. include:: /includes/fact-environments-atlas-only.rst
.. include:: /includes/fact-environments-onprem-only.rst
Syntax
------
``KeyVault.rewrapManyDataKey`` has the following syntax:
.. code-block:: javascript
let keyVault = db.getMongo().getKeyVault()
keyVault.rewrapManyDataKey(
<filter>,
<options>
)
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Parameter
- Type
- Description
* - ``filter``
- :ref:`query filter document <document-query-filter>`
- The query filter for the keyvault collection
* - ``options``
- document
-
This document has two fields:
- ``provider``: A :ref:`KMS provider
<qe-fundamentals-kms-providers>` (AWS KMS, Azure Key Vault,
GCP KMS, the local provider, or KMIP)
- ``masterKey``: A KMS-specific key used to encrypt the new
data key
.. include:: /includes/in-use-encryption/admonition-csfle-key-rotation.txt
Behavior
--------
This operation is not atomic and should not be run in parallel with
other key management operations.
Requires Configuring Client-Side Field Level Encryption on Database Connection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. include:: /includes/extracts/csfle-requires-enabling-encryption.rst
Example
-------
These examples allow you to rapidly evaluate client-side field level
encryption. For specific examples using each supported
:abbr:`KMS (Key Management Service)` provider, see
:ref:`field-level-encryption-data-key-manage`.
.. include:: /includes/csfle-connection-boilerplate-example.rst
Retrieve the :method:`KeyVault <getKeyVault()>` object and use the
:method:`KeyVault.rewrapManyDataKey` method to rewrap the existing
keys in a new ``masterKey``. If no new ``masterKey`` is given, each
data key retains its respective current ``masterKey``.
Rewrap Data Keys with the Current masterKey
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following example shows how you can rewrap each data key with its
respective current ``masterKey``:
.. code-block:: javascript
let keyVault = mongo.getKeyVault()
keyVault.rewrapManyDataKey()
Rewrap Data Keys with a New masterKey
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following example shows how you can rewrap each data key with a new ``masterKey``:
.. code-block:: javascript
let keyVault = mongo.getKeyVault()
keyVault.rewrapManyDataKey({}, {
provider: 'aws',
masterKey: {
region: 'us-east-2',
key: 'arn:aws:kms:us-east-2:...'
}
})
Rewrap Data Keys That Have Not Been Rewrapped Recently
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following example shows how to rewrap data keys that have not
been rewrapped in the previous thirty days.
.. code-block:: javascript
let keyVault = mongo.getKeyVault()
const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
keyVault.rewrapManyDataKey({ updateDate: { $lt: thirtyDaysAgo } });
Output
~~~~~~
:method:`KeyVault.rewrapManyDataKey()` returns a ``BulkWriteResult``
object detailing how many data keys were affected:
.. code-block:: json
:copyable: false
{
bulkWriteResult: BulkWriteResult {
result: {
ok: 1,
writeErrors: [],
writeConcernErrors: [],
insertedIds: [],
nInserted: 0,
nUpserted: 0,
nMatched: 3,
nModified: 3,
nRemoved: 0,
upserted: [],
opTime: { ts: Timestamp({ t: 1655840760, i: 3 }), t: 23 }
}
}
}