Encryption Key Management加密键管理
On this page本页内容
Encryption Components加密组件Supported Key Management Services支持的键管理服务Reasons to Use a Remote Key Management System使用远程键管理系统的原因Manage a Data Encryption Key's Alternate Name管理数据加密键的备用名称Create a Data Encryption Key with an Alternate Name创建具有备用名称的数据加密键Use Key Alternate Names in an Automatic Encryption Schema在自动加密架构中使用键备用名称Procedure: Rotate Encryption Keys Using Mongo Shell步骤:使用Mongo Shell旋转加密键Delete a Data Encryption Key删除数据加密键Learn More了解更多信息
In this guide, you can learn how to manage your encryption keys with a Key Management System (KMS) in your Client-Side Field Level Encryption (CSFLE)-enabled application.在本指南中,您可以了解如何在启用客户端字段级加密(CSFLE)的应用程序中使用键管理系统(KMS)管理加密键。
Encryption Components加密组件
MongoDB uses the following components to perform Client-Side Field Level Encryption:MongoDB使用以下组件执行客户端字段级加密:
- Data Encryption Keys (DEK)s
- Customer Master Keys (CMK)s
- Key Vault collections
- Key Management System (KMS)
To learn more about keys and key vaults, see Keys and Key Vaults.若要了解有关钥匙和钥匙库的详细信息,请参阅键和键库。
Supported Key Management Services支持的键管理服务
Client-Side Field Level Encryption supports the following Key Management System providers:客户端字段级加密支持以下键管理系统提供程序:
- Amazon Web Services KMS
- Azure Key Vault
- Google Cloud KMS
- Any KMIP Compliant Key Management System
- Local Key Provider (for testing only)
The default KMIP protocol version is 1.2. You can configure MongoDB to use KMIP version 1.0 or 1.1 in the MongoDB server configuration file.默认的KMIP协议版本是1.2。您可以在MongoDB服务器配置文件中将MongoDB配置为使用KMIP 1.0或1.1版本。
To learn more about these providers, including diagrams that show how your application uses them to perform Client-Side Field Level Encryption, see CSFLE KMS Providers.要了解有关这些提供程序的更多信息,包括显示应用程序如何使用它们执行客户端字段级加密的图表,请参阅CSFLE KMS提供程序。
Reasons to Use a Remote Key Management System使用远程键管理系统的原因
Using a remote Key Management System to manage your Customer Master Key has the following advantages over using your local filesystem to host the CMK:与使用本地文件系统托管CMK相比,使用远程键管理系统管理客户主键具有以下优势:
Secure storage of the key with access auditing通过访问审核实现键的安全存储Reduced risk of access permission issues降低了访问权限问题的风险Availability and distribution of the key to remote clients键的可用性和向远程客户端的分发Automated key backup and recovery自动化的键备份和恢复Centralized encryption key lifecycle management集中的加密键生命周期管理
Additionally, for the following KMS providers, your KMS remotely encrypts and decrypts your Data Encryption Key, ensuring your Customer Master Key is never exposed to your CSFLE-enabled application:此外,对于以下KMS提供商,您的KMS远程加密和解密您的数据加密键,确保您的客户主键永远不会暴露在启用CSFLE的应用程序中:
- Amazon Web Services KMS
- Azure Key Vault
- Google Cloud KMS
Manage a Data Encryption Key's Alternate Name管理数据加密键的备用名称
You can assign a Data Encryption Key alternate names to make the key easier to reference. 您可以为数据加密键分配备用名称,以使键更易于引用。Assigning alternate names allows you to perform the following actions:指定备用名称可以执行以下操作:
Reference a DEK by different means than the通过与_id
field._id
字段不同的方式引用DEK。Dynamically assign DEKs at runtime.在运行时动态分配DEK。
Create a Data Encryption Key with an Alternate Name创建具有备用名称的数据加密键
Prerequisite先决条件
Prior to adding a new key alternate name, you must create a partial unique index on the 在添加新的键备用名称之前,必须在keyAltNames
field. keyAltNames
字段上创建部分唯一索引。This index should have a 对于存在partialFilterExpression
for documents where keyAltNames
exists.keyAltNames
的文档,此索引应具有partialFilterExpression
。
Client-Side Field Level Encryption depends on server-enforced uniqueness of key alternate names.客户端字段级加密取决于服务器强制的键备用名称的唯一性。
To learn how to create a partial index, refer to Partial Indexes.要了解如何创建部分索引,请参阅部分索引。
The following example creates a Data Encryption Key with an alternate name. Select the tab that corresponds to your driver language:以下示例创建了一个具有备用名称的数据加密键。选择与您的驱动程序语言相对应的选项卡:
const encryption = new ClientEncryption(client, {
keyVaultNamespace,
kmsProviders,
});
const masterKey = {
"<Your dataKeyOpts Key>": "<Your dataKeyOpts Value>",
};
const key = await encryption.createDataKey(provider, {
masterKey: masterKey,
keyAltNames: ["<Your Key Alt Name>"],
});
To learn more about 要了解有关dataKeyOpts
and kmsProviders
objects, see CSFLE KMS Providers.dataKeyOpts
和kmsProviders
对象的更多信息,请参阅CSFLE KMS提供程序。
Use Key Alternate Names in an Automatic Encryption Schema在自动加密架构中使用键备用名称
Encryption schemas contain user-specified rules that identify which fields must be encrypted and how to encrypt those fields. In your encryption rules, you can specify alternate key names name for the Data Encryption Key which encrypts your field.加密模式包含用户指定的规则,这些规则标识哪些字段必须加密以及如何加密这些字段。在加密规则中,您可以为加密字段的数据加密键指定备用键名称。
You must refer to a key alternate name with a JSON pointer. A JSON pointer is a string prefixed with a 您必须使用JSON指针引用键备用名称。JSON指针是一个以"/"
character that can be used to access a particular field value in the same or another document. Use JSON pointers to reference a field in your query or update document which contains the value of your key alternate name."/"
字符为前缀的字符串,可用于访问同一文档或另一文档中的特定字段值。使用JSON指针引用查询或更新文档中包含键备用名称值的字段。
Cannot Use Alternate Name for Deterministically Encrypted Field不能为确定性加密字段使用备用名称
You cannot reference a DEK by it's alternate name when encrypting a field with the deterministic encryption algorithm. 使用确定性加密算法加密字段时,不能使用DEK的备用名称引用它。To encrypt your field deterministically, you must specify the 要确定地加密字段,必须指定要用于加密字段的键的_id
of the key you would like to use to encrypt your field._id
。
Reference Key Alternate Name in an Encryption Schema加密架构中的参考键备用名称
Consider the following encryption schema which encrypts the 考虑以下加密salary
field:salary
(薪资)字段的加密模式:
{
"<database>.<collection>": {
"bsonType": "object",
"properties": {
"salary": {
"encrypt": {
"bsonType": "int",
"keyId": "/fieldWithAltName",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
}
}
}
}
}
The schema's 架构的keyId
field contains a JSON pointer to reference the fieldWithAltName
field within the documents being encrypted.keyId
字段包含一个JSON游标,用于引用正在加密的文档中的fieldWithAltName
字段。
The following document's 以下文档的fieldWithAltName
value is my-alt-name
:fieldWithAltName
值是my-alt-name
:
{
"name": "Jon Doe",
"salary": 45000,
"fieldWithAltName": "my-alt-name"
}
The salary
field is encrypted by the DEK that has the alternate name my-alt-name
.salary
字段由DEK加密,DEK的别名为my-alt-name
。
Dynamically Assign Keys at Runtime在运行时动态分配键
You can use alternate key names to dynamically set the Data Encryption Key for a field at runtime. Use this functionality to encrypt individual documents with different DEKs using the same encryption schema.您可以使用备用键名称在运行时动态设置字段的数据加密键。使用此功能可以使用相同的加密架构使用不同的DEK对单个文档进行加密。
For example, consider the following documents:例如,请考虑以下文档:
{
"name": "Jon Doe",
"salary": 45000,
"fieldWithAltName": "my-alt-name"
},
{
"name": "Jane Smith",
"salary": 70000,
"fieldWithAltName": "my-other-alt-name"
}
You insert the preceding documents using a CSFLE-enabled client configured with the encryption schema from the previous example.您可以使用启用了CSFLE的客户端插入前面的文档,该客户端使用前面示例中的加密模式进行配置。
In the encryption schema, the 在加密模式中,salary.encrypt.keyId
field contains a JSON pointer to the fieldWithAltName
field of the inserted document. salary.encrypt.keyId
字段包含指向插入文档的fieldWithAltName
字段的JSON游标。As a result, the 因此,两个示例文档中的salary
fields in the two example documents are each encrypted using a DEK specific to the individual document. The keys are assigned dynamically at runtime.salary
字段都使用特定于单个文档的DEK进行加密。键是在运行时动态分配的。
Procedure: Rotate Encryption Keys Using Mongo Shell步骤:使用Mongo Shell旋转加密键
With version 1.5 and later of the Mongo Shell, you can rotate encryption keys using the 使用1.5版及更高版本的MongoShell,可以使用rewrapManyDataKey
method. rewriteManyDataKey
方法旋转加密键。The rewrapManyDataKey
method automatically decrypts multiple data keys and re-encrypts them using a specified Customer Master Key. It then updates the rotated keys in the key vault collection. rewriteManyDataKey
方法会自动解密多个数据键,并使用指定的客户主键对其进行重新加密。然后,它会更新键库集合中旋转的键。This method allows you to rotate encryption keys based on two optional arguments:此方法允许您基于两个可选参数旋转加密键:
A filter used to specify which keys to rotate. If no data key matches the given filter, no keys are rotated. Omit the filter to rotate all keys in your key vault collection.用于指定要旋转的关键点的筛选器。如果没有与给定筛选器匹配的数据键,则不会旋转任何键。省略筛选器以旋转键保管库集合中的所有键。An object that represents a new CMK. Omit this object to rotate the data keys using their current CMKs.表示新CMK的对象。省略此对象可使用数据键的当前CMK旋转数据键。
The rewrapManyDataKey
uses the following syntax:rewriteManyDataKey
使用以下语法:
keyVault = db.getKeyVault()
keyVault.rewrapManyDataKey(
{
"<Your custom filter>"
},
{
provider: "<KMS provider>",
masterKey: {
"<dataKeyOpts Key>" : "<dataKeyOpts Value>"
}
}
)
To learn more about the 要了解有关KMS提供程序的dataKeyOpts
object for your KMS provider, see Supported Key Management Services.dataKeyOpts
对象的更多信息,请参阅支持的键管理服务。
Delete a Data Encryption Key删除数据加密键
You can delete a Data Encryption Key from your Key Vault collection using standard CRUD delete operations. If you delete a DEK, all fields encrypted with that DEK become permanently unreadable.您可以使用标准CRUD删除操作从键保管库集合中删除数据加密键。如果删除一个DEK,则使用该DEK加密的所有字段都将永久不可读。
MongoDB Shell Specific FeatureMongoDB Shell特定功能
The MongoDB shell allows you to delete a DEK by MongoDB shell允许您使用UUID
using the keyVault.deleteKey()
method as follows:keyVaultdeleteKey()
方法通过UUID
删除DEK
,如下所示:
keyVault = db.getKeyVault()
keyVault.deleteKey(UUID("<UUID String>"))
To learn more about Key Vault collections see Key Vault Collections.要了解有关键库集合的详细信息,请参阅键库集合。
Learn More了解更多信息
For tutorials detailing how to set up a CSFLE-enabled application with each of the supported KMS providers, see the following pages:有关详细说明如何使用每个受支持的KMS提供程序设置启用CSFLE的应用程序的教程,请参阅以下页面:
Use Automatic Client-Side Field Level Encryption with AWS使用AWS自动客户端字段级加密Use Automatic Client-Side Field Level Encryption with Azure使用Azure的自动客户端字段级加密Use Automatic Client-Side Field Level Encryption with GCP在GCP中使用自动客户端字段级加密Use Automatic Client-Side Field Level Encryption with KMIP使用KMIP的自动客户端字段级加密
To view additional examples of encryption schemas, see 要查看加密模式的其他示例,请参阅CSFLE Encryption Schemas.CSFLE加密架构。