

 Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 Python UDF 將繼續正常運作至 2026 年 6 月 30 日。如需詳細資訊，請參閱[部落格文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

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

# 管理 Amazon Redshift 資源存取許可的概觀
<a name="redshift-iam-access-control-overview"></a>

每個 AWS 資源都由 AWS 帳戶擁有，而建立或存取資源的許可則由許可政策管理。帳戶管理員可以將許可政策連接到 IAM 身分 （即使用者、群組和角色），某些服務 （例如 AWS Lambda) 也支援將許可政策連接到 資源。

**注意**  
*帳戶管理員* (或管理員使用者) 是具有管理員權限的使用者。如需詳細資訊，請參閱《[IAM 使用者指南](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)》中的 *IAM 最佳實務*。

授予許可時，您會決定誰取得這些許可、取得哪些資源的許可，以及可以對那些資源進行的特定動作。

## Amazon Redshift 資源和操作
<a name="redshift-iam-accesscontrol.actions-and-resources"></a>

Amazon Redshift 提供服務特有的資源、動作和條件內容索引鍵，可用於 IAM 許可政策。

### Amazon Redshift、Amazon Redshift Serverless、Amazon Redshift 資料 API 和 Amazon Redshift 查詢編輯器 v2 的存取許可
<a name="redshift-policy-resources.resource-permissions"></a>

