

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

# 使用啟用 IAM Identity Center 的 Athena 工作群組
<a name="workgroups-identity-center"></a>

[信任的身分傳播](https://docs.aws.amazon.com//singlesignon/latest/userguide/trustedidentitypropagation-overview.html)是一項 AWS IAM Identity Center 功能，連線的管理員 AWS 服務 可以使用此功能來授予和稽核服務資料的存取權。存取此資料是根據使用者屬性，例如群組關聯。設定信任的身分傳播需要連線的管理員 AWS 服務 與 IAM Identity Center 管理員之間的協同合作。如需詳細資訊，請參閱[先決條件和考量](https://docs.aws.amazon.com//singlesignon/latest/userguide/trustedidentitypropagation-overall-prerequisites.html)。

使用 [IAM Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/what-is.html)，您可管理員工身分 (也稱為員工使用者) 的登入安全性。IAM Identity Center 提供一個位置，您可以在其中建立或連接人力資源使用者，並集中管理其所有 AWS 帳戶和應用程式的存取權。您可使用多帳戶許可，將對 AWS 帳戶的存取權指派給這些使用者。您可使用應用程式指派功能，來指派使用者對啟用 IAM Identity Center 的應用程式、雲端應用程式和客戶安全性聲明標記語言 (SAML 2.0) 應用程式的存取權。如需詳細資訊，請參閱《AWS IAM Identity Center 使用者指南》**中的[跨應用程式的受信任身分傳播](https://docs.aws.amazon.com/singlesignon/latest/userguide/trustedidentitypropagation.html)。

EMR Studio 和 SageMaker Unified Studio 均提供 Athena SQL 對可信身分傳播的支援。每個平台都為搭配使用 TIP 和 Athena 提供了特定介面。

在 EMR Studio 中搭配使用 Athena SQL 與 IAM Identity Center 身分時，您有兩個工作群組選項：
+ **一般工作群組** – 不需要使用者/群組指派。
+ **啟用 IAM Identity Center 的工作群組** – 需要透過 IAM Identity Center 主控台或 API 指派使用者/群組。

對於這兩個選項，您可以在已啟用 IAM Identity Center 的 EMR Studio 中使用 Athena SQL 介面來執行查詢。

## 考量和限制
<a name="workgroups-identity-center-considerations-and-limitations"></a>

當您搭配使用可信身分傳播與 Amazon Athena 時，請考慮下列幾點：
+ 建立工作群組之後，無法變更工作群組的身分驗證方法。
  + 無法修改現有的 Athena SQL 工作群組來支援啟用了 IAM Identity Center 的工作群組。現有的 Athena SQL 工作群組可以將身分資訊傳播到下游服務。
  + 無法修改啟用了 IAM Identity Center 的工作群組，來支援資源層級 IAM 許可或以 Identity Center 為基礎的 IAM 政策。
+ 若要存取啟用可信身分傳播的工作群組，IAM Identity Center 使用者必須指派給 Athena [GetWorkGroup](https://docs.aws.amazon.com/athena/latest/APIReference/API_GetWorkGroup.html) API 動作回應所傳回的 `IdentityCenterApplicationArn`。
+ Amazon S3 存取授權必須設定為使用可信身分傳播身分。如需詳細資訊，請參閱《Amazon S3 使用者指南》**中的 [S3 Access Grants 和公司目錄身分](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-grants-directory-ids.html)。
+ 啟用 IAM Identity Center 的 Athena 工作群組需要將 Lake Formation 設定為使用 IAM Identity Center 身分。如需組態資訊，請參閱《AWS Lake Formation 開發人員指南》**中的[整合 IAM Identity Center](https://docs.aws.amazon.com/lake-formation/latest/dg/identity-center-integration.html)。
+ 依預設，在啟用 IAM Identity Center 的工作群組中，查詢會在 30 分鐘後逾時。您可請求增加查詢逾時，但在可信身分傳播工作群組中，可執行的查詢上限為一小時。
+ 在可信身分傳播工作群組中，使用者或群組權利變更可能需要最多一小時才會生效。
+ 使用可信身分傳播的 Athena 工作群組中的查詢，無法直接從 Athena 主控台執行。必須從啟用了 IAM Identity Center 的 EMR Studio 中的 Athena 介面執行。如需有關在 EMR Studio 中使用 Athena 的詳細資訊，請參閱《Amazon EMR 管理指南》**中的在 [ EMR Studio 中使用 Amazon Athena SQL 編輯器](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-studio-athena.html)。
+ 受信任身分傳播與下列 Athena 功能不相容。
  + 啟用 IAM Identity Center 的工作群組的 `aws:CalledVia` 內容索引鍵。
  + Athena for Spark 工作群組。
  + 對 Athena API 的聯合存取。
  + 使用 Lake Formation 以及 Athena JDBC 和 ODBC 驅動程式對 Athena 進行聯合存取。
+ 您只能在下列情況下搭配 Athena 使用受信任身分傳播 AWS 區域：
  + `us-east-2` – 美國東部 (俄亥俄)
  + `us-east-1` – 美國東部 (維吉尼亞北部)
  + `us-west-1` – 美國西部 (加利佛尼亞北部)
  + `us-west-2` – 美國西部 (奧勒岡)
  + `af-south-1` – 非洲 (開普敦)
  + `ap-east-1` – 亞太區域 (香港)
  + `ap-southeast-3` – 亞太區域 (雅加達)
  + `ap-south-1` – 亞太區域 (孟買)
  + `ap-northeast-3` – 亞太區域 (大阪)
  + `ap-northeast-2` – 亞太區域 (首爾)
  + `ap-southeast-1` – 亞太區域 (新加坡)
  + `ap-southeast-2` – 亞太區域 (雪梨)
  + `ap-northeast-1` – 亞太區域 (東京)
  + `ca-central-1` – 加拿大 (中部)
  + `eu-central-1` – 歐洲 (法蘭克福)
  + `eu-central-2` – 歐洲 (蘇黎世)
  + `eu-west-1` – 歐洲 (愛爾蘭)
  + `eu-west-2` – 歐洲 (倫敦)
  + `eu-south-1` – 歐洲 (米蘭)
  + `eu-west-3` – 歐洲 (巴黎)
  + `eu-north-1` – 歐洲 (斯德哥爾摩)
  + `me-south-1` – 中東 (巴林)
  + `sa-east-1` – 南美洲 (聖保羅)

## 所需的許可
<a name="workgroups-identity-center-required-permissions"></a>

若管理員 IAM 使用者在 Athena 主控台中建立啟用了 IAM Identity Center 的工作群組，必須附加下列政策。
+ `AmazonAthenaFullAccess` 受管政策。如需詳細資訊，請參閱[AWS 受管政策：AmazonAthenaFullAccess](security-iam-awsmanpol.md#amazonathenafullaccess-managed-policy)。
+ 下列內嵌政策允許 IAM 和 IAM Identity Center 的以下動作：

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

****  

  ```
  { "Version":"2012-10-17",		 	 	  "Statement": [ { "Action": [ "iam:createRole",
      "iam:CreatePolicy", "iam:AttachRolePolicy", "iam:ListRoles", "identitystore:ListUsers",
      "identitystore:ListGroups", "identitystore:CreateUser", "identitystore:CreateGroup",
      "sso:ListInstances", "sso:CreateInstance", "sso:DeleteInstance", "sso:ListTrustedTokenIssuers",
      "sso:DescribeTrustedTokenIssuer", "sso:ListApplicationAssignments",
      "sso:DescribeRegisteredRegions", "sso:GetManagedApplicationInstance",
      "sso:GetSharedSsoConfiguration", "sso:PutApplicationAssignmentConfiguration",
      "sso:CreateApplication", "sso:DeleteApplication", "sso:PutApplicationGrant",
      "sso:PutApplicationAuthenticationMethod", "sso:PutApplicationAccessScope",
      "sso:ListDirectoryAssociations", "sso:CreateApplicationAssignment",
      "sso:DeleteApplicationAssignment", "organizations:ListDelegatedAdministrators",
      "organizations:DescribeAccount", "organizations:DescribeOrganization",
      "organizations:CreateOrganization", "sso-directory:SearchUsers", "sso-directory:SearchGroups",
      "sso-directory:CreateUser" ], "Effect": "Allow", "Resource": [ "*" ] }, { "Action": [
      "iam:PassRole" ], "Effect": "Allow", "Resource": [
          "arn:aws:iam::111122223333:role/service-role/AWSAthenaSQLRole-*"
      ] } ] }
  ```

------

## 建立啟用 IAM Identity Center 的 Athena 工作群組
<a name="workgroups-identity-center-creating-an-identity-center-enabled-athena-workgroup"></a>

下列程序顯示與建立啟用 IAM Identity Center 的 Athena 工作群組相關的步驟和選項。如需 Athena 工作群組可用的其他組態選項的說明，請參閱 [建立工作群組](creating-workgroups.md)。

**在 Athena 主控台中建立啟用 SSO 的工作群組**

1. 前往 [https://console.aws.amazon.com/athena/](https://console.aws.amazon.com/athena/home) 開啟 Athena 主控台。

1. 在 Athena 主控台導覽窗格中，選擇 **Workgroups** (工作群組)。

1. 在 **Workgroups** (工作群組) 頁面中，請選擇 **Create workgroup** (建立工作群組)。

1. 在**建立工作群組**頁面上，針對**工作群組名稱**，輸入工作群組的名稱。

1. 針對**分析引擎**，使用 **Athena SQL** 預設值。

1. 針對**身分驗證**，選擇 **IAM Identity Center**。

1. 針對 **IAM Identity Center 存取的服務角色**，選擇現有的服務角色，或建立新的服務角色。

   Athena 需要許可，才能代表您存取 IAM Identity Center。Athena 需要服務角色，才能執行此操作。服務角色是您管理的 IAM 角色，可授權 AWS 服務代表您存取其他 AWS 服務。若要查詢聯合目錄或執行 UDF，請使用對應的 Lambda 許可更新服務角色。如需詳細資訊，請參閱《*IAM 使用者指南*》中的[建立角色以將許可委派給 AWS 服務](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html)。

1. 展開**查詢結果組態**，然後針對**查詢結果的位置**輸入或選擇 Amazon S3 路徑。

1. (選用) 選擇**加密查詢結果**。依預設，可支援 SSE-S3。若要搭配查詢結果位置使用 SSE-KMS 和 CSE-KMS，請從 Amazon S3 存取授權向 **IAM Identity Center 的服務角色**提供授權。如需詳細資訊，請參閱[範例角色政策](#workgroups-identity-center-access-grant-location-sample-role-policy)。

1. (選用) 選擇**建立以使用者身分為基礎的 S3 字首**。

   當您建立啟用 IAM Identity Center 的工作群組時，預設會選取**啟用 S3 Access Grants** 選項。您可使用 Amazon S3 Access Grants，來控制對 Amazon S3 中 Athena 查詢結果位置 (字首) 的存取權。如需有關 Amazon S3 Access Grants 的詳細資訊，請參閱[使用 Amazon S3 Access Grants 管理存取權](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-grants.html)。

   在使用 IAM Identity Center 身分驗證的 Athena 工作群組中，您可建立由 Amazon S3 Access Grants 管控的以身分為基礎的查詢結果位置。藉助這些以使用者身分為基礎的 Amazon S3 字首，Athena 工作群組中的使用者可將查詢結果與相同工作群組中的其他使用者隔離。

   啟用使用者字首選項時，Athena 會將使用者 ID 做為 Amazon S3 路徑字首附加至工作群組的查詢結果輸出位置 (例如 `s3://amzn-s3-demo-bucket/${user_id}`)。若要使用此功能，您必須將 Access Grants 設定為僅允許使用者存取具有 `user_id` 字首的位置。如需限制存取 Athena 查詢結果的 Amazon S3 存取授權位置角色政策的範例，請參閱 [範例角色政策](#workgroups-identity-center-access-grant-location-sample-role-policy)。
**注意**  
選取使用者身分 S3 字首選項，會自動啟用工作群組的「覆寫用戶端設定」選項，如下一個步驟所述。「覆寫用戶端設定」選項是使用者身分字首功能的必要條件。

1. 展開**設定**，然後確認選取**覆寫用戶端設定**。

   如果選取**覆寫用戶端設定**，則會在工作群組層級，強制工作群組中所有用戶端執行工作群組設定。如需詳細資訊，請參閱[Override client-side settings (覆寫用戶端設定)](workgroups-settings-override.md)。

1. (選用) 如 [建立工作群組](creating-workgroups.md) 中所述，進行需要的任何其他組態設定。

1. 選擇**建立工作群組**。

1. 使用 Athena 主控台的**工作群組**區段，將 IAM Identity Center 目錄中的使用者或群組指派給啟用 IAM Identity Center 的 Athena 工作群組。

## 範例角色政策
<a name="workgroups-identity-center-access-grant-location-sample-role-policy"></a>

下列範例說明要連接至 Amazon S3 存取授權位置的角色的政策，以限制對 Athena 查詢結果的存取權。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Action": [
                "s3:*"
            ],
            "Condition": {
                "ArnNotEquals": {
                    "s3:AccessGrantsInstanceArn": "arn:aws:s3:us-east-1:111122223333:access-grants/default"
                },
                "StringNotEquals": {
                    "aws:ResourceAccount": "111122223333"
                }
            },
            "Effect": "Deny",
            "Resource": "*",
            "Sid": "ExplicitDenyS3"
        },
        {
            "Action": [
                "kms:*"
            ],
            "Effect": "Deny",
            "NotResource": "arn:aws:kms:us-east-1:111122223333:key/${keyid}",
            "Sid": "ExplictDenyKMS"
        },
        {
            "Action": [
                "s3:ListMultipartUploadParts",
                "s3:GetObject"
            ],
            "Condition": {
                "ArnEquals": {
                    "s3:AccessGrantsInstanceArn": "arn:aws:s3:us-east-1:111122223333:access-grants/default"
                },
                "StringEquals": {
                    "aws:ResourceAccount": "111122223333"
                }
            },
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::ATHENA-QUERY-RESULT-LOCATION/${identitystore:UserId}/*",
            "Sid": "ObjectLevelReadPermissions"
        },
        {
            "Action": [
                "s3:PutObject",
                "s3:AbortMultipartUpload"
            ],
            "Condition": {
                "ArnEquals": {
                    "s3:AccessGrantsInstanceArn": "arn:aws:s3:us-east-1:111122223333:access-grants/default"
                },
                "StringEquals": {
                "aws:ResourceAccount": "111122223333"
                }
            },
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::ATHENA-QUERY-RESULT-LOCATION/${identitystore:UserId}/*",
            "Sid": "ObjectLevelWritePermissions"
        },
        {
            "Action": "s3:ListBucket",
            "Condition": {
                "ArnEquals": {
                    "s3:AccessGrantsInstanceArn": "arn:aws:s3:us-east-1:111122223333:access-grants/default"
                },
                "StringEquals": {
                    "aws:ResourceAccount": "111122223333"
                },
                "StringLikeIfExists": {
                    "s3:prefix": [
                        "${identitystore:UserId}",
                        "${identitystore:UserId}/*"
                    ]
                }
            },
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::ATHENA-QUERY-RESULT-LOCATION",
            "Sid": "BucketLevelReadPermissions"
        },
        {
            "Action": [
                "kms:GenerateDataKey",
                "kms:Decrypt"
            ],
            "Effect": "Allow",
            "Resource": "arn:aws:kms:us-east-1:111122223333:key/${keyid}",
            "Sid": "KMSPermissions"
        }
    ]
}
```

------