

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

# IAM Identity Center 的 CloudTrail 使用案例
<a name="sso-cloudtrail-use-cases"></a>

IAM Identity Center 發出的 CloudTrail 事件對於各種使用案例可能很有價值。組織可以使用這些事件日誌來監控和稽核使用者在其 AWS 環境中的存取和活動。這有助於合規使用案例，因為日誌會擷取存取資源的人員和時間的詳細資訊。您也可以使用 CloudTrail 資料進行事件調查，讓團隊分析使用者動作並追蹤可疑行為。此外，事件歷史記錄可以支援故障診斷工作，提供一段時間內對使用者許可和組態所做的變更的可見性。

下列各節說明通知工作流程的基本使用案例，例如稽核、事件調查和故障診斷。

## 在 IAM Identity Center 使用者起始的 CloudTrail 事件中識別使用者
<a name="user-session-iam-identity-center"></a>

IAM Identity Center 會發出兩個 CloudTrail 欄位，讓您識別 CloudTrail 事件後方的 IAM Identity Center 使用者，例如登入 IAM Identity Center 或 AWS CLI，以及使用 AWS 存取入口網站，包括管理 MFA 裝置：
+ `userId` – IAM Identity Center 執行個體的 Identity Store 中唯一且不變的使用者識別符。
+ `identityStoreArn` – 包含使用者的 Identity Store 的 Amazon Resource Name (ARN)。

`userID` 和 `identityStoreArn` 欄位會顯示在巢狀於 `onBehalfOf` 元素內的 [https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-user-identity.html](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-user-identity.html) 元素中，如下列範例 CloudTrail 事件日誌所示。此事件日誌會在`userIdentity`類型為 "`IdentityCenterUser`" 的事件上顯示這兩個欄位。您也可以在已驗證 IAM Identity Center 使用者的事件上找到這些欄位，其中`userIdentity`類型為 "`Unknown`"。您的工作流程應該接受這兩種類型值。

```
"userIdentity":{
  "type":"IdentityCenterUser",
  "accountId":"111122223333",
  "onBehalfOf": {
    "userId": "544894e8-80c1-707f-60e3-3ba6510dfac1",
    "identityStoreArn": "arn:aws:identitystore::111122223333:identitystore/d-1234567890"
    },
    "credentialId" : "90e292de-5eb8-446e-9602-90f7c45044f7"
  }
```

**提示**  
我們建議您使用 `userId`和 `identityStoreArn` 來識別 IAM Identity Center CloudTrail 事件後方的使用者。`userIdentity` 元素下的 `userName`和 `principalId` 欄位不再可用。如果您的工作流程，例如稽核或事件回應，取決於是否有權存取 `username`，您有兩個選項：  
從 IAM Identity Center 目錄擷取使用者名稱，如 中所述[登入 CloudTrail 事件中的使用者名稱](username-sign-in-cloudtrail-events.md)。
在登入中的 `additionalEventData`元素下取得 `UserName` IAM Identity Center 發出的 。此選項不需要存取 IAM Identity Center 目錄。如需詳細資訊，請參閱[登入 CloudTrail 事件中的使用者名稱](username-sign-in-cloudtrail-events.md)。

