

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

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

使用 IAM 管理 Amazon Keyspaces 的存取權之前，您應該了解哪些 IAM 功能可與 Amazon Keyspaces 搭配使用。若要全面了解 Amazon Keyspaces 和其他 AWS 服務如何與 IAM 搭配使用，請參閱《[AWS IAM 使用者指南》中的與 IAM 搭配使用的 服務](https://docs.aws.amazon.com/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.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html)。

若要查看 Amazon Keyspaces 服務特定的資源和動作，以及可用於 IAM 許可政策的條件內容金鑰，請參閱*服務授權參考*中的 [Amazon Keyspaces （適用於 Apache Cassandra) 的動作、資源和條件金鑰](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html)。

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

管理員可以使用 AWS 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.aws.amazon.com/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html#amazonkeyspacesforapachecassandra-actions-as-permissions)。

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

管理員可以使用 AWS JSON 政策來指定誰可以存取內容。也就是說，哪個**主體**在什麼**條件**下可以對什麼**資源**執行哪些**動作**。

`Resource` JSON 政策元素可指定要套用動作的物件。最佳實務是使用其 [Amazon Resource Name (ARN)](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html) 來指定資源。若動作不支援資源層級許可，使用萬用字元 (\$1) 表示該陳述式適用於所有資源。

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

在 Amazon Keyspaces 中，金鑰空間、資料表和串流可用於 IAM 許可的 `Resource`元素。

**注意**  
若要存取 Amazon Keyspaces 中的使用者金鑰空間和資料表，您的 IAM 政策必須包含系統資料表的`cassandra:Select`許可：  

```
arn:${Partition}:cassandra:${Region}:${Account}:/keyspace/system*
```
這適用於下列案例：  
AWS 管理主控台存取
SDK 資源操作，例如 `GetKeyspace`、`ListKeyspaces`、 `GetTable`和 `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 Resource Name (ARNs AWS 和服務命名空間](https://docs.aws.amazon.com/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": "*"
```

 例如，若要將`SELECT`許可授予 `mytable`中的 IAM 主體`mykeyspace`，主體必須具有讀取 `mytable`和 的許可`keyspace/system*`。若要在單一陳述式中指定多項資源，請使用逗號分隔 ARN。

```
"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.aws.amazon.com/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html#amazonkeyspacesforapachecassandra-resources-for-iam-policies)。若要了解您可以使用哪些動作指定每個資源的 ARN，請參閱 [Amazon Keyspaces 定義的動作 （適用於 Apache Cassandra)](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html#amazonkeyspacesforapachecassandra-actions-as-permissions)。

### 條件索引鍵
<a name="security_iam_service-with-iam-id-based-policies-conditionkeys"></a>

管理員可以使用 AWS JSON 政策來指定誰可以存取內容。也就是說，哪個**主體**在什麼**條件**下可以對什麼**資源**執行哪些**動作**。

`Condition` 元素會根據定義的條件，指定陳述式的執行時機。您可以建立使用[條件運算子](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html)的條件運算式 (例如等於或小於)，來比對政策中的條件和請求中的值。若要查看所有 AWS 全域條件索引鍵，請參閱《*IAM 使用者指南*》中的[AWS 全域條件內容索引鍵](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)。

Amazon Keyspaces 會定義自己的一組條件金鑰，也支援使用一些全域條件金鑰。若要查看所有 AWS 全域條件索引鍵，請參閱《*IAM 使用者指南*》中的[AWS 全域條件內容索引鍵](https://docs.aws.amazon.com/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.aws.amazon.com/service-authorization/latest/reference/list_amazonkeyspacesforapachecassandra.html#amazonkeyspacesforapachecassandra-policy-keys)。若要了解您可以使用條件金鑰的動作和資源，請參閱 [Amazon Keyspaces 定義的動作 （適用於 Apache Cassandra)](https://docs.aws.amazon.com/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.aws.amazon.com/lambda/latest/dg/access-control-resource-based.html](https://docs.aws.amazon.com/lambda/latest/dg/access-control-resource-based.html)。

## 以 Amazon Keyspaces 標籤為基礎的授權
<a name="security_iam_service-with-iam-tags"></a>

您可以使用標籤來管理對 Amazon Keyspaces 資源的存取。若要根據標籤管理資源存取，您可以使用 `aws:RequestTag/key-name`、 `cassandra:ResourceTag/key-name`或 [條件索引鍵，在政策的條件元素](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html)中提供標籤資訊。 `aws:TagKeys`如需標記 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>

[IAM 角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html)是 中具有特定許可 AWS 帳戶 的實體。

### 搭配 Amazon Keyspaces 使用臨時憑證
<a name="security_iam_service-with-iam-roles-tempcreds"></a>

您可以使用暫時憑證來以聯合身分登入、擔任 IAM 角色，或是擔任跨帳戶角色。您可以透過呼叫 [AssumeRole](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) 或 [GetFederationToken](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetFederationToken.html) 等 AWS STS API 操作來取得臨時安全登入資料。

Amazon Keyspaces 支援使用臨時憑證搭配 Github 儲存庫提供的 AWS Signature 第 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.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#iam-term-service-linked-role)可讓 AWS 服務存取其他服務中的資源，以代表您完成 動作。服務連結角色會顯示在您的 IAM 帳戶中，並由該服務所擁有。IAM 管理員可以檢視，但不能編輯服務連結角色的許可。

如需建立或管理 Amazon Keyspaces 服務連結角色的詳細資訊，請參閱 **[使用 Amazon Keyspaces 的服務連結角色](using-service-linked-roles.md)**。

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

Amazon Keyspaces 不支援服務角色。