

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

# 為身分驗證回應設定 SAML 聲明
<a name="id_roles_providers_create_saml_assertions"></a>

驗證組織中的使用者身分後，外部身分提供者 (IdP) 會將身分驗證回應傳送至 AWS 登入端點 URL。此回應是一個包含 SAML 權杖的 POST 請求，該權杖遵循[適用於 SAML 2.0 的 HTTP POST 繫結](http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf)標準，其中包含下列元素或*宣告*。您可在與 SAML 相容的 IdP 中配置這些聲明。請參考 IdP 文件，以了解有關如何輸入這些聲明的說明。

當 IdP 傳送包含宣告的回應至 時 AWS，許多傳入宣告會對應至 AWS 內容索引鍵。可以在 IAM 政策中使用 `Condition` 元素來檢查這些內容索引鍵。可用映射的清單將根據 [將 SAML 屬性映射至 AWS 信任政策內容索引鍵](#saml-attribute-mapping) 中所示。

## `Subject` 與 `NameID`
<a name="saml_subject-name-id"></a>

回應必須恰好包含一個 `SubjectConfirmation` 元素，而該元素所包含的 `SubjectConfirmationData` 元素須同時具備 `NotOnOrAfter` 屬性和 `Recipient` 屬性。收件人屬性必須包含符合 AWS 登入端點 URL 的值。您的 IdP 可能會使用 `ACS`、 `Recipient`或 一詞`Target`來參考此屬性。

如果需要 SAML 加密，登入 URL 必須包含 AWS 指派給 SAML 提供者的唯一識別碼，您可以在「身分提供者詳細資訊」頁面上找到此識別碼。下列範例展示了包含選用 `region-code` 的登入 URL 格式。

`https://region-code.signin.aws.amazon.com/saml`

在下列範例中，登入 URL 包含唯一識別碼，這需要在登入路徑後附加 /acs/。

`https://region-code.signin.aws.amazon.com/saml/acs/IdP-ID`

對於可能的 *region-code* 值清單，請參閱 [AWS 登入端點](https://docs.aws.amazon.com/general/latest/gr/signin-service.html)中的 **Region** (區域) 欄位。對於 AWS 值，您也可以使用全域登入端點 `https://signin.aws.amazon.com/saml`。

`NameID` 元素的值可以是持久的、暫時的，也可以由 IdP 解決方案提供的完整格式 URI 組成。持久的值表示 `NameID` 中的值對於工作階段之間的使用者是相同的。如果值為暫時的，則使用者在每個工作階段中擁有不同的 `NameID` 值。單一登入互動支援下列類型的識別碼：
+ `urn:oasis:names:tc:SAML:2.0:nameid-format:persistent`
+ `urn:oasis:names:tc:SAML:2.0:nameid-format:transient`
+ `urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress`
+ `urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified`
+ `urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName`
+ `urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName`
+ `urn:oasis:names:tc:SAML:2.0:nameid-format:kerberos`
+ `urn:oasis:names:tc:SAML:2.0:nameid-format:entity`

下列的摘錄顯示了範例。用您自己的值替代標記值。

```
<Subject>
  <NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">_cbb88bf52c2510eabe00c1642d4643f41430fe25e3</NameID>
  <SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
    <SubjectConfirmationData NotOnOrAfter="2013-11-05T02:06:42.876Z" Recipient="https://region-code.signin.aws.amazon.com/saml/SAMLSP4SHN3UIS2D558H46"/>
  </SubjectConfirmation>
</Subject>
```

**重要**  
`saml:aud` 內容索引鍵來自 SAML *recipient* 屬性，因其為等同於 OIDC 觀眾欄位 (例如 `accounts.google.com:aud`) 的 SAML。

## `PrincipalTag` SAML 屬性
<a name="saml_role-session-tags"></a>

(選用) 您可以使用 `Attribute` 元素，並將 `Name` 屬性設為 `https://aws.amazon.com/SAML/Attributes/PrincipalTag:{TagKey}`。此元素可讓您在 SAML 聲明中將屬性做為工作階段標籤傳遞。如需有關工作階段標籤的詳細資訊，請參閱 [在 中傳遞工作階段標籤 AWS STS](id_session-tags.md)。

若要將屬性做為工作階段標籤傳遞，請包含指定標籤值的 `AttributeValue` 元素。例如，若要傳遞標籤金鑰/值對 `Project` = `Marketing` 和 `CostCenter` = `12345`，請使用以下屬性。為每個標籤包含個別的 `Attribute` 元素。

```
<Attribute Name="https://aws.amazon.com/SAML/Attributes/PrincipalTag:Project">
  <AttributeValue>Marketing</AttributeValue>
</Attribute>
<Attribute Name="https://aws.amazon.com/SAML/Attributes/PrincipalTag:CostCenter">
  <AttributeValue>12345</AttributeValue>
</Attribute>
```

如要將以上標籤設為可轉移，請在其中包含另一個 `Attribute` 元素，並將其 `Name` 屬性設為 `https://aws.amazon.com/SAML/Attributes/TransitiveTagKeys`。這是一個選用的多重值屬性，會將您的工作階段標籤設為可轉移。可轉移標籤會在您於 AWS中使用 SAML 聲明擔任另一個角色時保存。這就是所謂的[角色鏈接](id_roles.md#iam-term-role-chaining)。例如，若要將 `Principal` 和 `CostCenter` 標籤設為可轉移，請使用以下屬性來指定金鑰。

```
<Attribute Name="https://aws.amazon.com/SAML/Attributes/TransitiveTagKeys">
  <AttributeValue>Project</AttributeValue>
  <AttributeValue>CostCenter</AttributeValue>
</Attribute>
```

## `Role` SAML 屬性
<a name="saml_role-attribute"></a>

您可以使用 `Attribute` 元素，將 `Name` 屬性設為 `https://aws.amazon.com/SAML/Attributes/Role`。此元素包含一或多個 `AttributeValue` 元素，這些元素可列出將由您的 IdP 對應之使用者的 IAM 身分提供者和角色。該 IAM 角色和 IAM 身分提供者被指定為逗號分隔的 ARN 組，所採用的格式與傳遞到 [AssumeRoleWithSAML](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithSAML.html) 的 `RoleArn` 與 `PrincipalArn` 參數的格式相同。此元素必須包含至少一個角色提供者對 (`AttributeValue` 元素)，並且可以包含多個角色提供者對。如果該元素包含多個角色提供者組，則使用者將需要選擇其使用 WebSSO 登入 AWS 管理主控台時要擔任的角色。

**重要**  
`Name` 標籤中 `Attribute` 屬性的值區分大小寫。必須精準設定為 `https://aws.amazon.com/SAML/Attributes/Role`。

```
<Attribute Name="https://aws.amazon.com/SAML/Attributes/Role">
  <AttributeValue>arn:aws:iam::account-number:role/role-name1,arn:aws:iam::account-number:saml-provider/provider-name</AttributeValue>
  <AttributeValue>arn:aws:iam::account-number:role/role-name2,arn:aws:iam::account-number:saml-provider/provider-name</AttributeValue>
  <AttributeValue>arn:aws:iam::account-number:role/role-name3,arn:aws:iam::account-number:saml-provider/provider-name</AttributeValue>
</Attribute>
```

## `RoleSessionName` SAML 屬性
<a name="saml_role-session-attribute"></a>

您可以使用 `Attribute` 元素，將 `Name` 屬性設為 `https://aws.amazon.com/SAML/Attributes/RoleSessionName`。此元素包含一個為暫時憑證提供識別符的 `AttributeValue` 元素，而這些憑證是在擔任角色時所發出。您可以使用此功能將臨時憑證與正在使用應用程式的使用者建立關聯。此元素用於在 中顯示使用者資訊 AWS 管理主控台。`AttributeValue` 元素中的值長度必須介於 2 到 64 個字元之間，只能包含字母數位字元、底線和以下字元：**. , \$1 = @ -** (連字號)。其中不可含有空格。該值通常是使用者 ID (`john`) 或電子郵件地址 (`johndoe@example.com`)。該值不應包含空格，如使用者的顯示名稱 (`John Doe`)。

**重要**  
`Name` 標籤中 `Attribute` 屬性的值區分大小寫。必須精準設定為 `https://aws.amazon.com/SAML/Attributes/RoleSessionName`。

```
<Attribute Name="https://aws.amazon.com/SAML/Attributes/RoleSessionName">
  <AttributeValue>user-id-name</AttributeValue>
</Attribute>
```

## `SessionDuration` SAML 屬性
<a name="saml_role-session-duration"></a>

(選用) 您可以使用 `Attribute` 元素，並將 `Name` 屬性設為 `https://aws.amazon.com/SAML/Attributes/SessionDuration`。此元素包含一個`AttributeValue`元素，指定使用者在必須請求新的臨時登入資料 AWS 管理主控台 之前，可以存取 的時間長度。該值是一個表示工作階段秒數的整數。該值的範圍是 900 秒 (15 分鐘) 到 43200 秒 (12 小時)。如果此屬性不存在，則憑證有效時間為 1 小時 (`DurationSeconds` API 的 `AssumeRoleWithSAML` 參數的預設值)。

若要使用此屬性，您必須設定 SAML 供應商， AWS 管理主控台 透過位於 的主控台登入 Web 端點提供 的單一登入存取`https://region-code.signin.aws.amazon.com/saml`。對於可能的 *region-code* 值清單，請參閱 [AWS 登入端點](https://docs.aws.amazon.com/general/latest/gr/signin-service.html)中的 **Region** (區域) 欄位。您可以選擇使用以下 URL：`https://signin.aws.amazon.com/static/saml`。請注意，此屬性只會將工作階段擴展到 AWS 管理主控台。它不能延長其他憑證的有效期。但是，如果其存在於 `AssumeRoleWithSAML` API 呼叫中，則可以用來*縮短*工作階段的持續時間。呼叫傳回的憑證預設存留期是 60 分鐘。

另請注意，如果同時定義了 `SessionNotOnOrAfter` 屬性，則兩個屬性的***較小***值 (`SessionDuration` 或 `SessionNotOnOrAfter`) 將建立主控台工作階段的持續時間上限。

在啟用具有更長持續時間的主控台工作階段時，可能會導致憑證洩露的風險。為了幫助緩解這種風險，您可以在 IAM 主控台的 **Role Summary** (角色摘要) 頁面上選擇 **Revoke Sessions** (撤銷工作階段) 來立即停用所有角色的使用中的主控台工作階段。如需詳細資訊，請參閱 [撤銷 IAM 角色臨時安全憑證](id_roles_use_revoke-sessions.md)。

**重要**  
`Name` 標籤中 `Attribute` 屬性的值區分大小寫。必須精準設定為 `https://aws.amazon.com/SAML/Attributes/SessionDuration`。

```
<Attribute Name="https://aws.amazon.com/SAML/Attributes/SessionDuration">
  <AttributeValue>1800</AttributeValue>
</Attribute>
```

## `SourceIdentity` SAML 屬性
<a name="saml_sourceidentity"></a>

(選用) 您可以使用 `Attribute` 元素，並將 `Name` 屬性設為 `https://aws.amazon.com/SAML/Attributes/SourceIdentity`。此元素包含一個 `AttributeValue` 元素，提供使用 IAM 角色之人員或應用程式的識別碼。當您使用 SAML 工作階段在 AWS 中擔任另一個角色時，來源身分的值會持續存在，稱為[角色鏈結](id_roles.md#iam-term-role-chaining)。針對在角色工作階段期間所採取的每個動作，來源身分的值會出現在請求中。設定的值無法在角色工作階段期間變更。然後，管理員可以使用 AWS CloudTrail 日誌來監控和稽核來源身分資訊，以判斷誰使用共用角色執行動作。

`AttributeValue` 元素中的值長度必須介於 2 到 64 個字元之間，只能包含字母數位字元、底線和以下字元：**. , \$1 = @ -** (連字號)。其中不可含有空格。此值通常是與使用者相關聯的屬性，例如使用者 ID (`john`) 或電子郵件地址 (`johndoe@example.com`)。該值不應包含空格，如使用者的顯示名稱 (`John Doe`)。如需有關使用來源身分的詳細資訊，請參閱 [監控並控制使用擔任角色所採取的動作](id_credentials_temp_control-access_monitor.md)。

**重要**  
如果您的 SAML 聲明設定為使用 [`SourceIdentity`](#saml_sourceidentity) 屬性，則您的信任政策也必須包含 `sts:SetSourceIdentity` 動作，否則擔任角色操作將失敗。如需有關使用來源身分的詳細資訊，請參閱 [監控並控制使用擔任角色所採取的動作](id_credentials_temp_control-access_monitor.md)。

若要傳遞來源身分屬性，請包含指定來源身分值的 `AttributeValue` 元素。例如，若要傳遞來源身分 `Diego`，請使用下列屬性。

```
<Attribute Name="https://aws.amazon.com/SAML/Attributes/SourceIdentity">
  <AttributeValue>Diego</AttributeValue>
```

## 將 SAML 屬性映射至 AWS 信任政策內容索引鍵
<a name="saml-attribute-mapping"></a>

本部分中的表列出了常用的 SAML 屬性以及它們在 AWS中映射到信任政策條件內容索引鍵的方式。您可以使用這些金鑰來控制角色的存取。若要執行此作業，請將金鑰與包含在 SAML 存取請求隨附聲明中的值進行比較。

**重要**  
這些索引鍵僅在 IAM 信任政策 (可決定誰能擔任角色的政策) 中可用，並且不適用於許可政策。

在 eduPerson 和 eduOrg 屬性工作表中，值是以字串或字串清單的形式輸入的。對於字串值，您可以使用 `StringEquals` 或 `StringLike` 條件測試 IAM 信任政策中的這些值。對於包含字串清單的值，您可以使用 `ForAnyValue` 與 `ForAllValues` [政策集運算子](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys)來測試信任政策中的這些值。

**注意**  
每個 AWS 內容索引鍵應該只包含一個宣告。如果包含多個聲明，將僅映射其中一個。

下表顯示 eduPerson 和 eduOrg 屬性。


| eduPerson 或 eduOrg 屬性 (`Name` 索引鍵) | 映射至此 AWS 內容索引鍵 (`FriendlyName` 索引鍵） | Type | 
| --- | --- | --- | 
|   `urn:oid:1.3.6.1.4.1.5923.1.1.1.1`   |   `eduPersonAffiliation`   |  字串清單  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.1.1.2`   |   `eduPersonNickname`   |  字串清單  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.1.1.3`   |   `eduPersonOrgDN`   |  字串  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.1.1.4`   |   `eduPersonOrgUnitDN`   |  字串清單  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.1.1.5`   |   `eduPersonPrimaryAffiliation`   |  字串  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.1.1.6`   |   `eduPersonPrincipalName`   |  字串  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.1.1.7`   |   `eduPersonEntitlement`   |  字串清單  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.1.1.8`   |   `eduPersonPrimaryOrgUnitDN`   |  字串  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.1.1.9`   |   `eduPersonScopedAffiliation`   |  字串清單  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.1.1.10`   |   `eduPersonTargetedID`   |  字串清單  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.1.1.11`   |   `eduPersonAssurance`   |  字串清單  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.2.1.2`   |   `eduOrgHomePageURI`   |  字串清單  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.2.1.3`   |   `eduOrgIdentityAuthNPolicyURI`   |  字串清單  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.2.1.4`   |   `eduOrgLegalName`   |  字串清單  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.2.1.5`   |   `eduOrgSuperiorURI`   |  字串清單  | 
|   `urn:oid:1.3.6.1.4.1.5923.1.2.1.6`   |   `eduOrgWhitePagesURI`   |  字串清單  | 
|   `urn:oid:2.5.4.3`   |   `cn`   |  字串清單  | 

下表顯示 Active Directory 屬性。


| AD 屬性 | 對應至此 AWS 內容索引鍵 | Type | 
| --- | --- | --- | 
|  `http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name`  |  `name`  |  字串  | 
|  `http://schemas.xmlsoap.org/claims/CommonName`  |  `commonName`  |  字串  | 
|  `http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname`  |  `givenName`  |  字串  | 
|  `http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname`  |  `surname`  |  字串  | 
|  `http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress`  |  `mail`  |  字串  | 
|  `http://schemas.microsoft.com/ws/2008/06/identity/claims/primarygroupsid`  |  `uid`  |  String  | 

下表顯示 X.500 屬性。


| X.500 屬性 | 對應至此 AWS 內容索引鍵 | Type | 
| --- | --- | --- | 
|  `2.5.4.3`  |  `commonName`  |  字串  | 
|  `2.5.4.4`  |  `surname`  |  字串  | 
|  `2.4.5.42`  |  `givenName`  |  字串  | 
|  `2.5.4.45`  |  `x500UniqueIdentifier`  |  字串  | 
|  `0.9.2342.19200300100.1.1`  |  `uid`  |  字串  | 
|  `0.9.2342.19200300100.1.3`  |  `mail`  |  字串  | 
|  `0.9.2342.19200300.100.1.45`  |  `organizationStatus`  |  字串  | 