View a markdown version of this page

AWS IAM Identity Center OpenSearch UI 的身分驗證 - Amazon OpenSearch Service

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

AWS IAM Identity Center OpenSearch UI 的身分驗證

透過 AWS IAM Identity Center,您的團隊可以獲得以瀏覽器為基礎的單一登入體驗。您的使用者使用登入 AWS IAM Identity Center 資料登入,而不是產生預先簽章URLs。

先決條件

  • 同時具有 基礎和 IAM AWS IAM Identity Center 許可 AWS 的帳戶。如需所需許可的詳細資訊,請參閱OpenSearch UI 的 IAM 政策參考。

  • AWS IAM Identity Center 已在您的帳戶或組織中啟用 。請記下您擁有組織執行個體或帳戶執行個體,因為這會影響某些組態步驟。

  • 同時具有必要許可政策和信任政策的 IAM 角色。您可以在 中建立此角色步驟 2:建立 IAM 角色。

  • 區域中至少有一個 OpenSearch AWS 網域或無伺服器集合。

  • 至少有一個使用者或群組建立於其中 AWS IAM Identity Center。

使用客戶受管金鑰之組織執行個體的其他先決條件

如果您的組織執行個體 AWS IAM Identity Center 使用客戶受管金鑰進行靜態加密,您必須授予 OpenSearch UI 使用該金鑰解密身分資料的許可。如果沒有此許可,當 OpenSearch UI 驗證授權碼AccessDeniedException時,單一登入會失敗。

若要檢查您的執行個體是否使用客戶受管金鑰,請 AWS IAM Identity Center 開啟主控台,選擇設定,選擇管理索引標籤,然後檢閱用於加密靜態 IAM Identity Center 資料的金鑰。如果顯示客戶受管金鑰 ARN 而非 AWS 擁有的金鑰,請將下列陳述式新增至 AWS IAM Identity Center 已啟用 的管理帳戶中的金鑰政策。將 organization-id 取代為您的 AWS Organizations 組織 ID,格式為 o-xxxxxxxxxx。

{ "Sid": "Allow_AWS_app_admins_in_the_same_AWS_organization_to_use_the_KMS_key", "Effect": "Allow", "Principal": "*", "Action": [ "kms:Decrypt" ], "Resource": "*", "Condition": { "StringEquals": { "aws:PrincipalOrgID": "{{organization-id}}" }, "StringLike": { "kms:ViaService": [ "sso.*.amazonaws.com", "identitystore.*.amazonaws.com" ] } } }, { "Sid": "Allow_managed_apps_to_use_the_KMS_Key", "Effect": "Allow", "Principal": "*", "Action": [ "kms:Decrypt" ], "Resource": "*", "Condition": { "Bool": { "aws:PrincipalIsAWSService": "true" }, "StringLike": { "kms:ViaService": [ "sso.*.amazonaws.com", "identitystore.*.amazonaws.com" ] }, "StringEquals": { "aws:SourceOrgID": "{{organization-id}}" } } }

如需詳細資訊,請參閱AWS IAM Identity Center 《 使用者指南》中的客戶受管金鑰。

步驟 1:確認 AWS IAM Identity Center 已啟用

驗證 AWS IAM Identity Center 已啟用
  1. 開啟 AWS IAM Identity Center 主控台。

  2. 如果主控台顯示包含執行個體詳細資訊的儀表板, AWS IAM Identity Center 則會啟用 。請注意執行個體是組織執行個體還是帳戶執行個體。

  3. 如果主控台顯示設定頁面,請在繼續 AWS IAM Identity Center 之前啟用 。

組織執行個體可跨 AWS Organizations 組織中的所有帳戶運作,建議用於生產用途。帳戶執行個體的範圍為單一帳戶,適合測試和隔離設定。如果您的帳戶屬於其他人管理的組織,請詢問您的管理員是否 AWS IAM Identity Center 必須在組織層級啟用。

步驟 2:建立 IAM 角色

AWS IAM Identity Center 當使用者存取您的 OpenSearch UI 應用程式時, 會擔任 IAM 角色。該角色需要許可政策,其定義角色可執行的操作,以及信任政策,其定義誰可以擔任該角色。

使用下列許可政策。使用您的資訊取代預留位置的值。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "opensearch:ApplicationAccessAll", "Resource": "arn:aws:opensearch:{{region}}:{{account-id}}:application/*" } ] }

使用下列信任政策, AWS IAM Identity Center 允許 擔任角色:

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

若要建立角色並使用 連接許可政策 AWS CLI,請執行下列命令:

