

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

# Amazon Keyspaces 中的基础设施安全性
<a name="infrastructure-security"></a>

作为一项托管服务，Amazon Keyspaces（适用于 Apache Cassandra）受全球网络安全的保护。 AWS 有关 AWS 安全服务以及如何 AWS 保护基础设施的信息，请参阅[AWS 云安全](https://aws.amazon.com/security/)。要使用基础设施安全的最佳实践来设计您的 AWS 环境，请参阅 S * AWS ecurity Pillar Well-Architected Fram* ework 中的[基础设施保护](https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/infrastructure-protection.html)。

您可以使用 AWS 已发布的 API 调用通过网络访问 Amazon Keyspaces。客户端必须支持以下内容：
+ 传输层安全性协议（TLS）。我们要求使用 TLS 1.2，建议使用 TLS 1.3。
+ 具有完全向前保密（PFS）的密码套件，例如 DHE（临时 Diffie-Hellman）或 ECDHE（临时椭圆曲线 Diffie-Hellman）。大多数现代系统（如 Java 7 及更高版本）都支持这些模式。

Amazon Keyspaces 支持两种对客户端请求进行身份验证的方法。第一种方法使用特定于服务的凭证，这种凭证是为特定 IAM 用户生成的基于密码的凭证。您可以使用 IAM 控制台 AWS CLI、或 AWS API 创建和管理密码。有关更多信息，请参阅[将 IAM 与 Amazon Keyspaces 结合使用](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_mcs.html)。

第二种方法使用适用于 Cassandra 的开源 DataStax Java 驱动程序的身份验证插件。这一插件让 [IAM 用户、角色和联合身份](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html)能够使用[AWS 签名版本 4 流程 (Sigv4)](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html) 向 Amazon Keyspaces（Apache Cassandra 兼容）API 请求添加身份验证信息。有关更多信息，请参阅 [为 Amazon Keyspaces 创建和配置 AWS 证书](access.credentials.md)。

您可以从任何网络位置调用这些 API 操作，但是 Amazon Keyspaces 确实支持基于资源的访问策略，其中可能包括基于源 IP 地址的限制。您还可以使用 Amazon Keyspaces 策略来控制来自特定亚马逊虚拟私有云（亚马逊 VPC）终端节点或特定终端节点的访问。 VPCs实际上，这可以将对给定 Amazon Keyspaces 资源的网络访问与网络中的 AWS 特定 VPC 隔离开来。

您可以使用接口 VPC 端点来防止 Amazon VPC 和 Amazon Keyspaces 之间的流量离开 Amazon 网络。接口 VPC 终端节点由一项 AWS 技术提供支持 AWS PrivateLink，该技术允许使用弹性网络接口在 AWS 服务之间进行私密通信，并使用您的 Amazon VPC IPs 中的私有接口。有关更多信息，请参阅 [将 Amazon Keyspaces 与接口 VPC 端点结合使用](vpc-endpoints.md)。

# 将 Amazon Keyspaces 与接口 VPC 端点结合使用
<a name="vpc-endpoints"></a>

接口 VPC 端点可以在 Amazon VPC 中运行的虚拟私有云 (VPC) 与 Amazon Keyspaces 之间实现私有通信。接口 VPC 终端节点由提供支持 AWS PrivateLink，这是一项支持 VPCs 和 AWS 服务之间私有通信的 AWS 服务。

AWS PrivateLink 通过在您的 VPC 中使用带有私有 IP 地址的 elastic network interface 来实现这一点，这样网络流量就不会离开亚马逊网络。接口 VPC 端点不需要互联网网关、NAT 设备、VPN 连接或 Direct Connect 连接。有关更多信息，请参阅 [Amazon Virtual Private Cloud](https://docs.aws.amazon.com/vpc/latest/userguide/) 和 [接口 VPC 端点 (AWS PrivateLink)](https://docs.aws.amazon.com/vpc/latest/privatelink/vpce-interface.html)。

**Topics**
+ [将接口 VPC 端点用于 Amazon Keyspaces](#using-interface-vpc-endpoints)
+ [使用接口 VPC 端点信息填充 `system.peers` 表条目](#system_peers)
+ [控制 Amazon Keyspaces 对接口 VPC 端点的访问](#interface-vpc-endpoints-policies)
+ [可用性](#availability)
+ [VPC 终端节点策略和 Amazon Keyspaces point-in-time 恢复 (PITR)](#VPC_PITR_restore)
+ [常见错误和警告](#vpc_troubleshooting)

## 将接口 VPC 端点用于 Amazon Keyspaces
<a name="using-interface-vpc-endpoints"></a>

您可以创建接口 VPC 端点，这样 Amazon Keyspaces 和 Amazon VPC 资源之间的流量就会通过接口 VPC 端点开始流动。要开始使用，请按照步骤[创建接口端点](https://docs.aws.amazon.com/vpc/latest/privatelink/vpce-interface.html#create-interface-endpoint)。接下来，编辑与您在上一步中创建的终端节点关联的安全组，并为端口 9142 配置入站规则。有关详细信息，请参阅[添加、删除和更新规则](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html#AddRemoveRules)。

有关通过 VPC 终端节点配置与 Amazon Keyspaces 的连接的 step-by-step教程，请参阅。[教程：使用接口 VPC 终端节点连接到 Amazon Keyspaces](vpc-endpoints-tutorial.md)要了解如何为与 VPC 中 AWS 账户 不同应用程序分开的 Amazon Keyspaces 资源配置跨账户访问权限，请参阅。[使用 VPC 端点配置对 Amazon Keyspaces 的跨账户访问](access.cross-account.md)

## 使用接口 VPC 端点信息填充 `system.peers` 表条目
<a name="system_peers"></a>

Apache Cassandra 驱动程序使用该 `system.peers` 表来查询有关集群的节点信息。Cassandra 驱动程序使用节点信息对连接进行负载均衡并重试操作。Amazon Keyspaces 会自动为通过公共端点连接的客户端填充 `system.peers` 表中的九个条目。

为了向通过接口 VPC 端点连接的客户端提供类似的功能，Amazon Keyspaces 会在您账户的 `system.peers` 表格中填充一个条目，用于显示 VPC 端点可用的每个可用区。要在 `system.peers` 表中查找和存储可用的接口 VPC 端点，Amazon Keyspaces 要求您向用于连接到 Amazon Keyspaces 的 IAM 实体授予访问权限，以查询您的 VPC 的端点和网络接口信息。

**重要**  
在`system.peers`表格中填充您的可用接口 VPC 终端节点可以改善负载平衡并增加 read/write 吞吐量。建议使用接口 VPC 端点访问 Amazon Keyspaces 的所有客户端都这样做，Apache Spark 也需要这样做。

要向用于连接 Amazon Keyspaces 的 IAM 实体授予权限以查找必要的接口 VPC 端点信息，可以更新现有的 IAM 角色或用户策略，或创建新的 IAM 策略，如以下示例所示。

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement":[
      {
         "Sid":"ListVPCEndpoints",
         "Effect":"Allow",
         "Action":[
            "ec2:DescribeNetworkInterfaces",
            "ec2:DescribeVpcEndpoints"
         ],
         "Resource":"*"
      }
   ]
}
```

**注意**  
托管式策略 `AmazonKeyspacesReadOnlyAccess_v2` 和 `AmazonKeyspacesFullAccess` 包含允许 Amazon Keyspaces 访问 Amazon EC2 实例以读取可用接口 VPC 端点信息所需的权限。

要确认策略设置是否正确，请查询 `system.peers` 表以查看网络信息。如果该 `system.peers` 表为空，则可能表示策略未成功配置，或者您已超出 `DescribeNetworkInterfaces` 和 `DescribeVPCEndpoints` API 操作的请求速率限额。`DescribeVPCEndpoints` 属于 `Describe*` 类别，被视为*非变异操作*。`DescribeNetworkInterfaces` 属于*未过滤和未分页的非变异操作*的子集，并且适用不同的限额。有关更多信息，请参阅 Amazon EC2 API 参考中的[请求令牌桶大小和重新填充率](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/throttling.html#throttling-limits-rate-based)。

如果您看到一张空表，请在几分钟后重试，以排除请求速率限额问题。要验证您是否正确配置了 VPC 端点，请参阅[我的 VPC 端点连接无法正常工作](troubleshooting.connecting.md#troubleshooting.connection.vpce)。如果您的查询返回表中的结果，说明您的策略配置正确。



## 控制 Amazon Keyspaces 对接口 VPC 端点的访问
<a name="interface-vpc-endpoints-policies"></a>

VPC 端点策略使您能够通过两种方式控制对资源的访问：
+ **IAM 策略** – 您可以控制允许通过特定 VPC 端点访问 Amazon Keyspaces 的请求、用户或组。您可以通过在附加到 IAM 用户、组或角色的策略中使用[条件键](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)来完成此操作。
+ **VPC 策略** – 您可以通过向 VPC 端点附加策略来控制哪些端点可以访问您的 Amazon Keyspaces 资源。要限制仅允许通过特定 VPC 终端节点的流量来访问特定键空间或表，请编辑限制资源访问的现有 IAM 策略并添加该 VPC 终端节点。



下面是访问 Amazon Keyspaces 资源的端点策略示例。
+ **IAM 策略示例：限制对特定 Amazon Keyspaces 表的所有访问，除非流量来自指定的 VPC 端点** – 此示例策略可以附加到 IAM 用户、角色或组。它限制对指定 Amazon Keyspaces 表的访问，除非传入流量来自指定的 VPC 端点。

  ```
  {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
        {
           "Sid": "UserOrRolePolicyToDenyAccess",
           "Action": "cassandra:*",
           "Effect": "Deny",
           "Resource": [
                          "arn:aws:cassandra:us-east-1:111122223333:/keyspace/mykeyspace/table/mytable",
                          "arn:aws:cassandra:us-east-1:111122223333:/keyspace/system*"
             ],
           "Condition": { "StringNotEquals" : { "aws:sourceVpce": "vpce-abc123" } }
        }
     ]
  }
  ```
**注意**  
要限制对特定表的访问，还必须包括对系统表的访问权限。系统表为只读。
+ **VPC 策略示例：只读访问** – 此示例策略可以附加到 VPC 端点。（有关更多信息，请参阅[控制对 Amazon VPC 资源的访问](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-endpoints-access.html#vpc-endpoint-policies)）。它限制通过所连接的 VPC 端点对 Amazon Keyspaces 资源进行只读访问的操作。

  ```
  {
    "Version": "2012-10-17",		 	 	 
    "Statement": [
      {
        "Sid": "ReadOnly",
        "Principal": "*",
        "Action": [
          "cassandra:Select"
        ],
        "Effect": "Allow",
        "Resource": "*"
      }
    ]
  }
  ```
+ **VPC 策略示例：限制对特定 Amazon Keyspaces 表的访问** – 此示例策略可以附加到 VPC 端点。它限制通过所附加到的 VPC 端点访问特定表。

  ```
  {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
          {
              "Sid": "RestrictAccessToTable",
              "Principal": "*",
              "Action": "cassandra:*",
              "Effect": "Allow",
              "Resource": [
                          "arn:aws:cassandra:us-east-1:111122223333:/keyspace/mykeyspace/table/mytable",
                          "arn:aws:cassandra:us-east-1:111122223333:/keyspace/system*"
             ]
          }
     ]
  }
  ```
**注意**  
要限制对特定表的访问，还必须包括对系统表的访问权限。系统表为只读。

## 可用性
<a name="availability"></a>

Amazon Keyspaces 支持在所有提供服务 AWS 区域 的地方使用接口 VPC 终端节点。有关更多信息，请参阅 [Amazon Keyspaces 的服务端点](programmatic.endpoints.md)。

## VPC 终端节点策略和 Amazon Keyspaces point-in-time 恢复 (PITR)
<a name="VPC_PITR_restore"></a>

如果您使用带有[条件键](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)的 IAM 策略来限制传入流量，则表恢复操作可能会失败。例如，如果您使用 `aws:SourceVpce` 条件键将源流量限制到特定 VPC 端点，则表恢复操作将失败。要允许 Amazon Keyspaces 代表您的主体执行恢复操作，您必须在 IAM 策略中添加 `aws:ViaAWSService` 条件键。当任何 AWS 服务使用委托人的证书发出请求时，`aws:ViaAWSService`条件密钥允许访问。有关更多信息，请参阅《IAM 用户指南》中的 [IAM JSON 策略元素：条件键](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)**。下面是一个示例策略。

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement":[
      {
         "Sid":"CassandraAccessForVPCE",
         "Effect":"Allow",
         "Action":"cassandra:*",
         "Resource":"*",
         "Condition":{
            "Bool":{
               "aws:ViaAWSService":"false"
            },
            "StringEquals":{
               "aws:SourceVpce":[
                  "vpce-12345678901234567"
               ]
            }
         }
      },
      {
         "Sid":"CassandraAccessForAwsService",
         "Effect":"Allow",
         "Action":"cassandra:*",
         "Resource":"*",
         "Condition":{
            "Bool":{
               "aws:ViaAWSService":"true"
            }
         }
      }
   ]
}
```

## 常见错误和警告
<a name="vpc_troubleshooting"></a>

**如果您使用的是 Amazon Virtual Private Cloud 并连接到 Amazon Keyspaces，可能会看到以下警告。**

```
Control node cassandra.us-east-1.amazonaws.com/1.111.111.111:9142 has an entry for itself in system.peers: this entry will be ignored. This is likely due to a misconfiguration; 
please verify your rpc_address configuration in cassandra.yaml on all nodes in your cluster.
```

之所以出现此警告，是因为 `system.peers` 表包含 Amazon Keyspaces 有权查看的所有 Amazon VPC 端点的条目，包括您通过其连接的 Amazon VPC 端点。您可以放心地忽略这一警告。

有关其他错误，请参阅[我的 VPC 端点连接无法正常工作](troubleshooting.connecting.md#troubleshooting.connection.vpce)。

# 将 Amazon Keyspaces CDC 流与接口 VPC 终端节点一起使用
<a name="vpc-endpoints-streams"></a>

接口 VPC 端点可以在 Amazon VPC 中运行的虚拟私有云 (VPC) 与 Amazon Keyspaces 之间实现私有通信。接口 VPC 终端节点由提供支持 AWS PrivateLink，这是一项支持 VPCs 和 AWS 服务之间私有通信的 AWS 服务。

AWS PrivateLink 通过在您的 VPC 中使用带有私有 IP 地址的 elastic network interface 来实现这一点，这样网络流量就不会离开亚马逊网络。接口 VPC 端点不需要互联网网关、NAT 设备、VPN 连接或 Direct Connect 连接。有关更多信息，请参阅 [Amazon Virtual Private Cloud](https://docs.aws.amazon.com/vpc/latest/userguide/) 和 [接口 VPC 端点 (AWS PrivateLink)](https://docs.aws.amazon.com/vpc/latest/privatelink/vpce-interface.html)。

**Topics**
+ [为 Amazon Keyspaces CDC 直播使用接口 VPC 终端节点](#using-interface-vpc-endpoints-streams)
+ [Amazon Keyspaces CDC 直播接口 VPC 终端节点](#interface-vpc-endpoints-streams-types)
+ [创建 Amazon Keyspaces CDC 流接口 VPC 终端节点](#create-interface-vpc-endpoints-streams)
+ [更新 Amazon Keyspaces CDC 流接口 VPC 终端节点](#update-interface-vpc-endpoints-streams)
+ [使用 Amazon Keyspaces CDC 流接口 VPC 终端节点列出流](#list-interface-vpc-endpoints-streams)
+ [为 Amazon Keyspaces CDC 流接口 VPC 终端节点创建策略](#interface-vpc-endpoints-streams-policy)

## 为 Amazon Keyspaces CDC 直播使用接口 VPC 终端节点
<a name="using-interface-vpc-endpoints-streams"></a>

您可以使用接口 VPC 终端节点，以便 Amazon Keyspaces CDC 流和您的 Amazon VPC 资源之间的流量开始流经接口 VPC 终端节点。您可以使用 VPC 终端节点策略来限制对您的 CDC 直播的访问。

有关 Amazon Keyspaces CDC 直播的更多信息，请参阅。[在 Amazon Keyspaces 中处理变更数据捕获 (CDC) 流](cdc.md)

## Amazon Keyspaces CDC 直播接口 VPC 终端节点
<a name="interface-vpc-endpoints-streams-types"></a>

**当您创建接口终端节点时，Amazon Keyspaces CDC 流会为该流生成两种类型的终端节点特定的 DNS 名称：区域和区域。**

**区域性**  
区域 DNS 名称包含以下信息：  
+ 唯一的亚马逊 VPC 终端节点 ID
+ 服务标识符
+ 的 AWS 区域
+ 后`vpce.amazonaws.com`缀
对于带有 ID 的 Amazon VPC 终端节点`vpce-1a2b3c4d`，生成的 DNS 名称可能与以下示例类似：`vpce-1a2b3c4d-5e6f.cassandra-streams.us-east-1.vpce.amazonaws.com`。

**可用区**  
区域 DNS 名称除了[区域 DNS 名称中的信息外，还包括可用区](https://aws.amazon.com/about-aws/global-infrastructure/regions_az/)。为带有 ID 的 Amazon VPC 终端节点生成`vpce-1a2b3c4d`的 DNS 名称如下例所示，请注意， AWS 区域 现在包含可用区：`vpce-1a2b3c4d-5e6f-us-east-1a.cassandra-streams.us-east-1.vpce.amazonaws.com`  
如果您的架构隔离了可用区，则可以使用此选项。例如，您可以将其用于故障控制或降低区域数据传输成本。  
为了实现最佳可靠性，我们建议将您的服务部署在至少三个可用区中。

## 创建 Amazon Keyspaces CDC 流接口 VPC 终端节点
<a name="create-interface-vpc-endpoints-streams"></a>

您可以使用 AWS CLI 或软件开发工具包通过 Amazon AWS Keyspaces CDC Streams 接口终端节点访问 Amazon Keyspaces CDC Streams API 操作。有关所有可用 API 操作的完整列表，请参阅 [https://docs.aws.amazon.com/keyspaces/latest/StreamsAPIReference/Welcome.html](https://docs.aws.amazon.com/keyspaces/latest/StreamsAPIReference/Welcome.html) 参考。

有关如何创建 VPC 终端节点的更多信息，请参阅 Amazon VPC 用户指南中的[创建接口终端节点](https://docs.aws.amazon.com/vpc/latest/privatelink/vpce-interface.html#create-interface-endpoint)。

要创建 VPC 终端节点，您可以使用以下示例中的语法。

```
aws ec2 create-vpc-endpoint \
  --region us-east-1 \
  --service-name api.aws.us-east-1.cassandra-streams \
  --vpc-id client-vpc-id \
  --subnet-ids client-subnet-id \
  --vpc-endpoint-type Interface \
  --security-group-ids client-sg-id
```

## 更新 Amazon Keyspaces CDC 流接口 VPC 终端节点
<a name="update-interface-vpc-endpoints-streams"></a>

要更新 VPC 终端节点，您可以使用以下示例中的语法。

```
aws ec2 modify-vpc-endpoint \
  --region us-east-1 \
  --vpc-endpoint-id client-vpc-id \
  --policy-document policy-document \ #example optional parameter
  --add-security-group-ids security-group-ids \ #example optional parameter
```

## 使用 Amazon Keyspaces CDC 流接口 VPC 终端节点列出流
<a name="list-interface-vpc-endpoints-streams"></a>

要列出使用 VPC 终端节点的流，您可以使用以下示例中的语法。请务必使用您自己的信息替换 VPC 终端节点 ID 的地区和 DNS 名称。

```
aws keyspacesstreams \
  --endpoint https://vpce-1a2b3c4d-5e6f.cassandra-streams.us-east-1.vpce.amazonaws.com \
  --region us-east-1 \
  list-streams
```

## 为 Amazon Keyspaces CDC 流接口 VPC 终端节点创建策略
<a name="interface-vpc-endpoints-streams-policy"></a>

您可以将终端节点策略附加到控制对 Amazon Keyspaces CDC 流的访问权限的 Amazon VPC 终端节点。该策略指定以下信息：
+ 可以执行操作的 AWS Identity and Access Management (IAM) 委托人
+ 可执行的操作
+ 可对其执行操作的资源

要将访问特定 Amazon Keyspaces CDC 流限制为仅允许访问您的 Amazon VPC 中的特定 AWS 服务，您可以使用以下示例。

以下直播策略授予任何 IAM 委托人的访问权限，`cassandra:GetRecords`以执行操作`cassandra:GetStream`以及`2025-02-20T11:22:33.444`关联到账户`/keyspace/mykeyspace/table/mytable/`资源的指定流`123456788901`。要使用此终端节点策略，请务必将区域、账户 ID 和资源替换为直播标签。

```
{
"Version": "2012-10-17",		 	 	 
  "Id": "Policy1216114807515",
  "Statement": [
    { "Sid": "Access-to-specific-stream-only",
      "Principal": "*",
      "Action": [
        "cassandra:GetStream",
        "cassandra:GetRecords"
      ],
      "Effect": "Allow",
      "Resource": ["arn:aws:cassandra:us-east-1:111122223333:/keyspace/mykeyspace/table/mytable/stream/2025-02-20T11:22:33.444"]
    }
  ]
}
```

**注意**  
Amazon Keyspaces 不支持 CDC 直播的网关终端节点。