

 从补丁 198 开始，Amazon Redshift 将不再支持创建新的 Python UDF。现有的 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/)。

# 将 Redshift 与 AWS IAM Identity Center 连接来提供单点登录体验
<a name="redshift-iam-access-control-idp-connect"></a>

您可以通过可信身份传播来管理用户和组对 Amazon Redshift 数据仓库的访问权限。

[Trusted identity propagation](https://docs.aws.amazon.com//singlesignon/latest/userguide/trustedidentitypropagation-overview.html) 是一项 AWS IAM Identity Center 功能，已连接的 AWS 服务的管理员可以使用它来授予和审计对服务数据的访问权限。对这些数据的访问权限基于用户属性，例如组关联。设置可信身份传播要求已连接的 AWS 服务的管理员和 IAM Identity Center 管理员之间进行协作。有关更多信息，请参阅 [Prerequisites and considerations](https://docs.aws.amazon.com//singlesignon/latest/userguide/trustedidentitypropagation-overall-prerequisites.html)。

以一个端到端案例来说明，您可以使用 Amazon Quick 控制面板或 Amazon Redshift 查询编辑器 v2 来访问 Redshift。在这种情况下，访问权限基于 AWS IAM Identity Center 组。Redshift 可以确定用户的身份以及他们的组成员资格。AWSIAM Identity Center 还允许通过 Okta 或 PingOne 等第三方身份提供者 (IdP) 连接和管理身份。

管理员设置 Redshift 与 AWS IAM Identity Center 之间的连接后，他们可以根据身份提供者的组来配置精细访问权限，以授权用户访问数据。

**重要**  
从 AWS IAM Identity Center 或连接的身份提供者（IdP）目录中删除用户时，该用户不会自动从 Amazon Redshift 目录中删除。要从 Amazon Redshift 目录中手动删除用户，请运行 `DROP USER` 命令以完全删除已从 AWS IAM Identity Center 或 IdP 中移除的用户。有关如何删除用户的更多信息，请参阅《Amazon Redshift 数据库开发人员指南》**中的 [DROP USER](https://docs.aws.amazon.com/redshift/latest/dg/r_DROP_USER.html)。

## Redshift 与 AWS IAM Identity Center 集成的优势
<a name="redshift-iam-access-control-idp-connect-benefits"></a>

将 AWS IAM Identity Center 与 Redshift 结合使用，可以在以下方面为企业带来益处：
+  Amazon Quick 中的控制面板作者无需重新输入密码，也无需要求管理员设置具有复杂权限的 IAM 角色，即可连接 Redshift 数据来源。
+  AWS IAM Identity Center 为您在 AWS 中的员工用户提供了一个中心位置。您可以直接在 AWS IAM Identity Center 创建用户和群，也可以连接您在基于标准的身份提供者中管理的现有用户和组，例如 Okta、PingOne 或 Microsoft Entra ID（Azure AD）。AWSIAM Identity Center 将身份验证定向到您为用户和组选择的信任源，并维护一个用户和组的目录以供 Redshift 访问。有关更多信息，请参阅《AWS IAM Identity Center 用户指南》**中的[管理您的身份源](https://docs.aws.amazon.com/singlesignon/latest/userguide/manage-your-identity-source.html)和[支持的身份提供者](https://docs.aws.amazon.com/singlesignon/latest/userguide/supported-idps.html)。
+ 通过简单的自动发现和连接功能，您便可与多个 Redshift 集群和工作组共享一个 AWS IAM Identity Center 实例。这样可以快速添加集群，而无需额外地为每个集群配置 AWS IAM Identity Center 连接，还可确保所有集群和工作组都能一致地查看用户、其属性和组。请注意，您企业的 AWS IAM Identity Center 实例必须与要连接的任意 Redshift 数据共享位于同一区域。
+ 由于用户身份已知并与数据访问记录在一起，因此您可以通过在 AWS CloudTrail 中审计用户的访问，更轻松地满足合规性监管要求。

## 用于连接应用程序的管理员角色
<a name="redshift-iam-access-control-idp-personas"></a>

在将分析应用程序连接到 AWS IAM Identity Center 托管的 Redshift 应用程序的过程中，以下角色非常关键：
+ **应用程序管理员** – 创建应用程序并配置要与哪些服务启用身份令牌交换。此管理员还需要指定哪些用户或组有权访问应用程序。
+ **数据管理员** – 配置对数据的精细访问权限。AWS IAM Identity Center 中的用户和组可以映射到特定权限。

## 使用 AWS IAM Identity Center 通过 Amazon Quick 连接到 Amazon Redshift
<a name="redshift-iam-access-control-idp-connect-qs"></a>

以下内容演示在连接到 Redshift 并通过 AWS IAM Identity Center 管理访问权限时，如何使用 Quick 通过 Redshift 进行身份验证：[授权从 Quick 到 Amazon Redshift 集群的连接](https://docs.aws.amazon.com/quick/latest/userguide/enabling-access-redshift.html)。这些步骤也适用于 Amazon Redshift Serverless。

## 使用 AWS IAM Identity Center 通过 Amazon Redshift 查询编辑器 v2 连接到 Amazon Redshift
<a name="redshift-iam-access-control-idp-connect-qe"></a>

完成设置 AWS IAM Identity Center 与 Redshift 连接的步骤后，用户可以通过基于 AWS IAM Identity Center 且以命名空间为前缀的身份，访问数据库以及数据库中的相应对象。有关使用查询编辑器 v2 登录身份连接到 Redshift 数据库的更多信息，请参阅[使用查询编辑器 v2 查询数据库使用 Amazon Redshift 查询编辑器 v2 查询数据库](query-editor-v2.md)。



## 跨多个 AWS 区域使用 AWS IAM Identity Center
<a name="redshift-iam-access-control-idp-connect-multi-region"></a>

Amazon Redshift 在多个 AWS 区域中支持 AWS IAM Identity Center。您可以将 AWS IAM Identity Center 从您的主 AWS 区域扩展到其它区域，从而通过靠近用户和提高可靠性来提高性能。在 AWS IAM Identity Center 中添加新区域后，您无需从主区域中复制身份，即可在新区域中创建 Redshift IAM Identity Center 应用程序。您可以在新区域中使用 AWS IAM Identity Center 设置 Amazon Redshift 联合权限，在该新区域中，您可以启用行级、列级和掩蔽控件。有关在多个区域中开始使用 AWS IAM Identity Center 的更多详细信息，请参阅《AWS IAM Identity Center 用户指南》**中的[在多个 AWS 区域中管理 AWS IAM Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/multi-region-iam-identity-center.html)。

## 使用 AWS IAM Identity Center 连接到 Amazon Redshift 的优势
<a name="redshift-iam-access-control-idp-connect-limitations"></a>

使用 AWS IAM Identity Center 单点登录时，请考虑以下限制：


+  **不支持增强型 VPC**：当您对 Amazon Redshift 使用 AWS IAM Identity Center 单点登录时，不支持增强型 VPC。有关增强型 VPC 的更多信息，请参阅 [Amazon Redshift 中的增强型 VPC 路由](https://docs.aws.amazon.com/redshift/latest/mgmt/enhanced-vpc-routing.html)。

# 设置 AWS IAM Identity Center 与 Amazon Redshift 的集成
<a name="redshift-iam-access-control-idp-connect-console"></a>

您的 Amazon Redshift 集群管理员或 Amazon Redshift Serverless 管理员必须执行多个步骤，以将 Redshift 配置为启用了 AWS IAM Identity Center 的应用程序。这样，Redshift 便可以自动发现并连接到 AWS IAM Identity Center 来获取登录和用户目录服务。在此之后，当 Redshift 管理员创建集群或工作组时，他们可以允许新的数据仓库使用 AWS IAM Identity Center 来管理数据库访问。

启用 Redshift 作为 AWS IAM Identity Center 托管应用程序的意义在于，您可以从 AWS IAM Identity Center 中或与之集成的第三方身份提供者控制用户和组的权限。当数据库用户（例如分析师或数据科学家）登录 Redshift 数据库时，服务会在 AWS IAM Identity Center 中检查他们所属的组，这些组与 Redshift 中的角色名称相匹配。通过这种方式，举例而言，定义了 Redshift 数据库角色名称的组可以访问一组表以便进行销售分析。以下部分将介绍如何完成此设置。

## 先决条件
<a name="redshift-iam-access-control-idp-connect-prerequisites"></a>

将 AWS IAM Identity Center 与 Amazon Redshift 集成的先决条件如下所示：
+ *账户配置* – 如果您计划使用跨账户应用场景，或者如果您在具有相同 AWS IAM Identity Center 实例的不同账户中使用 Redshift 集群，则必须在 AWS Organizations 管理账户中配置 AWS IAM Identity Center。这包括配置您的身份源。有关更多信息，请参阅**《AWS IAM Identity Center 用户指南》中的[入门](https://docs.aws.amazon.com/singlesignon/latest/userguide/getting-started.html)、[员工身份](https://docs.aws.amazon.com/singlesignon/latest/userguide/identities.html)和[支持的身份提供者](https://docs.aws.amazon.com/singlesignon/latest/userguide/supported-idps.html)。您必须确保已在 AWS IAM Identity Center 中创建用户或组，或者已从您的身份源同步用户和组，然后才能在 Redshift 中将他们指定到 Redshift 中的数据。
**注意**  
您可以选择使用 AWS IAM Identity Center 的账户实例，前提是 Redshift 和 AWS IAM Identity Center 位于同一个账户中。在创建和配置 Redshift 集群或工作组时，您可以使用小组件创建此实例。
+ *配置可信令牌发布者* – 在某些情况下，您可能需要使用可信令牌发布者，这是可以发布和验证信任令牌的实体。在执行此操作之前，需要先执行预备步骤，然后配置 AWS IAM Identity Center 集成的 Redshift 管理员才能选择可信令牌发布者，并添加必要的属性以完成配置。这些步骤可能包括在 AWS IAM Identity Center 控制台中，将外部身份提供者配置为可信令牌发布者并添加其属性。要完成这些步骤，请参阅 [Using applications with a trusted token issuer](https://docs.aws.amazon.com/singlesignon/latest/userguide/using-apps-with-trusted-token-issuer.html#setuptrustedtokenissuer)。
**注意**  
并非所有外部连接都需要设置可信令牌发布者。使用 Amazon Redshift 查询编辑器 v2 连接到您的 Redshift 数据库时，不需要配置可信令牌发布者。但可能需要对第三方应用程序进行配置，例如通过您的身份提供者进行身份验证的控制面板或自定义应用程序。
+ *配置 IAM 角色* – 后面的部分提到了必须配置的权限。您必须按照 IAM 最佳实践添加权限。后面的步骤将会详细介绍具体权限。

有关更多信息，请参阅 [Getting Started with AWS IAM Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/get-started-enable-identity-center.html)。

## 配置您的身份提供者以使用 AWS IAM Identity Center
<a name="redshift-iam-access-control-idp-connect-admin-config"></a>

控制用户和组身份管理的第一步是连接到 AWS IAM Identity Center 并配置您的身份提供者。您可以使用 AWS IAM Identity Center 本身作为身份提供者，也可以连接第三方身份存储，例如 Okta。有关设置与身份提供者的连接和进行配置的更多信息，请参阅**《AWS IAM Identity Center 用户指南》中的[连接到外部身份提供者](https://docs.aws.amazon.com/singlesignon/latest/userguide/manage-your-identity-source-idp.html)。请确保在此过程结束时，您已将一小批用户和组添加到 AWS IAM Identity Center 以用于测试目的。

### 管理权限
<a name="redshift-iam-access-control-idp-connect-admin-permissions"></a>

#### Redshift/AWS IAM Identity Center 应用程序生命周期管理所需的权限
<a name="redshift-iam-access-control-permissions-application"></a>

您必须创建一个 IAM 身份供 Redshift 管理员用来配置 Redshift，以便与 AWS IAM Identity Center 结合使用。常见的做法是，创建一个具有相应权限的 IAM 角色，并根据需要将其分配给其他身份。该角色必须具有执行以下操作的权限。

**创建 Redshift/AWS IAM Identity Center 应用程序**
+ `sso:PutApplicationAssignmentConfiguration` – 用于安全设置。
+ `sso:CreateApplication` – 用于创建 AWS IAM Identity Center 应用程序。
+ `sso:PutApplicationAuthenticationMethod` – 授予 Redshift 身份验证访问权限。
+ `sso:PutApplicationGrant` – 用于更改可信令牌发布者信息。
+ `sso:PutApplicationAccessScope` – 用于 Redshift AWS IAM Identity Center 应用程序设置。这包括用于 AWS Lake Formation 和用于 [Amazon S3 Access Grants](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-grants-get-started.html)。
+ `redshift:CreateRedshiftIdcApplication` – 用于创建 Redshift AWS IAM Identity Center 应用程序。

**描述 Redshift/AWS IAM Identity Center 应用程序**
+ `sso:GetApplicationGrant` – 用于列出可信令牌发布者信息。
+ `sso:ListApplicationAccessScopes` – 用于 Redshift AWS IAM Identity Center 应用程序设置以列出下游集成，例如用于 AWS Lake Formation 和 S3 Access Grants。
+ `redshift:DescribeRedshiftIdcApplications` – 用于描述现有 AWS IAM Identity Center 应用程序。

**更改 Redshift/AWS IAM Identity Center 应用程序**
+ `redshift:ModifyRedshiftIdcApplication` – 用于更改现有的 Redshift 应用程序。
+ `sso:UpdateApplication` – 用于更新 AWS IAM Identity Center 应用程序。
+ `sso:GetApplicationGrant` – 获取可信令牌颁发者信息。
+ `sso:ListApplicationAccessScopes` – 用于 Redshift AWS IAM Identity Center 应用程序设置。
+ `sso:DeleteApplicationGrant` – 删除可信令牌颁发者信息。
+ `sso:PutApplicationGrant` – 用于更改可信令牌发布者信息。
+ `sso:PutApplicationAccessScope` – 用于 Redshift AWS IAM Identity Center 应用程序设置。这包括用于 AWS Lake Formation 和用于 [Amazon S3 Access Grants](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-grants-get-started.html)。
+ `sso:DeleteApplicationAccessScope` – 用于删除 Redshift AWS IAM Identity Center 应用程序设置。这包括用于 AWS Lake Formation 和用于 [Amazon S3 Access Grants](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-grants-get-started.html)。

**删除 Redshift/AWS IAM Identity Center 应用程序**
+ `sso:DeleteApplication` – 用于删除 AWS IAM Identity Center 应用程序。
+ `redshift:DeleteRedshiftIdcApplication` – 提供删除现有 Redshift AWS IAM Identity Center 应用程序的功能。

#### Redshift/查询编辑器 v2 应用程序生命周期管理所需的权限
<a name="redshift-iam-access-control-permissions-application-qev2"></a>

您必须创建一个 IAM 身份供 Redshift 管理员用来配置 Redshift，以便与 AWS IAM Identity Center 结合使用。常见的做法是，创建一个具有相应权限的 IAM 角色，并根据需要将其分配给其他身份。该角色必须具有执行以下操作的权限。

**创建查询编辑器 v2 应用程序**
+ `redshift:CreateQev2IdcApplication` – 用于创建 QEV2 应用程序。
+ `sso:CreateApplication` – 提供创建 AWS IAM Identity Center 应用程序的功能。
+ `sso:PutApplicationAuthenticationMethod` – 授予 Redshift 身份验证访问权限。
+ `sso:PutApplicationGrant` – 用于更改可信令牌发布者信息。
+ `sso:PutApplicationAccessScope` – 用于 Redshift AWS IAM Identity Center 应用程序设置。这包括查询编辑器 v2。
+ `sso:PutApplicationAssignmentConfiguration` – 用于安全设置。

**描述查询编辑器 v2 应用程序**
+ `redshift:DescribeQev2IdcApplications` – 用于描述 AWS IAM Identity Center QEV2 应用程序。

**更改查询编辑器 v2 应用程序**
+ `redshift:ModifyQev2IdcApplication` – 用于更改 AWS IAM Identity Center QEV2 应用程序。
+ `sso:UpdateApplication` – 用于更改 AWS IAM Identity Center QEV2 应用程序。

**删除查询编辑器 v2 应用程序**
+ `redshift:DeleteQev2IdcApplication` – 用于删除 QEV2 应用程序。
+ `sso:DeleteApplication` – 用于删除 QEV2 应用程序。

**注意**  
在 Amazon Redshift 开发工具包中，以下 API 不可用：  
CreateQev2IdcApplication
DescribeQev2IdcApplications
ModifyQev2IdcApplication
DeleteQev2IdcApplication
这些操作专门用于在 AWS 控制台中执行 AWS IAM Identity Center 与 Redshift QEV2 的集成。有关更多信息，请参阅 [Amazon Redshift 定义的操作](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonredshift.html#amazonredshift-actions-as-permissions)。

#### 数据库管理员在控制台中连接新资源所需的权限
<a name="redshift-iam-access-control-permissions-application-new-resources"></a>

在创建过程中，需要这些权限才能连接新预置的集群或 Amazon Redshift Serverless 工作组。如果您具有这些权限，则控制台中会显示一个选项，供您选择连接到 AWS IAM Identity Center 托管的 Redshift 应用程序。
+ `redshift:DescribeRedshiftIdcApplications`
+ `sso:ListApplicationAccessScopes`
+ `sso:GetApplicationAccessScope`
+ `sso:GetApplicationGrant`

作为最佳实践，我们建议将权限策略附加到 IAM 角色，然后根据需要将其分配给用户和组。有关更多信息，请参阅 [Amazon Redshift 中的 Identity and Access Management](https://docs.aws.amazon.com/redshift/latest/mgmt/redshift-iam-authentication-access-control.html)。

## 使用 AWS IAM Identity Center 将 Redshift 设置为 AWS 托管应用程序
<a name="redshift-iam-access-control-idp-connect-admin-tasks"></a>

Redshift 管理员必须完成以下步骤，使 Redshift 成为 AWS IAM Identity Center 托管应用程序，然后 AWS IAM Identity Center 才能管理 Amazon Redshift 预置集群或 Amazon Redshift Serverless 工作组的身份：

1. 在 Amazon Redshift 或 Amazon Redshift Serverless 控制台菜单中选择 **AWS IAM Identity Center 集成**，然后选择**连接到 AWS IAM Identity Center**。在其中，您可以逐步完成一系列选择来填充 AWS IAM Identity Center 集成的属性。

1. 为 Redshift 的 AWS Identity Center 托管应用程序选择显示名称和唯一名称。

1. 为您的组织指定命名空间。这通常是组织名称的缩写。它已作为前缀添加到 Redshift 数据库中 AWS IAM Identity Center 管理的用户和角色。

1. 选择要使用的 IAM 角色。此 IAM 角色应与用于 Redshift 的其他角色分开，建议不要将该角色其用于其他目的。所需的特定策略权限如下所示：
   + `sso:DescribeApplication` – 需要在目录中创建身份提供者 (IdP) 条目。
   + `sso:DescribeInstance` – 用于手动创建 IdP 联合身份验证角色或用户。

1. 配置客户端连接和可信令牌发布者。配置可信令牌发布者，通过设置与外部身份提供者的关系来协调可信身份的传播。例如，通过身份传播，用户可以登录一个应用程序并访问另一个应用程序中的特定数据。这样用户便可以更无缝地从不同位置收集数据。在此步骤中，您可以在控制台中为每个可信令牌发布者设置属性。这些属性包括名称和受众群体声明（简写为 *aud claim*），您可能需要从工具或服务的配置属性中获取这些信息。您可能还需要从第三方工具的 JSON Web 令牌 (JWT, JSON Web Token) 提供应用程序名称。
**注意**  
每个第三方工具或服务要求的 `aud claim` 可能会有所不同，具体取决于令牌类型，这些可以是身份提供者发布的访问令牌，也可以是 ID 令牌等其他类型。每个供应商都可能不同。在实施可信身份传播并与 Redshift 集成时，您需要为第三方工具发送到 AWS 的令牌类型提供正确的 *aud* 值。请查看您的工具或服务供应商的建议。

   有关可信身份传播的详细信息，请参阅《AWS IAM Identity Center 用户指南》**中的 [Trusted identity propagation overview](https://docs.aws.amazon.com/singlesignon/latest/userguide/trustedidentitypropagation-overview.html)。

Redshift 管理员完成步骤并保存配置后，AWS IAM Identity Center 属性将显示在 Redshift 控制台中。您也可以查询系统视图 [SVV\$1IDENTITY\$1PROVIDERS](https://docs.aws.amazon.com/redshift/latest/dg/r_SVV_IDENTITY_PROVIDERS.html) 来验证应用程序的属性。这些属性包括应用程序名称和命名空间。您可以使用命名空间作为与应用程序关联的 Redshift 数据库对象的前缀。完成这些任务后，Redshift 便成为支持 AWS IAM Identity Center 的应用程序。控制台中的属性包括集成状态。集成完成后，它会显示**已启用**。完成此流程后，可以在每个新集群上启用 AWS IAM Identity Center 集成。

完成配置后，您可以在 Redshift 中使用 AWS IAM Identity Center 的用户和组，方法是选择**用户**或**组**选项卡，然后选择**分配**。

## 为 Amazon Redshift 集群或 Amazon Redshift Serverless 工作组启用 AWS IAM Identity Center 集成
<a name="redshift-iam-access-control-idp-connect-resource-creation"></a>

您的数据库管理员配置新的 Redshift 资源，使其与 AWS IAM Identity Center 配合使用，从而简化登录和数据访问。此过程包括在创建预置集群或无服务器工作组的步骤中。任何有权创建 Redshift 资源的人员都可以执行这些 AWS IAM Identity Center 集成任务。当您创建预置集群时，请首先在 Amazon Redshift 控制台中选择**创建集群**。以下步骤显示如何为数据库启用 AWS IAM Identity Center 管理。（其中并未包括创建集群的所有步骤。）

1. 在创建集群步骤中，在 **IAM Identity Center 集成**部分中，选择**为 <您的集群名称> 启用**。

1. 在启用集成时，流程中有一个步骤。您可以在控制台中选择**启用 IAM Identity Center 集成**来完成此步骤。

1. 对于新的集群或工作组，使用 SQL 命令在 Redshift 中创建数据库角色。命令如下：

   ```
   CREATE ROLE <idcnamespace:rolename>;
   ```

   命名空间和角色名称如下：
   + *IAM Identity Center 命名空间前缀* – 这是您在设置 AWS IAM Identity Center 与 Redshift 之间的连接时，定义的命名空间。
   + *角色名称* – 此 Redshift 数据库角色必须与 AWS IAM Identity Center 中的组名匹配。

   Redshift 连接到 AWS IAM Identity Center，然后提取创建数据库角色并将其映射到 AWS IAM Identity Center 组所需的信息。

请注意，创建新的数据仓库时，为 AWS IAM Identity Center 集成指定的 IAM 角色将自动附加到预置集群或 Amazon Redshift Serverless 工作组。完成所需集群元数据的输入和资源创建后，您可以在属性中查看 AWS IAM Identity Center 集成的状态。如果您在 AWS IAM Identity Center 中的组名有空格，则在创建匹配角色时需要在 SQL 中使用引号。

启用 Redshift 数据库并创建角色后，就可以使用 Amazon Redshift 查询编辑器 v2 或 Amazon Quick 连接到数据库。详细信息将在后面的部分中进一步说明。

### 使用 API 设置默认 `RedshiftIdcApplication`
<a name="redshift-iam-access-control-idp-connect-admin-config-api"></a>

由您的身份管理员完成设置。使用 API，您可以创建并填充 `RedshiftIdcApplication`，它代表 AWS IAM Identity Center 中的 Redshift 应用程序。

1. 首先，您可以创建用户，并将这些用户添加到 AWS IAM Identity Center 的组中。您可以在 AWS 控制台中为 AWS IAM Identity Center 执行此操作。

1. 调用 `create-redshift-idc-application` 以创建 AWS IAM Identity Center 应用程序，使其与 Redshift 的使用兼容。您可以通过填充所需的值来创建应用程序。显示名称是在 AWS IAM Identity Center 控制面板上显示的名称。IAM 角色 ARN 是拥有 AWS IAM Identity Center 权限的 ARN，同样也可由 Redshift 代入。

   ```
   aws redshift create-redshift-idc-application
   ––idc-instance-arn 'arn:aws:sso:::instance/ssoins-1234a01a1b12345d'
   ––identity-namespace 'MYCO'
   ––idc-display-name 'TEST-NEW-APPLICATION'
   ––iam-role-arn 'arn:aws:redshift:us-east-1:012345678901:role/TestRedshiftRole'
   ––redshift-idc-application-name 'myredshiftidcapplication'
   ```

   以下示例显示了对 `create-redshift-idc-application` 的调用返回的示例 `RedshiftIdcApplication` 响应。

   ```
   "RedshiftIdcApplication": {
                   "IdcInstanceArn": "arn:aws:sso:::instance/ssoins-1234a01a1b12345d",
                   "RedshiftIdcApplicationName": "test-application-1",
                   "RedshiftIdcApplicationArn": "arn:aws:redshift:us-east-1:012345678901:redshiftidcapplication:12aaa111-3ab2-3ab1-8e90-b2d72aea588b",
                   "IdentityNamespace": "MYCO",
                   "IdcDisplayName": "Redshift-Idc-Application",
                   "IamRoleArn": "arn:aws:redshift:us-east-1:012345678901:role/TestRedshiftRole",
                   "IdcManagedApplicationArn": "arn:aws:sso::012345678901:application/ssoins-1234a01a1b12345d/apl-12345678910",
                   "IdcOnboardStatus": "arn:aws:redshift:us-east-1:123461817589:redshiftidcapplication",
                   "RedshiftIdcApplicationArn": "Completed",
                   "AuthorizedTokenIssuerList": [
                          "TrustedTokenIssuerArn": ...,
                          "AuthorizedAudiencesList": [...]...
                   ]}
   ```

1. 您可以使用 `create-application-assignment`，将特定组或个人用户分配给 AWS IAM Identity Center 中的托管应用程序。采用这种做法，您可以指定通过 AWS IAM Identity Center 管理的组。如果数据库管理员在 Redshift 中创建数据库角色，则 AWS IAM Identity Center 中的组名会映射到 Redshift 中的角色名称。数据库中的角色控制权限。有关更多信息，请参阅[Assign user access to applications in the AWS IAM Identity Center console](https://docs.aws.amazon.com/singlesignon/latest/userguide/assignuserstoapp.html)。

1. 启用应用程序后，调用 `create-cluster` 并附上 AWS IAM Identity Center 中的 Redshift 托管应用程序 ARN。通过这样做，可以将集群与 AWS IAM Identity Center 中的托管应用程序关联起来。

### 将 AWS IAM Identity Center 应用程序与现有集群或工作组关联
<a name="redshift-iam-access-control-idp-connect-admin-config-existing"></a>

如果您要为现有的集群或工作组启用 AWS IAM Identity Center 集成，可以通过运行 SQL 命令来实现。您也可以运行 SQL 命令来更改集成的设置。有关更多信息，请参阅 [ALTER IDENTITY PROVIDER](https://docs.aws.amazon.com/redshift/latest/dg/r_ALTER_IDENTITY_PROVIDER.html)。

还可以删除现有身份提供者。以下示例演示如何对附加到身份提供者的用户和角色执行级联删除。

```
DROP IDENTITY PROVIDER
<provider_name> [ CASCADE ]
```

## 设置用户权限
<a name="redshift-iam-access-control-idp-connect-user-permissions"></a>

管理员根据用户的身份属性和组成员资格，在其身份提供者内部或直接在 AWS IAM Identity Center 中配置对各种资源的权限。例如，身份提供者管理员可以将数据库工程师添加到适合其角色的组中。此组名映射到 Redshift 数据库角色名称。该角色提供或限制对 Redshift 中特定表或视图的访问权限。

# 自动为 AWS IAM Identity Center 创建 Amazon Redshift 角色
<a name="redshift-iam-access-control-sso-autocreate"></a>

此特征与 AWS IAM Identity Center 集成，让您可以根据组成员资格在 Redshift 中自动创建角色。

自动创建角色有几个好处。自动创建角色时，Redshift 会在您的 IdP 中创建具有组成员资格的角色，因此您可以避免繁琐的手动角色创建和维护。您还可以选择使用包括和排除模式来筛选映射到 Redshift 角色的组。

## 工作原理
<a name="autocreate-overview"></a>

当您以 IdP 用户身份登录 Redshift 时，会发生以下一系列事件：

1. Redshift 从 IdP 那里检索您的组成员资格。

1. Redshift 使用角色格式 `idp_namespace:rolename` 自动创建映射到这些组的角色。

1. Redshift 授予您使用映射角色的权限。

每次用户登录时，都会自动创建目录中不存在但该用户所属的每个组。您可以选择设置包括和排除筛选条件，从而控制哪些 IdP 组已创建 Redshift 角色。

## 配置自动创建角色
<a name="autocreate-configuring"></a>

使用 `CREATE IDENTITY PROVIDER` 和 `ALTER IDENTITY PROVIDER` 命令启用和配置自动角色创建。

```
-- Create a new IdP with auto role creation enabled
CREATE IDENTITY PROVIDER <idp_name> TYPE AWSIDC
  NAMESPACE '<namespace>' 
  APPLICATION_ARN 'app_arn'
  IAM_ROLE 'role_arn'
  AUTO_CREATE_ROLES TRUE; 

-- Enable on existing IdP 
ALTER IDENTITY PROVIDER <idp_name>
  AUTO_CREATE_ROLES TRUE;

-- Disable  
ALTER IDENTITY PROVIDER <idp_name>
  AUTO_CREATE_ROLES FALSE;
```

## 筛选组
<a name="autocreate-filtering"></a>

您可以选择使用 `INCLUDE` 和 `EXCLUDE` 模式筛选映射到 Redshift 角色的 IdP 组。当模式冲突时，`EXCLUDE` 优先于 `INCLUDE`。

```
-- Only create roles for groups with 'dev' 
CREATE IDENTITY PROVIDER <idp_name> TYPE AWSIDC
  ...
  AUTO_CREATE_ROLES TRUE
  INCLUDE GROUPS LIKE '%dev%';
    
-- Exclude 'test' groups
ALTER IDENTITY PROVIDER <idp_name>  
  AUTO_CREATE_ROLES TRUE
  EXCLUDE GROUPS LIKE '%test%';
```

## 示例
<a name="autocreate-filtering"></a>

以下示例说明了如何启用自动创建角色而不进行筛选。

```
CREATE IDENTITY PROVIDER prod_idc TYPE AWSIDC  ...
  AUTO_CREATE_ROLES TRUE;
```

以下示例包括开发组，不包括测试组。

```
ALTER IDENTITY PROVIDER prod_idc
  AUTO_CREATE_ROLES TRUE
  INCLUDE GROUPS LIKE '%dev%'
  EXCLUDE GROUPS LIKE '%test%';
```

## 最佳实践
<a name="autocreate-bp"></a>

为角色启用自动创建功能时，请考虑遵循以下最佳实践：
+ 使用 `INCLUDE` 和 `EXCLUDE` 筛选条件来控制哪些组获得角色。
+ 定期审核角色并清理未使用的角色。
+ 利用 Redshift 角色层次结构来简化权限管理。

# Amazon Redshift 与 Amazon S3 访问权限管控的集成
<a name="redshift-iam-access-control-sso-s3idc"></a>

通过与 Amazon S3 访问权限管控集成，可以无缝传播 IAM Identity Center 身份，来控制对 Amazon S3 数据的访问权限。此集成支持您根据 IAM Identity Center 用户和组授权 Amazon S3 数据访问权限。

有关 Amazon S3 访问权限管控的信息，请参阅[使用 S3 访问权限管控管理访问权限](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-grants.html)。

使用 Amazon S3 访问权限管控可为应用程序带来以下优势：
+ 基于 IAM Identity Center 身份，对 Amazon S3 数据进行精细的访问控制。
+ 跨 Amazon Redshift 和 Amazon S3 集中管理 IAM Identity Center 身份。
+ 您可以避免为 Amazon S3 访问权限管理单独的 IAM 权限。

## 工作原理
<a name="redshift-iam-access-control-sso-s3idc-howitworks"></a>

要将应用程序与 Amazon S3 访问权限管控集成，请执行以下操作：
+ 首先，使用 AWS 管理控制台或 AWS CLI 将 Amazon Redshift 配置为与 Amazon S3 访问权限管控集成。
+ 接下来，具有 IdC 管理员权限的用户使用 Amazon S3 访问权限管控服务，向特定 IdC 用户/组授予对 Amazon S3 存储桶或前缀的访问权限。有关更多信息，请参阅[在 S3 访问权限管控中处理授权](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-grants-grant.html)。
+ 当经过 Redshift 身份验证的 IdC 用户运行访问 S3 的查询（如 COPY、UNLOAD 或 Spectrum 操作）时，Amazon Redshift 会从 Amazon S3 访问权限管控服务中检索该 IdC 身份范围内的临时 S3 访问凭证。
+ 然后，Amazon Redshift 使用检索到的临时凭证，来访问该查询的经授权的 Amazon S3 位置。

## 设置与 Amazon S3 访问权限管控的集成
<a name="redshift-iam-access-control-sso-s3idc-setup"></a>

要为 Amazon Redshift 设置与 Amazon S3 访问权限管控的集成，请执行以下操作：

**Topics**
+ [使用 AWS 管理控制台设置与 Amazon S3 访问权限管控的集成](#redshift-iam-access-control-sso-s3idc-setup-console)
+ [使用 AWS CLI 启用与 Amazon S3 访问权限管控的集成](#redshift-iam-access-control-sso-s3idc-setup-cli)

### 使用 AWS 管理控制台设置与 Amazon S3 访问权限管控的集成
<a name="redshift-iam-access-control-sso-s3idc-setup-console"></a>

1. 打开 Amazon Redshift 控制台。

1. 从**集群**窗格中选择您的集群。

1. 在集群的详细信息页面的**身份提供者集成**部分，启用与 **S3 访问权限管控**服务的集成。
**注意**  
如果您未配置 IAM Identity Center，则不会显示**身份提供者集成**部分。有关更多信息，请参阅 [Enabling AWS IAM Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/get-set-up-for-idc.html)。

### 使用 AWS CLI 启用与 Amazon S3 访问权限管控的集成
<a name="redshift-iam-access-control-sso-s3idc-setup-cli"></a>

1. 要创建一个启用了 S3 集成的新 Amazon Redshift IdC 应用程序，请执行以下操作：

   ```
   aws redshift create-redshift-idc-application <other parameters> 
     --service-integrations '[ {"S3AccessGrants": [{"ReadWriteAccess": {"Authorization": "Enabled"}}]} ]'
   ```

1. 要修改现有应用程序以启用 S3 访问权限管控集成，请执行以下操作：

   ```
   aws redshift modify-redshift-idc-application <other parameters>
     --service-integrations '[ {"S3AccessGrants": [{"ReadWriteAccess": {"Authorization": "Enabled"}}]} ]'
   ```

1. 要修改现有应用程序以禁用 S3 访问权限管控集成，请执行以下操作：

   ```
   aws redshift modify-redshift-idc-application <other parameters>
     --service-integrations '[ {"S3AccessGrants": [{"ReadWriteAccess": {"Authorization": "Disabled"}}]} ]'
   ```

## 使用与 S3 访问权限管控的集成
<a name="redshift-iam-access-control-sso-s3idc-using"></a>

配置 S3 访问权限管控集成后，访问 S3 数据的查询（例如 `COPY`、`UNLOAD` 或 Spectrum 查询）将使用 IdC 身份进行授权。未使用 IdC 进行身份验证的用户也可以运行这些查询，但是这些用户账户无法利用 IdC 提供的集中式管理。

以下示例显示了通过 S3 访问权限管控集成运行的查询：

```
COPY table FROM 's3://mybucket/data';  // -- Redshift uses IdC identity 
UNLOAD ('SELECT * FROM table') TO 's3://mybucket/unloaded/'    // -- Redshift uses IdC identity
```