

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

# Amazon Keyspaces 如何与 IAM 配合使用
<a name="security_iam_service-with-iam"></a>

在使用 IAM 管理对 Amazon Keyspaces 的访问之前，您应该了解哪些 IAM 功能可用于 Amazon Keyspaces。要全面了解 Amazon Keyspaces 和其他 Amazon 服务如何与 IAM 配合使用，请参阅 IAM *用户指南中与 IAM 配合使用的Amazon *[服务](https://docs.amazonaws.cn/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html)。

**Topics**
+ [Amazon Keyspaces 基于身份的策略](#security_iam_service-with-iam-id-based-policies)
+ [Amazon Keyspaces 基于资源的策略](#security_iam_service-with-iam-resource-based-policies)
+ [基于 Amazon Keyspaces 标签的授权](#security_iam_service-with-iam-tags)
+ [Amazon Keyspaces IAM 角色](#security_iam_service-with-iam-roles)

## Amazon Keyspaces 基于身份的策略
<a name="security_iam_service-with-iam-id-based-policies"></a>

通过使用 IAM 基于身份的策略，您可以指定允许或拒绝的操作和资源以及允许或拒绝操作的条件。Amazon Keyspaces 支持特定的操作、资源和条件键。要了解在 JSON 策略中使用的所有元素，请参阅《IAM 用户指南》中的 [IAM JSON 策略元素参考](https://docs.amazonaws.cn/IAM/latest/UserGuide/reference_policies_elements.html)**。

要查看 Amazon Keyspaces 服务特定的资源和操作以及可用于 IAM 权限策略的条件上下文键，请参阅《服务授权参考》**中的 [Amazon Keyspaces（Apache Cassandra 兼容）的操作、资源和条件键](https://docs.amazonaws.cn/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html)。

### 操作
<a name="security_iam_service-with-iam-id-based-policies-actions"></a>

管理员可以使用 Amazon JSON 策略来指定谁有权访问什么。也就是说，哪个**主体**可以对什么**资源**执行**操作**，以及在什么**条件**下执行。

JSON 策略的 `Action` 元素描述可用于在策略中允许或拒绝访问的操作。在策略中包含操作以授予执行关联操作的权限。

Amazon Keyspaces 中的策略操作在操作前面使用以下前缀：`cassandra:`。例如，要授予某人使用 Amazon Keyspaces `CREATE` CQL 语句创建 Amazon Keyspaces 键空间的权限，您应将 `cassandra:Create` 操作纳入其策略中。策略语句必须包含 `Action` 或 `NotAction` 元素。Amazon Keyspaces 定义了一组自己的操作，以描述您可以使用该服务执行的任务。

要在单个语句中指定多项操作，请使用逗号将它们隔开，如下所示：

```
"Action": [
      "cassandra:CREATE",
      "cassandra:MODIFY"
          ]
```

要查看 Amazon Keyspaces 操作的列表，请参阅《服务授权参考》**中的 [Amazon Keyspaces（Apache Cassandra 兼容）定义的操作](https://docs.amazonaws.cn/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html#amazonkeyspacesforapachecassandra-actions-as-permissions)。

### 资源
<a name="security_iam_service-with-iam-id-based-policies-resources"></a>

管理员可以使用 Amazon JSON 策略来指定谁有权访问什么。也就是说，哪个**主体**可以对什么**资源**执行**操作**，以及在什么**条件**下执行。

`Resource` JSON 策略元素指定要向其应用操作的一个或多个对象。作为最佳实践，请使用其 [Amazon 资源名称（ARN）](https://docs.amazonaws.cn/IAM/latest/UserGuide/reference-arns.html)指定资源。对于不支持资源级权限的操作，请使用通配符 (\$1) 指示语句应用于所有资源。

```
"Resource": "*"
```

在 Amazon Keyspaces 中，密钥空间、表和流可以在 IAM 权限`Resource`元素中使用。

**注意**  
要访问 Amazon Keyspaces 中的用户密钥空间和表，您的 IAM 策略必须`cassandra:Select`包含对系统表的权限：  

```
arn:${Partition}:cassandra:${Region}:${Account}:/keyspace/system*
```
这适用于以下场景：  
Amazon 管理控制台访问权限
SDK 资源操作`GetKeyspace`，例如`GetTable``ListKeyspaces`、和 `ListTables`
标准 Apache Cassandra 客户端驱动程序连接，因为驱动程序会在连接初始化期间自动读取系统表
系统表是只读的，无法修改。

Amazon Keyspaces 键空间资源具有以下 ARN：

```
arn:${Partition}:cassandra:${Region}:${Account}:/keyspace/${keyspaceName}/
```

Amazon Keyspaces 表资源具有以下 ARN：

```
arn:${Partition}:cassandra:${Region}:${Account}:/keyspace/${keyspaceName}/table/${tableName}
```

Amazon Keyspaces 流资源具有以下 ARN：

```
arn:${Partition}:cassandra:{Region}:${Account}:/keyspace/${keyspaceName}/table/${tableName}/stream/${streamLabel}
```

有关格式的更多信息 ARNs，请参阅 [Amazon 资源名称 (ARNs) 和 Amazon 服务命名空间](https://docs.amazonaws.cn/general/latest/gr/aws-arns-and-namespaces.html)。

例如，要在语句中指定 `mykeyspace` 键空间，请使用以下 ARN：

```
"Resource": "arn:aws:cassandra:us-east-1:111122223333:/keyspace/mykeyspace/"
```

要指定属于特定账户的所有键空间，请使用通配符 (\$1)：

```
"Resource": "arn:aws:cassandra:us-east-1:111122223333:/keyspace/*"
```

无法对特定资源执行某些 Amazon Keyspaces 操作，例如，用于创建资源的操作。在这些情况下，您必须使用通配符（\$1)。

```
"Resource": "*"
```

 例如，要向 IAM 委托人授予`mytable`在中的`SELECT`权限`mykeyspace`，该委托人必须同时具有读取`mytable`和的权限`keyspace/system*`。要在单个语句中指定多个资源，请 ARNs 用逗号分隔。

```
"Resource": "arn:aws:cassandra:us-east-1:111122223333:/keyspace/mykeyspace/table/mytable",
            "arn:aws:cassandra:us-east-1:111122223333:/keyspace/system*"
```

*要查看 Amazon Keyspaces 资源类型及其列表 ARNs，请参阅《服务授权参考》中的 [Amazon Keyspaces 定义的资源（适用于 Apache Cassandra）](https://docs.amazonaws.cn/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html#amazonkeyspacesforapachecassandra-resources-for-iam-policies)。*要了解您可以在哪些操作中指定每个资源的 ARN，请参阅 [Amazon Keyspaces（Apache Cassandra 兼容）定义的操作](https://docs.amazonaws.cn/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html#amazonkeyspacesforapachecassandra-actions-as-permissions)。

### 条件键
<a name="security_iam_service-with-iam-id-based-policies-conditionkeys"></a>

管理员可以使用 Amazon JSON 策略来指定谁有权访问什么。也就是说，哪个**主体**可以对什么**资源**执行**操作**，以及在什么**条件**下执行。

`Condition` 元素根据定义的条件指定语句何时执行。您可以创建使用[条件运算符](https://docs.amazonaws.cn/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html)（例如，等于或小于）的条件表达式，以使策略中的条件与请求中的值相匹配。要查看所有 Amazon 全局条件键，请参阅 *IAM 用户指南*中的[Amazon 全局条件上下文密钥](https://docs.amazonaws.cn/IAM/latest/UserGuide/reference_policies_condition-keys.html)。

Amazon Keyspaces 定义了自己的一组条件键，还支持使用一些全局条件键。要查看所有 Amazon 全局条件键，请参阅 *IAM 用户指南*中的[Amazon 全局条件上下文密钥](https://docs.amazonaws.cn/IAM/latest/UserGuide/reference_policies_condition-keys.html)。



 所有 Amazon Keyspaces 操作都支持 `aws:RequestTag/${TagKey}`、`aws:ResourceTag/${TagKey}` 和 `aws:TagKeys` 条件键。有关更多信息，请参阅 [基于标签的 Amazon Keyspaces 资源访问](security_iam_id-based-policy-examples.md#security_iam_id-based-policy-examples-tags)。

要查看 Amazon Keyspaces 条件键的列表，请参阅《服务授权参考》**中的 [Amazon Keyspaces（Apache Cassandra 兼容）的条件键](https://docs.amazonaws.cn/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html#amazonkeyspacesforapachecassandra-policy-keys)。要了解您可以对哪些操作和资源使用条件键，请参阅 [Amazon Keyspaces（Apache Cassandra 兼容）定义的操作](https://docs.amazonaws.cn/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html#amazonkeyspacesforapachecassandra-actions-as-permissions)。

### 示例
<a name="security_iam_service-with-iam-id-based-policies-examples"></a>

要查看 Amazon Keyspaces 基于身份的策略的示例，请参阅[Amazon Keyspaces 基于身份的策略示例](security_iam_id-based-policy-examples.md)。

## Amazon Keyspaces 基于资源的策略
<a name="security_iam_service-with-iam-resource-based-policies"></a>

Amazon Keyspaces 不支持基于资源的策略。要查看详细的基于资源的策略页面示例，请参阅 [https://docs.amazonaws.cn/lambda/latest/dg/access-control-resource-based.html](https://docs.amazonaws.cn/lambda/latest/dg/access-control-resource-based.html)。

## 基于 Amazon Keyspaces 标签的授权
<a name="security_iam_service-with-iam-tags"></a>

您可以使用标签管理对 Amazon Keyspaces 资源的访问。要管理基于标签的资源访问，您可以使用 `cassandra:ResourceTag/key-name`、`aws:RequestTag/key-name` 或 `aws:TagKeys` 条件键在策略的[条件元素](https://docs.amazonaws.cn/IAM/latest/UserGuide/reference_policies_elements_condition.html)中提供标签信息。有关标记 Amazon Keyspaces 资源的更多信息，请参阅[对 Amazon Keyspaces 资源使用标签和标注](tagging-keyspaces.md)。

要查看基于身份的策略（用于根据资源上的标签来限制对该资源的访问）的示例，请参阅[基于标签的 Amazon Keyspaces 资源访问](security_iam_id-based-policy-examples.md#security_iam_id-based-policy-examples-tags)。

## Amazon Keyspaces IAM 角色
<a name="security_iam_service-with-iam-roles"></a>

I [AM 角色](https://docs.amazonaws.cn/IAM/latest/UserGuide/id_roles.html)是您内部具有特定权限 Amazon Web Services 账户 的实体。

### 将临时凭证用于 Amazon Keyspaces
<a name="security_iam_service-with-iam-roles-tempcreds"></a>

您可以使用临时凭证进行联合身份登录，来担任 IAM 角色或担任跨账户角色。您可以通过调用[AssumeRole](https://docs.amazonaws.cn/STS/latest/APIReference/API_AssumeRole.html)或之类的 Amazon STS API 操作来获取临时安全证书[GetFederationToken](https://docs.amazonaws.cn/STS/latest/APIReference/API_GetFederationToken.html)。

Amazon Keyspaces 支持使用 Github 存储库中提供的 Amazon 签名版本 4 (Sigv4) 身份验证插件的临时证书，适用于以下语言：
+ Java：[https://github.com/aws/aws-sigv4-auth-cassandra-java-driver-plugin](https://github.com/aws/aws-sigv4-auth-cassandra-java-driver-plugin)。
+ Node.js：[https://github.com/aws/aws-sigv4-auth-cassandra-nodejs-driver-plugin](https://github.com/aws/aws-sigv4-auth-cassandra-nodejs-driver-plugin)。
+ Python: [https://github.com/aws/aws-sigv4-auth-cassandra-python-driver-plugin](https://github.com/aws/aws-sigv4-auth-cassandra-python-driver-plugin)。
+ Go：[https://github.com/aws/aws-sigv4-auth-cassandra-gocql-driver-plugin](https://github.com/aws/aws-sigv4-auth-cassandra-gocql-driver-plugin)。

有关实现身份验证插件以编程方式访问 Amazon Keyspaces 的示例和教程，请参阅[使用 Cassandra 客户端驱动程序以编程方式访问 Amazon Keyspaces](programmatic.drivers.md)。

### 服务关联角色
<a name="security_iam_service-with-iam-roles-service-linked"></a>

[服务相关角色](https://docs.amazonaws.cn/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#iam-term-service-linked-role)允许 Amazon 服务访问其他服务中的资源以代表您完成操作。服务关联角色显示在 IAM 账户中，并归该服务所有。IAM 管理员可以查看但不能编辑服务关联角色的权限。

有关创建或管理 Amazon Keyspaces 服务相关角色的详细信息，请参阅**[对 Amazon Keyspaces 使用服务相关角色](using-service-linked-roles.md)**。

### 服务角色
<a name="security_iam_service-with-iam-roles-service"></a>

Amazon Keyspaces 不支持服务角色。