aws iam create-role \ --role-name OpenSearchUI-IDC-Role \ --assume-role-policy-document '{ "Version":"2012-10-17", "Statement":[{ "Effect":"Allow", "Principal":{"Service":"sso.amazonaws.com"}, "Action":"sts:AssumeRole" }] }' aws iam put-role-policy \ --role-name OpenSearchUI-IDC-Role \ --policy-name OpenSearchAppAccess \ --policy-document '{ "Version":"2012-10-17", "Statement":[{ "Effect":"Allow", "Action":"opensearch:ApplicationAccessAll", "Resource":"arn:aws:opensearch:{{region}}:{{account-id}}:application/*" }] }'

請記下 角色 ARN。您可以在下一個步驟中指定它。ARN 的格式為 arn:aws:iam::{{account-id}}:role/OpenSearchUI-IDC-Role。

步驟 3:建立 AWS IAM Identity Center 已啟用 的應用程式

開始建立應用程式
  1. 開啟 Amazon OpenSearch Service 主控台。

  2. 在導覽功能表中,選擇 OpenSearch UI (儀表板)。

  3. 選擇建立應用程式。

  4. 輸入應用程式的名稱。

  5. 新增至少一個資料來源,可以是 OpenSearch 網域或無伺服器集合。

繼續以相同的格式開啟單一登入並完成建立應用程式。

啟用 AWS IAM Identity Center 和建立應用程式
  1. 選取使用 IAM Identity Center 進行身分驗證核取方塊。

  2. 選取您在 中建立的 IAM 角色步驟 2:建立 IAM 角色。

  3. (選用) 設定儀表板管理員。

  4. 選擇建立。

若要使用 建立相同的應用程式 AWS CLI,請執行下列命令。使用您的資訊取代預留位置的值。

aws opensearch create-application \ --name "{{application-name}}" \ --iam-identity-center-options '{ "enabled": true, "iamRoleForIdentityCenterApplicationArn": "arn:aws:iam::{{account-id}}:role/OpenSearchUI-IDC-Role" }' \ --data-sources '[{ "dataSourceArn": "arn:aws:es:{{region}}:{{account-id}}:domain/{{domain-name}}" }]' \ --region {{region}}

步驟 4:在 中指派使用者 AWS IAM Identity Center

將使用者或群組指派給應用程式
  1. 開啟 AWS IAM Identity Center 主控台。

  2. 在導覽功能表中,選擇應用程式。

  3. 選擇 OpenSearch UI 自動註冊的應用程式。其名稱與您的 OpenSearch UI 應用程式名稱相符。

  4. 選擇指派使用者和群組。

  5. 選取需要存取的使用者或群組,然後選擇指派。

步驟 5:驗證設定

驗證設定
  1. 在 Amazon OpenSearch Service 主控台中,確認應用程式狀態為作用中,這表示應用程式已準備好可供使用。

  2. 確認應用程式詳細資訊頁面上已啟用使用 IAM Identity Center 進行身分驗證。

  3. 從應用程式詳細資訊頁面複製應用程式 URL。

  4. 在瀏覽器中開啟應用程式 URL。系統會將您重新導向至 AWS IAM Identity Center 登入頁面。

  5. 使用您的 AWS IAM Identity Center 登入資料登入。隨即顯示 OpenSearch UI 工作區選擇器。

以程式設計方式管理使用者和群組

當您建立 AWS IAM Identity Center 已啟用 的 OpenSearch UI 應用程式時,OpenSearch UI 會註冊 AWS IAM Identity Center 應用程式。您必須先將使用者指派給該應用程式,才能登入。有兩種不同的存取層級:

應用程式指派

控制誰可以登入 OpenSearch UI。您可以使用 sso-admin命令來管理它。

應用程式管理員

控制誰可以編輯或刪除應用程式並管理其工作區。您可以使用 來管理它aws opensearch update-application。如需應用程式管理員的詳細資訊,請參閱 管理應用程式管理員。

您需要三個識別符,才能管理指派。

識別符 如何取得
AWS IAM Identity Center 應用程式 ARN aws opensearch get-application,在 iamIdentityCenterOptions.iamIdentityCenterApplicationArn
身分存放區 ID aws sso-admin list-instances,在 Instances[0].IdentityStoreId
使用者或群組 ID aws identitystore list-users 或 aws identitystore list-groups

下列命令會依使用者的名稱尋找使用者,並依其顯示名稱尋找群組。將預留位置值取代為您自己的資訊:

