

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

# 使用 Auth0 和 實作 Amazon WorkSpaces 的 SAML 2.Auth0驗證 AWS Managed Microsoft AD
<a name="implement-saml-authentication-for-amazon-workspaces-by-using-auth0-and-aws-managed-microsoft-ad"></a>

*Siva Vinnakota 和 Shantanu Padhye，Amazon Web Services*

## 總結
<a name="implement-saml-authentication-for-amazon-workspaces-by-using-auth0-and-aws-managed-microsoft-ad-summary"></a>

此模式會探索如何將 Auth0 與 整合 AWS Directory Service for Microsoft Active Directory ，為您的 Amazon WorkSpaces 環境建立強大的 SAML 2.0 身分驗證解決方案。它說明如何在這些項目之間建立聯合 AWS 服務 ，以啟用多重要素驗證 (MFA) 和自訂登入流程等進階功能，同時保留無縫桌面存取 AWS Managed Microsoft AD。無論您是只管理少數使用者還是數千個使用者，此整合都有助於為您的組織提供靈活性和安全性。此模式提供設定程序的步驟，讓您可以在自己的環境中實作此解決方案。

## 先決條件和限制
<a name="implement-saml-authentication-for-amazon-workspaces-by-using-auth0-and-aws-managed-microsoft-ad-prereqs"></a>

**先決條件 **
+ 作用中 AWS 帳戶
+ AWS Managed Microsoft AD
+ Amazon WorkSpaces Personal 中與 相關聯的佈建桌面 AWS Managed Microsoft AD
+ Amazon Elastic Compute Cloud (Amazon EC2) 執行個體
+ Auth0 帳戶

**限制**

有些 AWS 服務 完全無法使用 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)頁面，然後選擇服務的連結。

## Architecture
<a name="implement-saml-authentication-for-amazon-workspaces-by-using-auth0-and-aws-managed-microsoft-ad-architecture"></a>

WorkSpaces 用戶端應用程式的 SAML 2.0 身分驗證程序包含五個步驟，如下圖所示。這些步驟代表用於登入的典型工作流程。您可以在遵循此模式中的指示後，使用此分散式方法進行身分驗證，以協助提供結構化且安全的使用者存取方法。

![WorkSpaces 用戶端應用程式的 SAML 2.0 身分驗證程序工作流程。](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5a0f227c-c111-495b-9fde-98ae7832bb10/images/957b2a11-e898-4c4f-ae4e-c2e85bfa93a0.png)


 工作流程：

1. **註冊**。使用者啟動 WorkSpaces 的用戶端應用程式，並為其已啟用 SAML 的 WorkSpaces 目錄輸入 WorkSpaces 註冊碼。WorkSpaces 會將 Auth0 身分提供者 (IdP) URL 傳回至用戶端應用程式。

1. **登入。 **WorkSpaces 用戶端會使用 Auth0 URL 重新導向至使用者的 Web 瀏覽器。 使用者使用其使用者名稱和密碼進行身分驗證。Auth0 會將 SAML 聲明傳回至用戶端瀏覽器。SAML 聲明是可宣告使用者身分的加密字符。

1. **驗證**。用戶端瀏覽器會將 SAML 聲明發佈至 AWS 登入 端點以進行驗證。 AWS 登入 允許發起人擔任 AWS Identity and Access Management (IAM) 角色。這會傳回包含 IAM 角色臨時登入資料的字符。

1. **WorkSpaces 登入**。WorkSpaces 用戶端會將權杖呈現給 WorkSpaces 服務端點。WorkSpaces 會交換工作階段字符，並使用登入 URL 將工作階段字符傳回給 WorkSpaces 用戶端。當 WorkSpaces 用戶端載入登入頁面時，使用者名稱值會填入在 SAML 回應中傳遞`NameId`的值。

1. **串流**。使用者輸入其密碼並對 WorkSpaces 目錄進行身分驗證。身分驗證之後，WorkSpaces 會將權杖傳回給用戶端。用戶端會重新導向回 WorkSpaces 服務，並呈現權杖。這會代理 WorkSpaces 用戶端和 WorkSpace 之間的串流工作階段。