當設定 [存取控制](redshift-iam-authentication-access-control.md#redshift-iam-accesscontrol) 時，您要編寫可附加到 IAM 身分的許可政策 (身分型政策)。如需詳細的參考資訊，請參閱《服務授權參考》**中的下列主題：
+ 若為 Amazon Redshift，請參閱使用 `redshift:` 前置詞的 [Amazon Redshift 的動作、資源和條件索引鍵](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonredshift.html)。
+ 若為 Amazon Redshift Serverless，請參閱使用 `redshift-serverless:` 前置詞的 [Amazon Redshift Serverless 的動作、資源和條件索引鍵](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonredshiftserverless.html)。
+ 若為 Amazon Redshift 資料 API，請參閱使用 `redshift-data:` 前置詞的 [Amazon Redshift 資料 API 的動作、資源和條件索引鍵](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonredshiftdataapi.html)。
+ 對於 Amazon Redshift 查詢編輯器 v2，請參閱使用 `sqlworkbench:`字首[的 AWS SQL Workbench (Amazon Redshift 查詢編輯器 v2) 的動作、資源和條件索引](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awssqlworkbench.html)鍵。

  查詢編輯器 v2 包含非直接對應至 API 操作的僅限許可動作。《服務授權參考》**中會使用 `[permission only]` 指出這些動作。

《服務授權參考》**包含了可在 IAM 政策中使用哪些 API 操作的相關資訊。它還包含您可以授予許可 AWS 的資源，以及您可以包含用於精細存取控制的條件索引鍵。如需條件的相關資訊，請參閱[使用 IAM 政策條件進行精細定義存取控制](#redshift-policy-resources.conditions)。

您可以在政策的 `Action` 欄位中指定動作、在政策的 `Resource` 欄位中指定資源值，以及在政策的 `Condition` 欄位中指定條件。若要指定 Amazon Redshift 的動作，請使用後接 API 操作名稱的 `redshift:` 前置詞 (例如，`redshift:CreateCluster`)。

## 了解資源所有權
<a name="redshift-iam-access-control-resource-ownership"></a>

*資源擁有者*是建立資源 AWS 的帳戶。也就是說，資源擁有者是驗證建立資源之請求的*委託人實體* （根帳戶、IAM 使用者或 IAM 角色） AWS 的帳戶。下列範例說明其如何運作：
+ 如果您使用 AWS 帳戶的根帳戶登入資料來建立資料庫叢集， AWS 您的帳戶就是 Amazon Redshift 資源的擁有者。
+ 如果您在 AWS 帳戶中建立具有建立 Amazon Redshift 資源許可的 IAM 角色，則任何可以擔任該角色的人都可以建立 Amazon Redshift 資源。您的 AWS 帳戶 (即角色所屬帳戶) 會擁有 Amazon Redshift 資源。
+ 如果您在 AWS 帳戶中建立 IAM 使用者，並將建立 Amazon Redshift 資源的許可授予該使用者，則使用者可以建立 Amazon Redshift 資源。但是您的 AWS 帳戶 (即使用者所屬帳戶) 會擁有 Amazon Redshift 資源。在大多數情況下，不建議您使用此方法。建議您建立 IAM 角色並將許可附加到該角色，然後將角色指派給使用者。

## 管理 資源的存取
<a name="redshift-iam-accesscontrol-managingaccess"></a>

*許可政策*描述誰可以存取哪些資源。下一節說明可用來建立許可政策的選項。

**注意**  
本節著重討論如何在 Amazon Redshift 的環境中使用 IAM。它不提供 IAM 服務的詳細資訊。如需完整的 IAM 文件，請參閱《IAM 使用者指南》**中的[什麼是 IAM？](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)。如需有關 IAM 政策語法和說明的資訊，請參閱《IAM 使用者指南》**中的 [AWS IAM 政策參考](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html)。

連接到 IAM 身分的政策稱為*身分類型*政策 (IAM 政策)，而連接到資源的政策參考*資源類型政策*。Amazon Redshift 僅支援以身分為基礎的政策 (IAM 政策)。

### 身分類型政策 (IAM 政策)
<a name="redshift-iam-manage-access-identity-based"></a>

您可以透過將政策附加到 IAM 角色，然後將該角色指派給使用者或群組來指派許可。下面的範例政策包含用來為您的 AWS 帳戶建立、刪除、修改 Amazon Redshift 叢集和將叢集重新開機的許可。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid":"AllowManageClusters",
      "Effect":"Allow",
      "Action": [
        "redshift:CreateCluster",
        "redshift:DeleteCluster",
        "redshift:ModifyCluster",
        "redshift:RebootCluster"
      ],
      "Resource":"*"
    }
  ]
}
```

------

如需將以身分為基礎的政策與 Amazon Redshift 搭配使用的相關資訊，請參閱[將以身分為基礎的政策 (IAM 政策) 用於 Amazon Redshift](redshift-iam-access-control-identity-based.md)。如需使用者、群組、角色和許可的相關資訊，請參閱《IAM 使用者指南》**中的[身分 (使用者、群組和角色)](https://docs.aws.amazon.com/IAM/latest/UserGuide/id.html)。

### 資源型政策
<a name="redshift-iam-access-control-resource-based"></a>

其他服務 (例如 Amazon S3) 也支援以資源為基礎的許可政策。例如，您可以將政策連接至 S3 儲存貯體，以管理該儲存貯體的存取許可。Amazon Redshift 不支援資源型政策。

## 指定政策元素：動作、效果、資源和主體
<a name="redshift-iam-access-control-specify-actions"></a>

針對每一個 Amazon Redshift 資源 (請參閱 [Amazon Redshift 資源和操作](#redshift-iam-accesscontrol.actions-and-resources))，服務會定義一組 API 操作 (請參閱[動作](https://docs.aws.amazon.com/redshift/latest/APIReference/API_Operations.html))。Amazon Redshift 會定義一組您可在政策中指定的動作，以授予這些 API 操作的許可。執行一項 API 操作可能需要多個動作的許可。

以下是基本的政策元素：
+ **資源** – 在政策中，您可以使用 Amazon Resource Name (ARN) 來識別要套用政策的資源。如需詳細資訊，請參閱[Amazon Redshift 資源和操作](#redshift-iam-accesscontrol.actions-and-resources)。
+ **動作**：使用動作關鍵字識別您要允許或拒絕的資源操作。例如，`redshift:DescribeClusters` 許可會讓使用者獲得執行 Amazon Redshift `DescribeClusters` 操作的許可。
+ **效果** - 您可以指定使用者要求特定動作時會有什麼效果；可為允許或拒絕。如果您未明確授予存取 (允許) 資源，則隱含地拒絕存取。您也可以明確拒絕資源存取，這樣做可確保使用者無法存取資源，即使不同政策授予存取也是一樣。
+ **委託人**：在以身分為基礎的政策 (IAM 政策) 中，政策所連接的使用者就是隱含委託人。對於資源型政策，您可以指定想要收到許可的使用者、帳戶、服務或其他實體 (僅適用於資源型政策)。Amazon Redshift 不支援資源型政策。

如需進一步了解有關 IAM 政策語法和說明的詳細資訊，請參閱《IAM 使用者指南》**中的 [AWS IAM 政策參考](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html)。

如需詳列所有 Amazon Redshift API 動作及適用資源的表格，請參閱 [Amazon Redshift、Amazon Redshift Serverless、Amazon Redshift 資料 API 和 Amazon Redshift 查詢編輯器 v2 的存取許可](#redshift-policy-resources.resource-permissions)。



## 在政策中指定條件
<a name="redshift-policy-resources.specifying-conditions"></a>

當您授予許可時，可以使用存取政策語言來指定政策應該何時生效的條件。例如，建議只在特定日期之後套用政策。如需以存取政策語言指定條件的相關資訊，請參閱《IAM 使用者指南》**中的 [IAM JSON 政策元素：條件](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html)。

若要識別許可政策適用的條件，請在您的 IAM 許可政策中包含 `Condition` 元素。例如，您可以建立允許使用者使用 `redshift:CreateCluster` 動作來建立叢集的政策，並且可以新增 `Condition` 元素，將該使用者限制在僅限於特定區域中建立叢集。如需詳細資訊，請參閱[使用 IAM 政策條件進行精細定義存取控制](#redshift-policy-resources.conditions)。如需呈現所有條件索引鍵值以及 Amazon Redshift 動作和其套用之資源的清單，請參閱 [Amazon Redshift、Amazon Redshift Serverless、Amazon Redshift 資料 API 和 Amazon Redshift 查詢編輯器 v2 的存取許可](#redshift-policy-resources.resource-permissions)。

### 使用 IAM 政策條件進行精細定義存取控制
<a name="redshift-policy-resources.conditions"></a>

在 Amazon Redshift 中，您可以使用兩個條件索引鍵，根據那些資源的標籤來限制對資源的存取權限。下列是常見的 Amazon Redshift 條件索引鍵。


| 條件金鑰 | Description | 
| --- | --- | 
| `aws:RequestTag` | 每當使用者建立資源時，都會要求使用者包括標籤索引鍵 (名稱) 和值。如需詳細資訊，請參閱《IAM 使用者指南》**中的 [aws:RequestTag](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-requesttag)。 | 
| `aws:ResourceTag` | 根據特定標籤索引鍵和值，限制使用者對資源的存取。如需詳細資訊，請參閱《IAM 使用者指南》**中的 [aws:ResourceTag](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-resourcetag)。 | 
| `aws:TagKeys` | 使用此鍵來將請求中的標籤鍵與您在政策中所指定的鍵進行比較。如需詳細資訊，請參閱《IAM 使用者指南》**中的 [aws:TagKeys](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-tagkeys)。 | 

如需標籤的詳細資訊，請參閱[在 Amazon Redshift 中標記資源](amazon-redshift-tagging.md)。

如需支援 `redshift:RequestTag` 和 `redshift:ResourceTag` 條件索引鍵的 API 動作清單，請參閱[Amazon Redshift、Amazon Redshift Serverless、Amazon Redshift 資料 API 和 Amazon Redshift 查詢編輯器 v2 的存取許可](#redshift-policy-resources.resource-permissions)。

下列條件索引鍵可以與 Amazon Redshift GetClusterCredentials 動作搭配使用。


| 條件金鑰 | Description | 
| --- | --- | 
| `redshift:DurationSeconds` | 限制可為持續時間指定的秒數。 | 
| `redshift:DbName` | 限制可以指定的資料庫名稱。 | 
| `redshift:DbUser` | 限制可以指定的資料庫使用者名稱。 | 

#### 範例 1：透過使用 aws:ResourceTag 條件金鑰限制存取
<a name="redshift-policy-resources.resource-permissions-example1"></a>

使用下列 IAM 政策，可讓使用者僅針對 `us-west-2` 區域中具有標籤值為 `environment`之標籤的特定 AWS 帳戶修改 Amazon Redshift 叢集`test`。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": {
        "Sid":"AllowModifyTestCluster",
        "Effect": "Allow",
        "Action": "redshift:ModifyCluster",
        "Resource": "arn:aws:redshift:us-west-2:123456789012:cluster:*",
        "Condition": {
            "StringEquals": {
                "aws:ResourceTag/environment": "test"
            }
        }
    }
}
```

------

#### 範例 2：透過使用 aws:RequestTag 條件金鑰限制存取
<a name="redshift-policy-resources.resource-permissions-example2"></a>

使用下列 IAM 政策可讓使用者僅在建立叢集的命令包含名為 `usage` 的標籤和標籤值為 `production` 時建立 Amazon Redshift 叢集。`aws:TagKeys` 和 `ForAllValues` 修飾符的條件指定您在請求中只能指定金鑰 `costcenter` 和 `usage`。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": {
        "Sid":"AllowCreateProductionCluster",
        "Effect": "Allow",
        "Action": [
            "redshift:CreateCluster",
            "redshift:CreateTags"
        ],
        "Resource": "*",
        "Condition": {
            "StringEquals": {
                "aws:RequestTag/usage": "production"
            },
            "ForAllValues:StringEquals": {
                "aws:TagKeys": [
                    "costcenter",
                    "usage"
                ]
            }
        }
    }
}
```

------