KeyVault.rewrapManyDataKey()
KeyVault.rewrapManyDataKey(filter, options)
Decrypts multiple Data Encryption Keys (DEK) and re-encrypts them with a new Customer Master Key (CMK). Use this method to rotate the CMK that encrypts your DEKs. To learn more about CMKs and DEKs, see 暗号化のキーとキー ボールト.
You specify a CMK through the
masterKey
parameter. If you do not include amasterKey
argument, the method decrypts and encrypts each DEK with the CMK referenced in that DEK's metadata. To learn more about the metadata of DEKs, see 復号に使用されるメタデータ.次の値を返します。 A BulkWriteResult object that reports how many data keys were affected.
警告
Back-Up Your Key Vault collection
Before you rotate your Data Encryption Keys, ensure you create a backup of your Key Vault collection. If you lose access to your Data Encryption Keys, you will lose all your encrypted data.
To learn how to create a backup of a collection, see MongoDB ツールを使用した自己管理型配置のバックアップと復元.
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
KeyVault.rewrapManyDataKey
の構文は次のとおりです。
let keyVault = db.getMongo().getKeyVault() keyVault.rewrapManyDataKey( <filter>, <options> )
Parameter | タイプ | 説明 |
---|---|---|
| The query filter for the keyvault collection | |
| ドキュメント | This document has two fields:
|
動作
This operation is not atomic and should not be run in parallel with other key management operations.
データベース接続にクライアント側のフィールドレベル暗号化を構成する必要があります
mongosh
クライアント側のフィールド レベル暗号化メソッドでは、クライアント側のフィールド レベル暗号化が有効になっているデータベース接続が必要です。現在のデータベース接続がクライアント側のフィールド レベル暗号化を有効にして開始されなかった場合、次のいずれかが発生します。
Mongo()
必要なクライアント側のフィールドレベル暗号化オプションとの接続を確立するには、mongosh
から コンストラクターを使用します。Mongo()
メソッドは、CMK(Customer Master Key)管理のために次のKMS ( KMS )プロバイダーをサポートしています。or
必要なオプションとの接続を確立するには、
mongosh
コマンドライン オプションを使用します。 コマンドライン オプションは、CMK 管理用のAmazon Web Services KMSプロバイダーのみをサポートしています。
例
These examples allow you to rapidly evaluate client-side field level encryption. For specific examples using each supported KMS provider, see 暗号化キー管理.
暗号化されたクライアントの作成
データベース接続を作成するには、クライアント側のフィールドレベル暗号化オプションが構成されたMongo()
コンストラクターを使用します。 mongodb://myMongo.example.net
URI を、ターゲットクラスターの接続string URIに置き換えます。
encryptedClient = Mongo( "mongodb://myMongo.example.net:27017/?replSetName=myMongo", autoEncryptionOpts )
Retrieve the KeyVault
object and use the
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
:
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
:
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.
let keyVault = mongo.getKeyVault() const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000); keyVault.rewrapManyDataKey({ updateDate: { $lt: thirtyDaysAgo } });
出力
KeyVault.rewrapManyDataKey()
returns a BulkWriteResult
object detailing how many data keys were affected:
{ 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 } } } }