**注意**  
若要設定不需要密碼提示的無縫單一登入體驗，請參閱 [ WorkSpaces 文件中的憑證型身分驗證和 WorkSpaces Personal](https://docs.aws.amazon.com/workspaces/latest/adminguide/certificate-based-authentication.html)。 WorkSpaces 

## 工具
<a name="implement-saml-authentication-for-amazon-workspaces-by-using-auth0-and-aws-managed-microsoft-ad-tools"></a>

**AWS 服務**
+ [Amazon WorkSpaces](https://docs.aws.amazon.com/workspaces/latest/adminguide/amazon-workspaces.html) 是一項全受管的虛擬桌面基礎設施 (VDI) 服務，為使用者提供雲端型桌面，而無需購買和部署硬體或安裝複雜的軟體。
+ [AWS Directory Service for Microsoft Active Directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_microsoft_ad.html) 可讓您的目錄感知工作負載 AWS 和資源在 中使用 Microsoft Active Directory AWS 雲端。

**其他工具**
+ [Auth0](https://auth0.com/) 是一種身分驗證和授權平台，可協助您管理對應用程式的存取。

## 史詩
<a name="implement-saml-authentication-for-amazon-workspaces-by-using-auth0-and-aws-managed-microsoft-ad-epics"></a>

### 在 Auth0 中設定 Active Directory LDAP 連接器
<a name="configure-the-active-directory-ldap-connector-in-auth0"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 在 Auth0 中安裝 Active Directory LDAP 連接器 AWS Managed Microsoft AD。 | 1. 登入 Auth0 儀表板，然後選擇**身分驗證**、**企業**、**Active Directory/LDAP**。選擇**建立連線**。<br />2. 提供 Active Directory 連線的名稱，然後選擇**建立**。<br />3. 在**設定**索引標籤上，下載作業系統的代理程式。<br />安裝完成時，您的預設瀏覽器會顯示票證 URL 的提示。<br />4. 輸入佈建票證 URL，這對於您的連線字串應該是唯一的，然後選擇**繼續**。<br />5. 在 **AD LDAP 組態**對話方塊中，針對**使用者名稱和密碼******，輸入您的管理員登入資料，然後選擇**儲存**。<br />建立與 Auth0 的連線後，組態日誌會顯示所有檢查的報告狀態為 **OK**。 | 雲端管理員、雲端架構師 | 
| 在 Auth0 中建立應用程式，以產生 SAML 中繼資料清單檔案。 | 1. 登入 Auth0 儀表板，並遵循 [Auth0 文件中](https://auth0.com/docs/get-started/auth0-overview/create-applications)的指示建立新的應用程式。<br />2. 在 Auth0 儀表板上，選擇應用程式名稱以存取其組態設定。在 **AddOns** 索引標籤上，選擇 **SAML2 Web 應用程式**。<br />3. 在附加元件**的設定**索引標籤上，針對**應用程式回呼 URL**，輸入 **https://signin.aws.amazon.com/saml**。這是 SAML 字符將傳送`POST`請求的位置。<br />4. 在**設定**索引標籤**的設定**方塊中，以 JSON 格式貼上下列 SAML 組態碼：<pre>{<br />  "audience": "https://signin.aws.amazon.com/saml",<br />  "mappings": {<br />    "email": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/sAMAccountName",<br />    "name": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"<br />  },<br />  "createUpnClaim": false,<br />  "passthroughClaimsWithNoMapping": false,<br />  "mapUnknownClaimsAsIs": false,<br />  "mapIdentities": false,<br />  "nameIdentifierFormat": "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",<br />  "nameIdentifierProbes": [<br />    "http://schemas.auth0.com/sAMAccountName"<br />  ]<br />}</pre><br />5. 儲存，然後選擇**啟用**。<br />6. 選擇**用量**索引標籤，然後下載身分提供者的中繼資料資訊清單檔案。後續步驟需要此資訊。<br />7. 關閉 **SAML2 Web 應用程式**視窗。<br />8. 在應用程式畫面上，選擇**連線**。在**企業**下，選取正確的 Active Directory/LDAP 連接器並啟用它。 | 雲端管理員、雲端架構師 | 

### 在 IAM 中設定 SAML 2.0 的 IdP、角色和政策
<a name="set-up-idp-role-and-policy-for-saml-2-0-in-iam"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 IAM 中建立 SAML 2.0 IdP。 | 若要將 SAML 2.0 設定為 IdP，請遵循 IAM 文件中在 [IAM 中建立 SAML 身分提供者](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_saml.html)中所述的步驟。 | 雲端管理員 | 
| 建立 SAML 2.0 聯合的 IAM 角色和政策。 | 1. 為 SAML 2.0 聯合建立 IAM 角色。如需說明，請參閱 WorkSpaces 文件中設定 WorkSpaces Personal 專用 SAML 2.0 的說明中的 WorkSpaces[步驟 2](https://docs.aws.amazon.com/workspaces/latest/adminguide/setting-up-saml.html#create-saml-iam-role)。<br />2. 建立 IAM 政策，並將其與您在上一個步驟中建立的角色建立關聯。如需說明，請參閱 WorkSpaces 文件中設定 WorkSpaces Personal 專用 SAML 2.0 的說明中的 WorkSpaces[步驟 3](https://docs.aws.amazon.com/workspaces/latest/adminguide/setting-up-saml.html#embed-inline-policy)。 | 雲端管理員 | 

### 在 Auth0 中設定宣告
<a name="configure-assertions-in-auth0"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Auth0 和 SAML 聲明。 | 您可以使用 Auth0 動作在 SAML 2.0 回應中設定宣告。SAML 聲明是可宣告使用者身分的加密字符。1. 登入 Auth0 儀表板。選擇**動作**、**程式庫**、**建立動作**、**從頭開始建置**。<br />2. 提供下列值，然後選擇**建立**。<br />**名稱：指定動作的名稱**<br />**觸發：選擇登入/登入後**<br />**執行時間：選擇節點 18**<br />3. 在下一個畫面上，輸入下列程式碼：<pre>exports.onExecutePostLogin = async (event, api) => <br />{   if (event.client.name === "Workspace_Saml")<br />   {     const awsRole = 'arn:aws:iam::030784294031:role/Workspace_Auth0,arn:aws:iam::030784294031:saml-provider/Auth0';<br />     const awsRoleSession = event.user.sAMAccountName;<br />     const email = event.user.emails[0];<br />     api.samlResponse.setDestination('https://signin.aws.amazon.com/saml');<br />     api.samlResponse.setAttribute('https://aws.amazon.com/SAML/Attributes/Role', awsRole)<br />     api.samlResponse.setAttribute('https://aws.amazon.com/SAML/Attributes/RoleSessionName', awsRoleSession)<br />     api.samlResponse.setAttribute('https://aws.amazon.com/SAML/Attributes/PrincipalTag:Email', email)<br />   } return;<br />};</pre><br />4. 選擇**部署**。<br />如此即完成 WorkSpaces Personal 桌面的 SAML 2.0 身分驗證設定。[架構](#implement-saml-authentication-for-amazon-workspaces-by-using-auth0-and-aws-managed-microsoft-ad-architecture)區段說明設定後的身分驗證程序。 | 雲端管理員 | 

## 疑難排解
<a name="implement-saml-authentication-for-amazon-workspaces-by-using-auth0-and-aws-managed-microsoft-ad-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| WorkSpaces 中的 SAML 2.0 身分驗證問題<br />** ** | 如果您在實作 WorkSpaces Personal 的 SAML 2.0 身分驗證時遇到任何問題，請遵循 [AWS re：Post 文章](https://repost.aws/knowledge-center/workspaces-saml-authentication-issues)中關於對 SAML 2.0 身分驗證進行疑難排解的步驟和連結。<br />如需有關在存取 WorkSpaces 時調查 SAML 2.0 錯誤的其他資訊，請參閱：+ [如何從瀏覽器為 AWS 支援 案例建立 HAR 檔案和主控台日誌？](https://repost.aws/knowledge-center/support-case-browser-har-file)(AWS re：Post)<br />+ [在瀏覽器中檢視 SAML 回應 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_saml_view-saml-response.html)(IAM 文件）  | 

## 相關資源
<a name="implement-saml-authentication-for-amazon-workspaces-by-using-auth0-and-aws-managed-microsoft-ad-resources"></a>
+ [為 WorkSpaces Personal 設定 SAML 2.0](https://docs.aws.amazon.com/workspaces/latest/adminguide/setting-up-saml.html) (WorkSpaces 文件）
+ [Auth0 文件](https://auth0.com/docs)