aws identitystore list-users \ --identity-store-id {{identity-store-id}} \ --filters '[{"AttributePath":"UserName","AttributeValue":"{{user-name}}"}]' \ --region {{region}} \ --query 'Users[0].UserId' --output text aws identitystore list-groups \ --identity-store-id {{identity-store-id}} \ --filters '[{"AttributePath":"DisplayName","AttributeValue":"{{group-name}}"}]' \ --region {{region}} \ --query 'Groups[0].GroupId' --output text

下列命令會將使用者或群組指派給應用程式,並檢閱或移除指派。對於 群組,--principal-type請將 設定為 ,GROUP並使用您先前發現做為委託人 ID 的群組 ID:

aws sso-admin create-application-assignment \ --application-arn {{identity-center-application-arn}} \ --principal-id {{principal-id}} \ --principal-type USER \ --region {{region}} aws sso-admin list-application-assignments \ --application-arn {{identity-center-application-arn}} \ --region {{region}} aws sso-admin delete-application-assignment \ --application-arn {{identity-center-application-arn}} \ --principal-id {{principal-id}} \ --principal-type USER \ --region {{region}}

如果身分存放區中還沒有使用者或群組,請使用 aws identitystore create-user或 建立它aws identitystore create-group,並使用 新增成員aws identitystore create-group-membership。

下列 Python 程式碼範例會依使用者名稱查詢使用者,並使用適用於 Python 的 AWS SDK (Boto3) 將該使用者指派給應用程式:

import boto3 region = "{{region}}" app_id = "{{application-id}}" opensearch = boto3.client("opensearch", region_name=region) sso_admin = boto3.client("sso-admin", region_name=region) identity_store = boto3.client("identitystore", region_name=region) app = opensearch.get_application(id=app_id) idc_app_arn = app["iamIdentityCenterOptions"]["iamIdentityCenterApplicationArn"] identity_store_id = sso_admin.list_instances()["Instances"][0]["IdentityStoreId"] users = identity_store.list_users( IdentityStoreId=identity_store_id, Filters=[{"AttributePath": "UserName", "AttributeValue": "{{user-name}}"}], ) user_id = users["Users"][0]["UserId"] sso_admin.create_application_assignment( ApplicationArn=idc_app_arn, PrincipalId=user_id, PrincipalType="USER", )

對 AWS IAM Identity Center 身分驗證進行故障診斷

AWS IAM Identity Center 身分驗證問題通常來自省略 的信任政策sso.amazonaws.com、缺少必要動作的許可政策,或未指派給應用程式的使用者。下表列出常見的症狀、可能的原因,以及如何解決每個症狀。

徵狀 可能原因 Resolution
當您建立應用程式時, AWS IAM Identity Center 未啟用的訊息隨即出現 您的帳戶或組織中沒有執行個體 在 AWS IAM Identity Center 主控台 AWS IAM Identity Center 中啟用
單一登入重新導向,但傳回錯誤 角色信任政策不包含 sso.amazonaws.com 更新信任政策,如 中所述 步驟 2:建立 IAM 角色
登入成功,但使用者無法存取 使用者未指派給應用程式 在 AWS IAM Identity Center 主控台中指派使用者,如 中所述 步驟 4:在 中指派使用者 AWS IAM Identity Center
登入後存取遭拒 角色許可政策缺少必要的動作 確認角色具有存取資料來源的 opensearch:ApplicationAccessAll和 許可
應用程式顯示 AWS IAM Identity Center 為已啟用,但登入失敗 角色 ARN 不相符 確認應用程式設定中的角色 ARN 是具有正確信任和許可政策的角色
無法使用 建立應用程式 AWS IAM Identity Center AWS IAM Identity Center 缺少 許可 確認您的 IAM 主體具有 sso:CreateApplication、 sso:PutApplicationGrant和 iam:PassRole
出現登入頁面,但沒有使用者可以登入 中未指派任何使用者 AWS IAM Identity Center 在 AWS IAM Identity Center 主控台中將使用者指派給應用程式
登入失敗,並顯示無法驗證授權碼的訊息,或使用 AccessDeniedException AWS IAM Identity Center 使用不含必要金鑰政策的客戶受管金鑰 新增本主題先前所述的金鑰政策陳述式
使用者在指派之後不久就無法登入 指派尚未傳播 等待一到兩分鐘,然後再試一次
create-application-assignment 的 AccessDeniedException 缺少sso:CreateApplicationAssignment許可 新增 中列出的 AWS IAM Identity Center 許可 OpenSearch UI 的 IAM 政策參考
ConflictException 指派上的 已指派使用者或群組 使用 確認 list-application-assignments