若要擷取使用者的詳細資訊，包括 `username` 欄位，您可以使用使用者 ID 和身分存放區 ID 做為參數來查詢身分存放區。您可以透過 [https://docs.aws.amazon.com/singlesignon/latest/IdentityStoreAPIReference/API_DescribeUser.html](https://docs.aws.amazon.com/singlesignon/latest/IdentityStoreAPIReference/API_DescribeUser.html) API 請求或透過 CLI 執行此動作。以下是範例 CLI 命令。如果您的 IAM Identity Center 執行個體位於 CLI 預設區域中，您可以省略 `region` 參數。

```
aws identitystore describe-user \
--identity-store-id  d-1234567890 \
--user-id  544894e8-80c1-707f-60e3-3ba6510dfac1 \
--region your-region-id
```

若要判斷上一個範例中 CLI 命令的 Identity Store ID 值，您可以從 `identityStoreArn`值擷取 Identity Store ID。在範例 ARN 中`arn:aws:identitystore::111122223333:identitystore/d-1234567890`，身分存放區 ID 為 `d-1234567890`。或者，您也可以在 IAM Identity Center 主控台**的設定**區段中導覽至 **Identity Store** 索引標籤，以尋找 Identity Store ID。

如果您要自動查詢 IAM Identity Center 目錄中的使用者，建議您預估使用者查詢的頻率，並考慮 [Identity Store API 上的 IAM Identity Center 限流限制](limits.md#ssodirectorylimits)。快取擷取的使用者屬性可協助您保持在限流限制內。

## 關聯相同使用者工作階段中的使用者事件
<a name="correlating-users-same-session"></a>

登入事件中發出的 [`AuthWorkflowID`](understanding-sign-in-events.md) 欄位可在 IAM Identity Center 使用者工作階段開始之前，追蹤與登入序列相關聯的所有 CloudTrail 事件。

對於 AWS 存取入口網站內的使用者動作，`credentialId`值會設定為用於請求動作之 IAM Identity Center 使用者工作階段的 ID。您可以使用此值來識別在 AWS 存取入口網站中相同已驗證的 IAM Identity Center 使用者工作階段中啟動的 CloudTrail 事件。

**注意**  
您無法使用 `credentialId` 將登入事件與後續事件建立關聯，例如使用 AWS 存取入口網站。登入事件中發出的`credentialId`欄位值具有內部使用，我們建議您不要依賴它。使用 OIDC 叫用之[AWS 存取入口網站事件](sso-info-in-cloudtrail.md#cloudtrail-events-access-portal-operations)所發出的 `credentialId` 欄位值等於存取字符的 ID。

## 在 IAM Identity Center 使用者起始的 CloudTrail 事件中識別使用者背景工作階段詳細資訊
<a name="identifying-user-background-session-details"></a>

下列 CloudTrail 事件會擷取 OAuth 2.0 權杖交換的程序，其中代表使用者互動式工作階段的現有存取權杖 (`subjectToken`) 會交換為重新整理權杖 ()`requestedTokenType`。重新整理權杖可讓任何使用者啟動的長期執行任務繼續以使用者的許可執行，即使在使用者登出之後也是如此。

對於 IAM Identity Center [使用者背景工作階段](user-background-sessions.md)，CloudTrail 事件會在 元素`resource`中包含名為 的其他`requestParameters`元素。`resource` 參數包含在背景中執行之任務的 Amazon Resource Name (ARN)。此元素僅存在於 CloudTrail 事件記錄中，不包含在 IAM Identity Center [CreateTokenWithIAM](https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/API_CreateTokenWithIAM.html) API 或 SDK 回應中。

```
{
  "clientId": "EXAMPLE-CLIENT-ID",
  "grantType": "urn:ietf:params:oauth:grant-type:token-exchange",
  "code": "HIDDEN_DUE_TO_SECURITY_REASONS",
  "redirectUri": "https://example.com/callback",
  "assertion": "HIDDEN_DUE_TO_SECURITY_REASONS",
  "subjectToken": "HIDDEN_DUE_TO_SECURITY_REASONS",
  "subjectTokenType": "urn:ietf:params:oauth:token-type:access_token",
  "requestedTokenType": "urn:ietf:params:oauth:token-type:refresh_token",
  "resource": "arn:aws:sagemaker:us-west-2:123456789012:training-job/my-job"
}
```

## 在 IAM Identity Center 和外部目錄之間關聯使用者
<a name="correlating-users"></a>

IAM Identity Center 提供兩個使用者屬性，您可以用來將目錄中的使用者與外部目錄中的相同使用者 （例如 Microsoft Active Directory和 ) 建立關聯Okta Universal Directory。
+ `externalId` – IAM Identity Center 使用者的外部識別符。我們建議您將此識別符映射到外部目錄中的不可變使用者識別符。請注意，IAM Identity Center 不會在 CloudTrail 中發出此值。
+ `username` – 使用者通常登入的客戶提供值。值可能會變更 （例如，使用 SCIM 更新）。請注意，當身分來源為 時 Directory Service，IAM Identity Center 在 CloudTrail 中發出的使用者名稱會與您輸入要驗證的使用者名稱相符。使用者名稱不需要與 IAM Identity Center 目錄中的使用者名稱完全相符。

   如果您可存取 CloudTrail 事件，但無法存取 IAM Identity Center 目錄，則可以使用登入時在 `additionalEventData`元素下發出的使用者名稱。如需 中使用者名稱的詳細資訊`additionalEventData`，請參閱 [登入 CloudTrail 事件中的使用者名稱](username-sign-in-cloudtrail-events.md)。

當身分來源為 時，IAM Identity Center 會定義這兩個使用者屬性與外部目錄中對應使用者屬性的映射 Directory Service。如需資訊，請參閱 [IAM Identity Center 與外部身分提供者目錄之間的屬性映射](attributemappingsconcept.md)。使用 SCIM 佈建使用者的外部 IdPs 有自己的映射。即使您使用 IAM Identity Center 目錄做為身分來源，也可以使用 `externalId` 屬性將安全主體交叉參考至外部目錄。

下一節說明如何根據使用者的 `username`和 來查詢 IAM Identity Center 使用者`externalId`。

## 依使用者名稱和 externalId 檢視 IAM Identity Center 使用者
<a name="view-username-extid"></a>

您可以從 IAM Identity Center 目錄中擷取已知使用者名稱的使用者屬性，方法是先`userId`使用 [https://docs.aws.amazon.com/singlesignon/latest/IdentityStoreAPIReference/API_GetUserId.html](https://docs.aws.amazon.com/singlesignon/latest/IdentityStoreAPIReference/API_GetUserId.html) API 請求請求對應的 ，然後發出 [https://docs.aws.amazon.com/singlesignon/latest/IdentityStoreAPIReference/API_DescribeUser.html](https://docs.aws.amazon.com/singlesignon/latest/IdentityStoreAPIReference/API_DescribeUser.html) API 請求，如先前範例所示。下列範例示範如何`userId`從 Identity Store 擷取特定使用者名稱的 。如果您的 IAM Identity Center 執行個體位於使用 CLI 的預設區域中，您可以省略 `region` 參數。

```
aws identitystore get-user-id \
    --identity-store d-9876543210 \
    --alternate-identifier '{
      "UniqueAttribute": {
      "AttributePath": "username",
      "AttributeValue": "anyuser@example.com"
        }
          }' \
    --region your-region-id
```

同樣地，當您知道 時，可以使用相同的機制`externalId`。使用 `externalId`值更新先前範例中的屬性路徑，並使用您要搜尋`externalId`的特定 更新屬性值。

## 在 Microsoft Active Directory (AD) 和 externalId 中檢視使用者的安全識別符 (SID)
<a name="view-users-sid-ad"></a>

在某些情況下，IAM Identity Center 會在 CloudTrail 事件的 `principalId` 欄位中發出使用者的 SID，例如 AWS 存取入口網站和 OIDC APIs發出的 SID。**這些案例正在淘汰。**當您需要 AD 的唯一使用者識別符`objectguid`時，建議您的工作流程使用 AD 屬性。您可以在 IAM Identity Center 目錄中的 `externalId` 屬性中找到此值。不過，如果您的工作流程需要使用 SID，請從 AD 擷取該值，因為它無法透過 IAM Identity Center APIs 使用。

[關聯相同使用者工作階段中的使用者事件在 IAM Identity Center 和外部目錄之間關聯使用者](#correlating-users) 說明如何使用 `externalId`和 `username` 欄位，將 IAM Identity Center 使用者與外部目錄中相符的使用者建立關聯。根據預設，IAM Identity Center 會映射`externalId`至 AD `objectguid` 中的 屬性，而且此映射是固定的。IAM Identity Center 允許管理員靈活地映射到 AD `userprincipalname`中的`username`預設映射。

您可以在 IAM Identity Center 主控台中檢視這些映射。導覽至**設定**中的**身分來源**索引標籤，然後在**動作**功能表中選擇**管理同步**。在**管理同步**區段中，選擇**檢視屬性映射**按鈕。

雖然您可以使用 IAM Identity Center 中可用的任何唯一 AD 使用者識別符來查詢 AD 中的使用者，但我們建議您在查詢`objectguid`中使用 ，因為它是不可變的識別符。下列範例說明如何使用 Powershell 查詢 Microsoft AD，以使用使用者`objectguid`的值 擷取使用者`16809ecc-7225-4c20-ad98-30094aefdbca`。此查詢的成功回應包含使用者的 SID。

```
Install-WindowsFeature -Name  RSAT-AD-PowerShell
 
  Get-ADUser `
  -Filter {objectGUID -eq  [GUID]::Parse("16809ecc-7225-4c20-ad98-30094aefdbca")} `
  -Properties *
```