

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 静态加密：如何使用客户自主管理型密钥加密 Amazon Keyspaces 中的表
<a name="encryption.customermanaged"></a>

您可以使用控制台或 CQL 语句 AWS KMS key 为新表指定，并更新 Amazon Keyspaces 中现有表的加密密钥。以下主题概述如何对新表和现有表实施客户自主管理型密钥。

**Topics**
+ [先决条件：使用 Amazon Keyspaces 创建客户托管密钥 AWS KMS 并向其授予权限](#encryption.createCMKMS)
+ [步骤 3：为新表指定客户自主管理型密钥](#encryption.tutorial-creating)
+ [步骤 4：更新现有表的加密密钥](#encryption.tutorial-update)
+ [步骤 5：在日志中使用 Amazon Keyspaces 加密上下文](#encryption-context)
+ [步骤 6：使用配置监控 AWS CloudTrail](#encryption-cmk-trail)

## 先决条件：使用 Amazon Keyspaces 创建客户托管密钥 AWS KMS 并向其授予权限
<a name="encryption.createCMKMS"></a>

在使用[客户托管](encryption.howitworks.md#customer-managed)密钥保护 Amazon Keyspaces 表之前，必须先在 AWS Key Management Service (AWS KMS) 中创建密钥，然后授权 Amazon Keyspaces 使用该密钥。

### 步骤 1：使用创建客户托管密钥 AWS KMS
<a name="encryption-create-key"></a>

要创建用于保护 Amazon Keyspaces 表的客户托管密钥，您可以按照使用控制台或 API [创建对称加密 KMS 密钥](https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html#create-symmetric-cmk)中的步骤进行操作。 AWS 

### 步骤 2：授权使用您的客户自主管理型密钥
<a name="encryption-authz"></a>

要选择一个[客户自主管理型密钥](encryption.howitworks.md#customer-managed)来保护 Amazon Keyspaces 表，必须先让针对该密钥的策略为 Amazon Keyspaces 授予代表您使用该密钥的权限。您可以全面控制针对客户自主管理型密钥的策略和授权。您可以在[密钥策略](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html)、[IAM 策略](https://docs.aws.amazon.com/kms/latest/developerguide/iam-policies.html)或[授权](https://docs.aws.amazon.com/kms/latest/developerguide/grants.html)中提供这些权限。

Amazon Keyspaces 无需额外授权即可使用默认的 [AWS 拥有的密钥](encryption.howitworks.md#keyspaces-owned)来保护 AWS 账户中的 Amazon Keyspaces 表。

以下主题介绍如何使用允许 Amazon Keyspaces 表使用客户自主管理型密钥的 IAM 策略和授权来配置所需的权限。

**Topics**
+ [针对客户自主管理型密钥的密钥策略](#encryption-customer-managed-policy)
+ [示例 密钥策略](#encryption-customer-managed-policy-sample)
+ [使用授权来授权 Amazon Keyspaces](#encryption-grants)

#### 针对客户自主管理型密钥的密钥策略
<a name="encryption-customer-managed-policy"></a>

如果选择[客户自主管理型密钥](encryption.howitworks.md#customer-managed)来保护 Amazon Keyspaces 表，那么 Amazon Keyspaces 将获得代表做出此选择的主体使用客户自主管理型密钥的权限。该主体（用户或角色）必须拥有 Amazon Keyspaces 所需的客户自主管理型密钥权限。

Amazon Keyspaces 至少需要以下客户自主管理型密钥权限：
+ [kms:Encrypt](https://docs.aws.amazon.com/kms/latest/APIReference/API_Encrypt.html)
+ [kms:Decrypt](https://docs.aws.amazon.com/kms/latest/APIReference/API_Decrypt.html)
+ [kms: ReEncrypt](https://docs.aws.amazon.com/kms/latest/APIReference/API_ReEncrypt.html) \$1（代表 kms:ReEncryptFrom 和 kms:ReEncryptTo）
+ kms: GenerateDataKey \$1（对于 [kms: GenerateDataKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKey.html) 和 [kms: GenerateDataKeyWithoutPlaintext](https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKeyWithoutPlaintext.html)）
+ [kms: DescribeKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_DescribeKey.html)
+ [kms: CreateGrant](https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateGrant.html)

#### 示例 密钥策略
<a name="encryption-customer-managed-policy-sample"></a>

例如，以下示例密钥策略仅提供所需的权限。该策略具有以下效果：
+ 允许 Amazon Keyspaces 在加密操作中使用客户自主管理型密钥并创建授权，但仅当它代表账户中拥有 Amazon Keyspaces 使用权限的主体行事时才可如此。如果策略语句中指定的主体无权使用 Amazon Keyspaces，调用将失败，即使调用来自 Amazon Keyspaces 服务也是如此。
+ 只有当请求来自 Amazon [Keyspaces 代表政策声明中列出的委托人时，kms: ViaService](https://docs.aws.amazon.com/kms/latest/developerguide/policy-conditions.html#conditions-kms-via-service) 条件密钥才允许权限。这些主体不能直接调用这些操作。请注意，`kms:ViaService` 值 `cassandra.*.amazonaws.com`在“区域”位置中有一个星号 (\$1)。Amazon Keyspaces 要求该权限独立于任何特定的权限。 AWS 区域
+ 为客户自主管理型密钥管理员（可代入 `db-team` 角色的用户）授予对客户自主管理型密钥的只读访问权限，以及撤销授权的权限，包括 [Amazon Keyspaces 保护表所需的授权](#encryption-grants)。
+ 为 Amazon Keyspaces 授予对客户自主管理型密钥的只读访问权限。在此情况下，Amazon Keyspaces 可以直接调用这些操作，而不必代表账户主体行事。

在使用示例密钥策略之前，请将示例委托人替换为您的实际委托人。 AWS 账户

```
{
  "Id": "key-policy-cassandra",
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid" : "Allow access through Amazon Keyspaces for all principals in the account that are authorized to use Amazon Keyspaces",
      "Effect": "Allow",
      "Principal": {"AWS": "arn:aws:iam::111122223333:user/db-lead"},
      "Action": [
        "kms:Encrypt",
        "kms:Decrypt",
        "kms:ReEncrypt*",
        "kms:GenerateDataKey*",
        "kms:DescribeKey",
        "kms:CreateGrant"
      ],
      "Resource": "*",      
      "Condition": { 
         "StringLike": {
           "kms:ViaService" : "cassandra.*.amazonaws.com"
         }
      }
    },
    {
      "Sid":  "Allow administrators to view the customer managed key and revoke grants",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111122223333:role/db-team"
       },
      "Action": [
        "kms:Describe*",
        "kms:Get*",
        "kms:List*",
        "kms:RevokeGrant"
      ],
      "Resource": "*"
    }
  ]
}
```

#### 使用授权来授权 Amazon Keyspaces
<a name="encryption-grants"></a>

除密钥策略之外，Amazon Keyspaces 还使用授权来设置对客户自主管理型密钥的权限。要查看有关您账户中的客户托管密钥的授权，请使用 [ListGrants](https://docs.aws.amazon.com/kms/latest/APIReference/API_ListGrants.html) 操作。Amazon Keyspaces 不需要授权或任何其他权限即可使用 [AWS 拥有的密钥](encryption.howitworks.md#keyspaces-owned)来保护您的表。

Amazon Keyspaces 在执行后台系统维护和持续数据保护任务时使用授予权限。它还使用授权来生成表密钥。

每个授权特定于一个表。如果该账户包含使用同一客户自主管理型密钥加密的多个表，则每个表都有每种类型的授权。该授权受到 [Amazon Keyspaces 加密上下文](https://docs.aws.amazon.com/kms/latest/developerguide/encryption-context.html)的限制，其中包括表名和 ID。 AWS 账户 该授权包含在不再需要授权时[停用授权](https://docs.aws.amazon.com/kms/latest/APIReference/API_RetireGrant.html)的权限。

要创建授权，Amazon Keyspaces 必须拥有代表创建加密表的用户调用 `CreateGrant` 的权限。

该密钥策略还可以允许账户[撤销对客户自主管理型密钥的授权](https://docs.aws.amazon.com/kms/latest/APIReference/API_RevokeGrant.html)。但是，如果您撤销对某个活动的加密表的授权，Amazon Keyspaces 将无法保护和维护该表。

## 步骤 3：为新表指定客户自主管理型密钥
<a name="encryption.tutorial-creating"></a>

按照以下步骤，使用 Amazon Keyspaces 控制台或 CQL 指定新表的客户自主管理型密钥。

### 使用客户自主管理型密钥创建加密表（控制台）
<a name="encryption.tutorial-console"></a>

1. [登录并在家中打开 Amazon Keyspaces 控制台。 AWS 管理控制台 https://console.aws.amazon.com/keyspaces/](https://console.aws.amazon.com/keyspaces/home)

1. 在导航窗格中，选择**表**，然后选择**创建表**。

1. 在**创建表**页面的**表详细信息**部分中，选择一个键空间并为新表提供一个名称。

1. 在**架构**部分，为您的表创建架构。

1. 在**表设置**部分，选择**自定义设置**。

1. 继续进入**加密设置**。

   在此步骤中，您将为表选择加密设置。

   在 **“选择一个**” 下的 “**静态加密**” 部分 AWS KMS key，选择 **“选择其他 KMS 密钥（高级）**” 选项，然后在搜索字段中选择 AWS KMS key 或输入 Amazon 资源名称 (ARN)。
**注意**  
如果您选择的密钥无法访问或缺少所需的权限，请参阅 AWS Key Management Service 开发人员指南中的[密钥访问疑难解答](https://docs.aws.amazon.com/kms/latest/developerguide/policy-evaluation.html)。

1. 选择 **Create (创建)** 以创建加密表。

### 创建使用客户自主管理型密钥进行静态加密 (CQL) 的新表
<a name="encryption.tutorial-cql"></a>

要创建使用客户自主管理型密钥进行静态加密 (CQL) 的新表，可以使用 `CREATE TABLE` 语句，如以下示例所示。确保将密钥 ARN 替换为一个有效密钥的 ARN，该有效密钥拥有授予 Amazon Keyspaces 的权限。

```
CREATE TABLE my_keyspace.my_table(id bigint, name text, place text STATIC, PRIMARY KEY(id, name)) WITH CUSTOM_PROPERTIES = {
        'encryption_specification':{
                'encryption_type': 'CUSTOMER_MANAGED_KMS_KEY', 
                'kms_key_identifier':'arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111'
            }
    };
```

如果您收到 `Invalid Request Exception`，则需要确认客户自主管理型密钥有效，并且 Amazon Keyspaces 拥有所需的权限。要确认密钥配置是否正确，请参阅《 AWS Key Management Service 开发人员指南》中的[密钥访问疑难解答](https://docs.aws.amazon.com/kms/latest/developerguide/policy-evaluation.html)。

## 步骤 4：更新现有表的加密密钥
<a name="encryption.tutorial-update"></a>

您也可以随时使用 Amazon Keyspaces 控制台或 CQL 在客户托管的 KMS 密钥 AWS 拥有的密钥 和客户托管的 KMS 密钥之间更改现有表的加密密钥。

### 使用新的客户自主管理型密钥更新现有表（控制台）
<a name="encryption.tutorial-update-console"></a>

1. [登录并在家中打开 Amazon Keyspaces 控制台。 AWS 管理控制台 https://console.aws.amazon.com/keyspaces/](https://console.aws.amazon.com/keyspaces/home)

1.  在导航窗格中，选择**表**。

1. 选择要更新的表，然后选择**其他设置**选项卡。

1. 在**静态加密**部分中，选择**管理加密**以编辑表的加密设置。

   在 **“选择一个**” 下 AWS KMS key，选择 **“选择其他 KMS 密钥（高级）**” 选项，然后在搜索字段中选择 AWS KMS key 或输入 Amazon 资源名称 (ARN)。
**注意**  
如果您选择的密钥无效，请参阅 AWS Key Management Service 开发人员指南中的[密钥访问疑难解答](https://docs.aws.amazon.com/kms/latest/developerguide/policy-evaluation.html)。

   或者，您可以 AWS 拥有的密钥 为使用客户托管密钥加密的表选择一个。

1. 选择**保存更改**以保存对表所做的更改。

### 更新用于现有表的加密密钥
<a name="encryption.tutorial-update-cql"></a>

要更改现有表的加密密钥，请使用 `ALTER TABLE` 语句指定用于静态加密的客户自主管理型密钥。确保将密钥 ARN 替换为一个有效密钥的 ARN，该有效密钥拥有授予 Amazon Keyspaces 的权限。

```
ALTER TABLE my_keyspace.my_table WITH CUSTOM_PROPERTIES = {     
              'encryption_specification':{ 
                      'encryption_type': 'CUSTOMER_MANAGED_KMS_KEY', 
                      'kms_key_identifier':'arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111'     
                  } 
         };
```

如果您收到 `Invalid Request Exception`，则需要确认客户自主管理型密钥有效，并且 Amazon Keyspaces 拥有所需的权限。要确认密钥配置是否正确，请参阅《 AWS Key Management Service 开发人员指南》中的[密钥访问疑难解答](https://docs.aws.amazon.com/kms/latest/developerguide/policy-evaluation.html)。

要将加密密钥更改回默认的静态加密选项 AWS 拥有的密钥，您可以使用如下示例所示的`ALTER TABLE`语句。

```
ALTER TABLE my_keyspace.my_table WITH CUSTOM_PROPERTIES = {
                'encryption_specification':{
                      'encryption_type' : 'AWS_OWNED_KMS_KEY' 
                    } 
         };
```

## 步骤 5：在日志中使用 Amazon Keyspaces 加密上下文
<a name="encryption-context"></a>

[加密上下文](https://docs.aws.amazon.com/kms/latest/developerguide/encrypt_context.html) 是一组包含任意非机密数据的键值对。当您在加密数据的请求中包含加密上下文时，会以加密 AWS KMS 方式将加密上下文绑定到加密数据。要解密数据，您必须传入相同的加密上下文。

Amazon Keys AWS KMS paces 在所有加密操作中使用相同的加密上下文。如果您使用[客户自主管理型密钥](encryption.howitworks.md#customer-managed)来保护 Amazon Keyspaces 表，则可以使用加密上下文在审计记录和日志中标识客户自主管理型密钥的使用。它还以纯文本形式出现在日志中，例如和 [AWS CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html)A [ma CloudWatch ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) zon Logs 的日志中。

在请求中 AWS KMS，Amazon Keyspaces 使用了包含三个密钥值对的加密上下文。

```
"encryptionContextSubset": {
    "aws:cassandra:keyspaceName": "my_keyspace",
    "aws:cassandra:tableName": "mytable"
    "aws:cassandra:subscriberId": "111122223333"
}
```
+ **键空间**：第一个键值对标识包含 Amazon Keyspaces 要加密的表的键空间。键是 `aws:cassandra:keyspaceName`。值是键空间的名称。

  ```
  "aws:cassandra:keyspaceName": "<keyspace-name>"
  ```

  例如：

  ```
  "aws:cassandra:keyspaceName": "my_keyspace"
  ```
+ **表**：第二个键值对标识 Amazon Keyspaces 要加密的表。键是 `aws:cassandra:tableName`。值为表的名称。

  ```
  "aws:cassandra:tableName": "<table-name>"
  ```

  例如：

  ```
  "aws:cassandra:tableName": "my_table"
  ```
+ **账户**：第三个键值对标识 AWS 账户。键是 `aws:cassandra:subscriberId`。该值为账户 ID。

  ```
  "aws:cassandra:subscriberId": "<account-id>"
  ```

  例如：

  ```
  "aws:cassandra:subscriberId": "111122223333"
  ```

## 步骤 6：使用配置监控 AWS CloudTrail
<a name="encryption-cmk-trail"></a>

如果您使用[客户托管密钥](encryption.howitworks.md#customer-managed)来保护您的 Amazon Keyspaces 表，则可以使用 AWS CloudTrail 日志来跟踪 Amazon Keyspaces 代表您发送 AWS KMS 的请求。

本节将讨论 `GenerateDataKey`、`DescribeKey`、`Decrypt` 和 `CreateGrant` 请求。此外，当您删除表时，Amazon Keyspaces 会使用[RetireGrant](https://docs.aws.amazon.com/kms/latest/APIReference/API_RetireGrant.html)操作来移除授权。

**注意**  
当您使用 Amazon Keyspaces 时，某些操作可能会生成`invokedBy`字段为 CloudTrail 的事件。`dynamodb.amazonaws.com`这是意料之中的，而且之所以发生，是因为亚马逊密钥空间与亚马逊 DynamoDB 集成以提供其服务。

**GenerateDataKey**  
Amazon Keyspaces 会创建一个唯一表密钥来加密静态数据。它向发送*[GenerateDataKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKey.html)*请求 AWS KMS ，为该表指定 KMS 密钥。  
记录 `GenerateDataKey` 操作的事件与以下示例事件类似。用户是 Amazon Keyspaces 服务账户。参数包括客户自主管理型密钥的 Amazon 资源名称 (ARN)、需要 256 位密钥的密钥说明符以及标识键空间、表和 AWS 账户的[加密上下文](#encryption-context)。  

```
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "AWSService",
        "invokedBy": "AWS Internal"
    },
    "eventTime": "2021-04-16T04:56:05Z",
    "eventSource": "kms.amazonaws.com",
    "eventName": "GenerateDataKey",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "AWS Internal",
    "userAgent": "AWS Internal",
    "requestParameters": {
        "keySpec": "AES_256",
        "encryptionContext": {
            "aws:cassandra:keyspaceName": "my_keyspace",
            "aws:cassandra:tableName": "my_table",
            "aws:cassandra:subscriberId": "123SAMPLE012"
        },
        "keyId": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111"
    },
    "responseElements": null,
    "requestID": "5e8e9cb5-9194-4334-aacc-9dd7d50fe246",
    "eventID": "49fccab9-2448-4b97-a89d-7d5c39318d6f",
    "readOnly": true,
    "resources": [
        {
            "accountId": "123SAMPLE012",
            "type": "AWS::KMS::Key",
            "ARN": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111"
        }
    ],
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "123SAMPLE012",
    "sharedEventID": "84fbaaf0-9641-4e32-9147-57d2cb08792e"
}
```

**DescribeKey**  
Amazon Keyspaces 使用[DescribeKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_DescribeKey.html)操作来确定您选择的 KMS 密钥是否存在于账户和区域中。  
记录 `DescribeKey` 操作的事件与以下示例事件类似。用户是 Amazon Keyspaces 服务账户。参数包括客户自主管理型密钥的 ARN 和需要 256 位密钥的密钥说明符。  

```
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "IAMUser",
        "principalId": "AIDAZ3FNIIVIZZ6H7CFQG",
        "arn": "arn:aws:iam::123SAMPLE012:user/admin",
        "accountId": "123SAMPLE012",
        "accessKeyId": "AKIAIOSFODNN7EXAMPLE",
        "userName": "admin",
        "sessionContext": {
            "sessionIssuer": {},
            "webIdFederationData": {},
            "attributes": {
                "mfaAuthenticated": "false",
                "creationDate": "2021-04-16T04:55:42Z"
            }
        },
        "invokedBy": "AWS Internal"
    },
    "eventTime": "2021-04-16T04:55:58Z",
    "eventSource": "kms.amazonaws.com",
    "eventName": "DescribeKey",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "AWS Internal",
    "userAgent": "AWS Internal",
    "requestParameters": {
        "keyId": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111"
    },
    "responseElements": null,
    "requestID": "c25a8105-050b-4f52-8358-6e872fb03a6c",
    "eventID": "0d96420e-707e-41b9-9118-56585a669658",
    "readOnly": true,
    "resources": [
        {
            "accountId": "123SAMPLE012",
            "type": "AWS::KMS::Key",
            "ARN": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111"
        }
    ],
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "123SAMPLE012"
}
```

**Decrypt**  
当您访问 Amazon Keyspaces 表时，Amazon Keyspaces 需要解密表密钥，以便解密层次结构中位于其下方的密钥。然后，解密表中的数据。为了解密表密钥，Amazon Keyspaces 会向其发送[解密](https://docs.aws.amazon.com/kms/latest/APIReference/API_Decrypt.html)请求 AWS KMS ，该请求指定表的 KMS 密钥。  
记录 `Decrypt` 操作的事件与以下示例事件类似。用户是您中访问该表的委托 AWS 账户 人。这些参数包括加密的表密钥（作为密文 blob）和用于标识表的[加密上下文](#encryption-context)和。 AWS 账户 AWS KMS 从密文中获取客户托管密钥的 ID。  

```
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "AWSService",
        "invokedBy": "AWS Internal"
    },
    "eventTime": "2021-04-16T05:29:44Z",
    "eventSource": "kms.amazonaws.com",
    "eventName": "Decrypt",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "AWS Internal",
    "userAgent": "AWS Internal",
    "requestParameters": {
        "encryptionContext": {
            "aws:cassandra:keyspaceName": "my_keyspace",
            "aws:cassandra:tableName": "my_table",
            "aws:cassandra:subscriberId": "123SAMPLE012"
        },
        "encryptionAlgorithm": "SYMMETRIC_DEFAULT"
    },
    "responseElements": null,
    "requestID": "50e80373-83c9-4034-8226-5439e1c9b259",
    "eventID": "8db9788f-04a5-4ae2-90c9-15c79c411b6b",
    "readOnly": true,
    "resources": [
        {
            "accountId": "123SAMPLE012",
            "type": "AWS::KMS::Key",
            "ARN": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111"
        }
    ],
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "123SAMPLE012",
    "sharedEventID": "7ed99e2d-910a-4708-a4e3-0180d8dbb68e"
}
```

**CreateGrant**  
如果您使用[客户自主管理型密钥](encryption.howitworks.md#customer-managed)来保护 Amazon Keyspaces 表，则 Amazon Keyspaces 会使用[授权](#encryption-grants)以允许服务执行持续数据保护和维护以及持久性任务。[AWS 拥有的密钥](encryption.howitworks.md#keyspaces-owned)不需要这些授权。  
Amazon Keyspaces 创建的授权特定于表。CreateGrant 请求[CreateGrant](https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateGrant.html)的委托人是创建了表的用户。  
记录 `CreateGrant` 操作的事件与以下示例事件类似。参数包括表的客户自主管理型密钥的 ARN、被授权主体和停用主体（Amazon Keyspaces 服务）以及授权涵盖的操作。它还包括要求所有加密操作都使用指定[加密上下文](#encryption-context)的约束。  

```
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "IAMUser",
        "principalId": "AIDAZ3FNIIVIZZ6H7CFQG",
        "arn": "arn:aws:iam::arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111:user/admin",
        "accountId": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111",
        "accessKeyId": "AKIAI44QH8DHBEXAMPLE",
        "userName": "admin",
        "sessionContext": {
            "sessionIssuer": {},
            "webIdFederationData": {},
            "attributes": {
                "mfaAuthenticated": "false",
                "creationDate": "2021-04-16T04:55:42Z"
            }
        },
        "invokedBy": "AWS Internal"
    },
    "eventTime": "2021-04-16T05:11:10Z",
    "eventSource": "kms.amazonaws.com",
    "eventName": "CreateGrant",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "AWS Internal",
    "userAgent": "AWS Internal",
    "requestParameters": {
        "keyId": "a7d328af-215e-4661-9a69-88c858909f20",
        "operations": [
            "DescribeKey",
            "GenerateDataKey",
            "Decrypt",
            "Encrypt",
            "ReEncryptFrom",
            "ReEncryptTo",
            "RetireGrant"
        ],
        "constraints": {
            "encryptionContextSubset": {
                "aws:cassandra:keyspaceName": "my_keyspace",
                "aws:cassandra:tableName": "my_table",
                "aws:cassandra:subscriberId": "123SAMPLE012"
            }
        },
        "retiringPrincipal": "cassandratest.us-east-1.amazonaws.com",
        "granteePrincipal": "cassandratest.us-east-1.amazonaws.com"
    },
    "responseElements": {
        "grantId": "18e4235f1b07f289762a31a1886cb5efd225f069280d4f76cd83b9b9b5501013"
    },
    "requestID": "b379a767-1f9b-48c3-b731-fb23e865e7f7",
    "eventID": "29ee1fd4-28f2-416f-a419-551910d20291",
    "readOnly": false,
    "resources": [
        {
            "accountId": "123SAMPLE012",
            "type": "AWS::KMS::Key",
            "ARN": "arn:aws:kms:eu-west-1:5555555555555:key/11111111-1111-111-1111-111111111111"
        }
    ],
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "eventCategory": "Management",
    "recipientAccountId": "123SAMPLE012"
}
```