

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

# 设置 Amazon EMR Studio 的可信身份传播
<a name="setting-up-tip-emr"></a>

以下过程将引导您设置 Amazon EMR Studio，以实现对 Amazon Athena 工作组或运行 Apache Spark 的 Amazon EMR 集群执行查询时的可信身份传播。

## 先决条件
<a name="setting-up-tip-emr-prereqs"></a>

在开始本教程之前，您需要设置以下方面：

1. [启用 IAM 身份中心](enable-identity-center.md)。建议使用[组织实例](organization-instances-identity-center.md)。有关更多信息，请参阅 [先决条件和注意事项](trustedidentitypropagation-overall-prerequisites.md)。

1. [将身份源中的用户和组配置到 IAM Identity Center](tutorials.md)。

要完成 Amazon EMR Studio 的可信身份传播配置，EMR Studio 管理员必须执行以下步骤。

## 步骤 1：为 EMR Studio 创建所需的 IAM 角色
<a name="setting-up-tip-emr-step1"></a>

本步骤中，Amazon EMR Studio 管理员需为 EMR Studio 创建 IAM 服务角色和 IAM 用户角色。

1. **[创建 EMR Studio 服务角色](https://docs.aws.amazon.com//emr/latest/ManagementGuide/emr-studio-service-role.html)** - EMR Studio 将通过该 IAM 角色安全管理工作区和笔记本、连接集群并处理数据交互。

   1. 导航到 IAM 控制台 ([https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/)) 并创建 IAM 角色。

   1. 选择 **AWS 服务** 作为可信实体，然后选择 **Amazon EMR**。附加以下策略以定义该角色的权限和信任关系。

      要使用这些政策，请将示例策略*italicized placeholder text*中的替换为您自己的信息。有关详细操作指引，请参阅[创建策略](https://docs.aws.amazon.com//IAM/latest/UserGuide/access_policies_create.html)或[编辑策略](https://docs.aws.amazon.com//IAM/latest/UserGuide/access_policies_manage-edit.html)。

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

****  

      ```
      {
          "Version":"2012-10-17",		 	 	 
          "Statement": [
              {
                  "Sid": "ObjectActions",
                  "Effect": "Allow",
                  "Action": [
                      "s3:PutObject",
                      "s3:GetObject",
                      "s3:DeleteObject"
                  ],
                  "Resource": [
                      "arn:aws:s3:::Your-S3-Bucket-For-EMR-Studio/*"
                  ],
                  "Condition": {
                      "StringEquals": {
                          "aws:ResourceAccount": "Your-AWS-Account-ID"
                      }
                  }
              },
              {
                  "Sid": "BucketActions",
                  "Effect": "Allow",
                  "Action": [
                      "s3:ListBucket",
                      "s3:GetEncryptionConfiguration"
                  ],
                  "Resource": [
                      "arn:aws:s3:::Your-S3-Bucket-For-EMR-Studio"
                  ],
                  "Condition": {
                      "StringEquals": {
                          "aws:ResourceAccount": "Your-AWS-Account-ID"
                      }
                  }
              }
          ]
      }
      ```

------

      有关服务角色的所有权限参考，请参阅 [EMR Studio 服务角色权限](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-studio-service-role.html#emr-studio-service-role-permissions-table)。

1. **[创建用于 IAM Identity Center 身份验证的 EMR Studio 用户角色](https://docs.aws.amazon.com//emr/latest/ManagementGuide/emr-studio-user-permissions.html#emr-studio-create-user-role)** - 当用户通过 IAM Identity Center 登录以管理工作区、EMR 集群、作业和 Git 代码库时，EMR Studio 将使用该角色。**该角色用于启动可信身份传播工作流**。
**注意**  
EMR Studio 用户角色不需要包含访问目录中 AWS Glue 表的 Amazon S3 位置的权限。 AWS Lake Formation 权限和注册的湖泊位置将用于获得临时权限。

   以下示例策略可用于允许 EMR Studio 用户通过 Athena 工作组运行查询的角色。

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Sid": "AllowDefaultEC2SecurityGroupsCreationInVPCWithEMRTags",
               "Effect": "Allow",
               "Action": [
                   "ec2:CreateSecurityGroup"
               ],
               "Resource": [
                   "arn:aws:ec2:*:*:vpc/*"
               ],
               "Condition": {
                   "StringEquals": {
                       "aws:ResourceTag/for-use-with-amazon-emr-managed-policies": "true"
                   }
               }
           },
           {
               "Sid": "AllowAddingEMRTagsDuringDefaultSecurityGroupCreation",
               "Effect": "Allow",
               "Action": [
                   "ec2:CreateTags"
               ],
               "Resource": "arn:aws:ec2:*:*:security-group/*",
               "Condition": {
                   "StringEquals": {
                       "aws:RequestTag/for-use-with-amazon-emr-managed-policies": "true",
                       "ec2:CreateAction": "CreateSecurityGroup"
                   }
               }
           },
           {
               "Sid": "AllowSecretManagerListSecrets",
               "Action": [
                   "secretsmanager:ListSecrets"
               ],
               "Resource": "*",
               "Effect": "Allow"
           },
           {
               "Sid": "AllowSecretCreationWithEMRTagsAndEMRStudioPrefix",
               "Effect": "Allow",
               "Action": "secretsmanager:CreateSecret",
               "Resource": "arn:aws:secretsmanager:*:*:secret:emr-studio-*",
               "Condition": {
                   "StringEquals": {
                       "aws:RequestTag/for-use-with-amazon-emr-managed-policies": "true"
                   }
               }
           },
           {
               "Sid": "AllowAddingTagsOnSecretsWithEMRStudioPrefix",
               "Effect": "Allow",
               "Action": "secretsmanager:TagResource",
               "Resource": "arn:aws:secretsmanager:*:*:secret:emr-studio-*"
           },
           {
               "Sid": "AllowPassingServiceRoleForWorkspaceCreation",
               "Action": "iam:PassRole",
               "Resource": [
                   "arn:aws:iam::111122223333:role/service-role/AmazonEMRStudio_ServiceRole_Name"
               ],
               "Effect": "Allow"
           },
           {
               "Sid": "AllowS3ListAndLocationPermissions",
               "Action": [
                   "s3:ListAllMyBuckets",
                   "s3:ListBucket",
                   "s3:GetBucketLocation"
               ],
               "Resource": "arn:aws:s3:::*",
               "Effect": "Allow"
           },
           {
               "Sid": "AllowS3ReadOnlyAccessToLogs",
               "Action": [
                   "s3:GetObject"
               ],
               "Resource": [
                   "arn:aws:s3:::aws-logs-Your-AWS-Account-ID-Region/elasticmapreduce/*"
               ],
               "Effect": "Allow"
           },
           {
               "Sid": "AllowAthenaQueryExecutions",
               "Effect": "Allow",
               "Action": [
                   "athena:StartQueryExecution",
                   "athena:GetQueryExecution",
                   "athena:GetQueryResults",
                   "athena:StopQueryExecution",
                   "athena:ListQueryExecutions",
                   "athena:GetQueryResultsStream",
                   "athena:ListWorkGroups",
                   "athena:GetWorkGroup",
                   "athena:CreatePreparedStatement",
                   "athena:GetPreparedStatement",
                   "athena:DeletePreparedStatement"
               ],
               "Resource": "*"
           },
           {
               "Sid": "AllowGlueSchemaManipulations",
               "Effect": "Allow",
               "Action": [
                   "glue:GetDatabase",
                   "glue:GetDatabases",
                   "glue:GetTable",
                   "glue:GetTables",
                   "glue:GetPartition",
                   "glue:GetPartitions"
               ],
               "Resource": "*"
           },
           {
               "Sid": "AllowQueryEditorToAccessWorkGroup",
               "Effect": "Allow",
               "Action": "athena:GetWorkGroup",
               "Resource": "arn:aws:athena:*:111122223333:workgroup*"
           },
           {
               "Sid": "AllowConfigurationForWorkspaceCollaboration",
               "Action": [
                   "elasticmapreduce:UpdateEditor",
                   "elasticmapreduce:PutWorkspaceAccess",
                   "elasticmapreduce:DeleteWorkspaceAccess",
                   "elasticmapreduce:ListWorkspaceAccessIdentities"
               ],
               "Resource": "*",
               "Effect": "Allow",
               "Condition": {
                   "StringEquals": {
                       "elasticmapreduce:ResourceTag/creatorUserId": "${aws:userId}"
                   }
               }
           },
           {
               "Sid": "DescribeNetwork",
               "Effect": "Allow",
               "Action": [
                   "ec2:DescribeVpcs",
                   "ec2:DescribeSubnets",
                   "ec2:DescribeSecurityGroups"
               ],
               "Resource": "*"
           },
           {
               "Sid": "ListIAMRoles",
               "Effect": "Allow",
               "Action": [
                   "iam:ListRoles"
               ],
               "Resource": "*"
           },
           {
               "Sid": "AssumeRole",
               "Effect": "Allow",
               "Action": [
                   "sts:AssumeRole"
               ],
               "Resource": "*"
           }
       ]
   }
   ```

------

   以下信任策略允许 EMR Studio 扮演该角色：
**注意**  
使用 EMR Studio 工作区和 EMR 笔记本需额外配置权限。有关更多信息，请参阅[为 EMR Studio 用户创建权限策略](https://docs.aws.amazon.com//emr/latest/ManagementGuide/emr-studio-user-permissions.html#emr-studio-permissions-policies)。

**您可通过以下链接获取更多信息：**
   + [使用客户管理型策略定义自定义 IAM 权限](https://docs.aws.amazon.com//IAM/latest/UserGuide/access_policies_create.html)
   + [EMR Studio 服务角色权限](https://docs.aws.amazon.com//emr/latest/ManagementGuide/emr-studio-service-role.html#emr-studio-service-role-permissions-table)

## 步骤 2：创建并配置 EMR Studio
<a name="setting-up-tip-emr-step2"></a>

本步骤中，您将在 EMR Studio 控制台创建 Amazon EMR Studio，并使用在 [步骤 1：为 EMR Studio 创建所需的 IAM 角色步骤 2：创建并配置 EMR Studio](#setting-up-tip-emr-step1) 中创建的 IAM 角色。

1. 访问 EMR Studio 控制台，选择**创建 Studio** 并选择**自定义设置**选项。您可以创建新的 S3 存储桶或使用现有存储桶。您可勾选**使用自己的 KMS 密钥加密工作区文件**选项。有关更多信息，请参阅 [AWS Key Management Service](https://docs.aws.amazon.com//kms/latest/developerguide/overview.html)。  
![\[步骤 1：在 EMR 控制台创建 EMR Studio。\]](http://docs.aws.amazon.com/zh_cn/singlesignon/latest/userguide/images/emr-tutorial-step-3.1.png)

1. 在**允许 Studio 访问您资源的服务角色**下，从下拉菜单中选择在 [步骤 1：为 EMR Studio 创建所需的 IAM 角色步骤 2：创建并配置 EMR Studio](#setting-up-tip-emr-step1) 中创建的服务角色。

1. 在**身份验证**下选择 **IAM Identity Center**。选择在 [步骤 1：为 EMR Studio 创建所需的 IAM 角色步骤 2：创建并配置 EMR Studio](#setting-up-tip-emr-step1) 中创建的用户角色。  
![\[步骤 3：在 EMR 控制台创建 EMR Studio，选择 IAM Identity Center 作为身份验证方式。\]](http://docs.aws.amazon.com/zh_cn/singlesignon/latest/userguide/images/emr-tutorial-step-3.3.png)

1. 勾选**可信身份传播**选项框。在应用程序访问部分选择**仅已分配的用户和组**，这样仅授权的用户和组可访问该 Studio。

1. *（可选）*– 如果您将该 Studio 与 EMR 集群配合使用，可配置 VPC 和子网。  
![\[步骤 4：在 EMR 控制台创建 EMR Studio，配置网络和安全设置。\]](http://docs.aws.amazon.com/zh_cn/singlesignon/latest/userguide/images/emr-tutorial-step-3.4.png)

1. 审核所有详细信息并选择**创建 Studio**。

1. 配置 Athen WorkGroup a 或 EMR 集群后，请登录 Studio 的 URL，以：

   1. 通过查询编辑器运行 Athena 查询。

   1. 在工作区中通过 Jupyter Notebook 运行 Spark 作业。