

# AWS Glue ETL 中的可信身份传播入门
<a name="security-trusted-identity-propagation-getting-started"></a>

本节的内容有助您配置使用交互式会话的 AWS Glue 应用程序，从而与 IAM Identity Center 集成并启用[可信身份传播](https://docs.aws.amazon.com/singlesignon/latest/userguide/trustedidentitypropagation-overview.html)。

## 先决条件
<a name="security-trusted-identity-propagation-prerequisites"></a>
+ 在要创建启用可信身份传播的 AWS Glue 交互式会话的 AWS 区域中有一个 Identity Center 实例。对于任何 AWS 账户而言，Identity Center 实例只能存在于单个区域中。有关更多信息，请参阅 [Enable IAM Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/get-started-enable-identity-center.html) 以及 [provision the users and groups from your source of identities into IAM Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/tutorials.html)。
+ 为交互式工作负载将与之交互的下游服务（例如 Lake Formation 或 Amazon S3 访问权限管控或 Amazon Redshift 集群）启用可信身份传播，以便访问数据。

## 将 AWS Glue ETL 连接到 IAM Identity Center 所需的权限
<a name="security-trusted-identity-propagation-permissions"></a>

**创建一个 IAM 角色**  
创建 IAM Identity Center 连接的角色需要具有在 AWS Glue 和 IAM Identity Center 中创建和修改应用程序配置的权限，如以下内联策略所示。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "glue:CreateGlueIdentityCenterConfiguration",
                "sso:CreateApplication",
                "sso:PutApplicationAssignmentConfiguration",
                "sso:PutApplicationAuthenticationMethod",
                "sso:PutApplicationGrant",
                "sso:PutApplicationAccessScope",
                "sso:ListInstances"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
```

------

以下内联策略包含查看、更新和删除 AWS Glue 与 IAM Identity Center 集成的属性所需的特定权限。

使用以下内联策略允许 IAM 角色查看 AWS Glue 与 IAM Identity Center 的集成。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "glue:GetGlueIdentityCenterConfiguration"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
```

------

使用以下内联策略允许 IAM 角色更新 AWS Glue 与 IAM Identity Center 的集成。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "glue:UpdateGlueIdentityCenterConfiguration",
                "sso:PutApplicationAccessScope",
                "sso:DeleteApplicationAccessScope"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
```

------

使用以下内联策略允许 IAM 角色删除 AWS Glue 与 IAM Identity Center 的集成。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "glue:DeleteGlueIdentityCenterConfiguration",
                "sso:DeleteApplication"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
```

------

### 权限描述
<a name="security-trusted-identity-propagation-permissions-description"></a>
+ `glue:CreateGlueIdentityCenterConfiguration`：授予创建 AWS Glue IdC 配置的权限。
+ `glue:GetGlueIdentityCenterConfiguration`：授予获取现有 IdC 配置的权限。
+ `glue:DeleteGlueIdentityCenterConfiguration`：授予删除现有 AWS Glue IdC 配置的权限。
+ `glue:UpdateGlueIdentityCenterConfiguration`：授予更新现有 AWS Glue IdC 配置的权限。
+ `sso:CreateApplication`：授予创建 AWS Glue 托管式 IAM Identity Center 应用程序的权限。
+ `sso:DescribeApplication`：授予描述 AWS Glue 托管式 IAM Identity Center 应用程序的权限。
+ `sso:DeleteApplication`：授予删除 AWS Glue 托管式 IAM Identity Center 应用程序的权限。
+ `sso:UpdateApplication`：授予更新 AWS Glue 托管式 IAM Identity Center 应用程序的权限。
+ `sso:PutApplicationGrant`：授予在 IdC 应用程序上应用 token-exchange、introspectToken、refreshToken 和 RevokeToken 授权的权限。
+ `sso:PutApplicationAuthenticationMethod`：授予在 AWS Glue 托管式 IdC 应用程序上放置 authenticationMethod 的权限，以便 AWS Glue 服务主体能够与 IdC 应用程序交互。
+ `sso:PutApplicationAccessScope`：授予在 AWS Glue 托管式 IdC 应用程序上添加或更新授权下游服务作用域列表的权限。
+ `sso:DeleteApplicationAccessScope`：授予在为 AWS Glue 托管式 IdC 应用程序移除某个作用域时授予删除下游作用域的权限。
+ `sso:PutApplicationAssignmentConfiguration`：授予在 IdC 应用程序上设定“User-assignment-not-required”设置的权限。
+ `sso:ListInstances`：授予列出实例和验证您在 identity-center-configuration 参数中指定的 IdC InstanceArn 的权限。

## 将 AWS Glue 连接到 IAM Identity Center
<a name="security-trusted-identity-propagation-connecting"></a>

将 AWS Glue 连接到 IAM Identity Center 时，系统会为每个账户创建一个单例托管式 IdC 应用程序。以下示例演示了如何将 AWS Glue 连接到 IAM Identy Center：

```
aws glue create-glue-identity-center-configuration \
--instance-arn arn:aws:sso:::instance/ssoins-123456789 \
--scopes '["s3:access_grants:read_write", "redshift:connect","lakeformation:query"]'
```

要更新托管式应用程序的作用域（通常是为了传播到更多下游服务），可以使用：

```
aws glue update-glue-identity-center-configuration \
--scopes '["s3:access_grants:read_write", "redshift:connect","lakeformation:query"]'
```

Scopes 参数是可选的，如果未提供此参数，则将会添加所有作用域。支持的值为 `s3:access_grants:read_write`、`redshift:connect` 和 `lakeformation:query`。

要获取配置详细信息，可以使用：

```
aws glue get-glue-identity-center-configuration
```

您可以使用以下命令删除 AWS Glue 与 IAM Identity Center 之间的连接：

```
aws glue delete-glue-identity-center-configuration
```

**注意**  
AWS Glue 会在您的账户中创建一个服务托管式 Identity Center 应用程序以供服务使用，从而对下游服务进行身份验证和身份传播。您账户中的所有可信身份传播会话都会共享 AWS Glue 创建的托管式 Identity Center 应用程序。  
**警告：**请勿手动修改托管式 Identity Center 应用程序的设置。任何更改都可能影响账户中所有启用可信身份传播的 AWS Glue 交互式会话。

## 创建启用可信身份传播的 AWS Glue 交互式会话
<a name="security-trusted-identity-propagation-creating-session"></a>

将 AWS Glue 连接到 IAM Identity Center 后，您可以使用[身份增强型角色凭证](https://docs.aws.amazon.com/singlesignon/latest/userguide/trustedidentitypropagation-identity-enhanced-iam-role-sessions.html)来创建 AWS Glue 交互式会话。创建 5.0 AWS Glue 会话时无需传递其他参数。由于 AWS Glue 已连接到 IAM Identity Center，如果 AWS Glue 检测到身份增强型角色凭证，则会自动将身份信息传播到您的语句中将会调用的下游服务。但是，会话的运行时角色需要具有如下所示的 `sts:SetContext` 权限。

**传播身份所需的运行时角色权限**  
 由于 AWS Glue 会话使用[身份增强型凭证](https://docs.aws.amazon.com/singlesignon/latest/userguide/trustedidentitypropagation-identity-enhanced-iam-role-sessions.html)将身份传播到下游 AWS 服务，因此其运行时角色的信任策略需要获得额外的权限 `sts:SetContext`，才能允许将身份传播到下游服务（例如 Amazon S3 访问权限管控、Lake Formation 和 Amazon Redshift）。要详细了解如何创建运行时角色，请参阅[设置运行时角色](https://docs.aws.amazon.com/glue/latest/dg/create-service-role.html)。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "glue.amazonaws.com"
      },
      "Action": [
        "sts:AssumeRole",
        "sts:SetContext"
      ]
    }
  ]
}
```

------

此外，运行时角色需要作业运行将会调用的下游 AWS 服务的权限，以便使用用户身份获取数据。请参阅以下链接，了解如何配置 Amazon S3 访问权限管控和 Lake Formation：
+ [将 Lake Formation 与 AWS Glue 结合使用](https://docs.aws.amazon.com/glue/latest/dg/security-lake-formation-fgac.html)
+ [将 Amazon S3 访问权限管控与 AWS Glue 结合使用](https://docs.aws.amazon.com/glue/latest/dg/security-s3-access-grants.html)