

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

# 在 SageMaker AI Studio Classic 的 CloudTrail 日誌中開啟 sourceIdentity
<a name="monitor-user-access-how-to"></a>

使用 Amazon SageMaker Studio Classic，您就可以監控使用者資源存取。不過，資源存取的 AWS CloudTrail 日誌只會將 Studio Classic 執行 IAM 角色列為識別碼。當多個使用者設定檔之間共用單一執行 IAM 角色時，您必須使用 `sourceIdentity`組態來取得存取 AWS 資源之特定使用者的相關資訊。

下列主題說明如何開啟或關閉 `sourceIdentity` 組態。

**Topics**
+ [先決條件](#monitor-user-access-prereq)
+ [開啟 sourceIdentity](#monitor-user-access-enable)
+ [關閉 sourceIdentity](#monitor-user-access-disable)

## 先決條件
<a name="monitor-user-access-prereq"></a>
+ 在[安裝或更新最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) 中，安裝和設定 AWS Command Line Interface 下列步驟。
+ 請確定您網域中的 Studio Classic 使用者不具備允許使用者更新或修改網域的政策。  
+ 若要開啟或關閉 `sourceIdentity` 傳播，網域中的所有應用程式都必須處於 `Stopped` 或 `Deleted` 狀態。如需如何停止並關閉應用程式的詳細資訊，請參閱[關閉及更新 Studio Classic 應用程式](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-tasks-update-apps.html)。
+ 如果來源身分傳播已開啟，則所有執行角色都必須具有下列信任政策許可： 
  + 網域執行角色所擔任的任何角色都必須具有信任政策中的 `sts:SetSourceIdentity` 許可。如果缺少此許可，當您呼叫任務建立 API 時，您的動作會失敗，並發生 `ValidationError` 或 `AccessDeniedException`。以下範例信任政策包含 `sts:SetSourceIdentity` 許可。

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

****  

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

------
  + 當您使用一個角色擔任另一個角色，稱為角色串連，請執行下列動作：
    + 在擔任該角色的主體之許可政策和目標角色的角色信任政策中都需要 `sts:SetSourceIdentity` 的許可。否則，擔任角色操作將會失敗。
    +  此角色串連可能發生在 Studio Classic 或任何其他下游服務中 (例如 Amazon EMR)。如需有關角色串連的詳細資訊，請參閱中[角色術語和概念](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html)。

## 開啟 sourceIdentity
<a name="monitor-user-access-enable"></a>

根據預設關閉 Studio Classic 中傳播使用者設定檔名稱為 `sourceIdentity` 的功能。

若要啟用將使用者設定檔名稱傳播為 的功能`sourceIdentity`，請在網域建立和網域更新 AWS CLI 期間使用 。會在網域層級啟用此功能，而不是在使用者設定檔層級。

 啟用此設定後，系統管理員可以在已存取服務的 AWS CloudTrail 日誌中檢視使用者設定檔。在 `userIdentity` 區段中指定使用者設定檔為 `sourceIdentity`。如需搭配 SageMaker AI 使用 AWS CloudTrail 日誌的詳細資訊，請參閱 [搭配 記錄 Amazon SageMaker AI API 呼叫 AWS CloudTrail](https://docs.aws.amazon.com/sagemaker/latest/dg/logging-using-cloudtrail.html)。

在使用 `create-domain` API 建立網域期間，您可以使用下列程式碼來啟用使用者設定檔名稱為 `sourceIdentity` 的傳播。

```
create-domain
--domain-name <value>
--auth-mode <value>
--default-user-settings <value>
--subnet-ids <value>
--vpc-id <value>
[--tags <value>]
[--app-network-access-type <value>]
[--home-efs-file-system-kms-key-id <value>]
[--kms-key-id <value>]
[--app-security-group-management <value>]
[--domain-settings "ExecutionRoleIdentityConfig=USER_PROFILE_NAME"]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
```

在使用 `update-domain` API 更新網域期間，您可以啟用使用者設定檔名稱為 `sourceIdentity` 的傳播。

若要更新此設定，網域中的所有應用程式都必須處於 `Stopped` 或 `Deleted` 狀態。如需如何停止並關閉應用程式的詳細資訊，請參閱[關閉及更新 Studio Classic 應用程式](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-tasks-update-apps.html)。

使用下列程式碼來啟用使用者設定檔名稱為 `sourceIdentity` 的傳播。

```
update-domain
--domain-id <value>
[--default-user-settings <value>]
[--domain-settings-for-update "ExecutionRoleIdentityConfig=USER_PROFILE_NAME"]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
```

## 關閉 sourceIdentity
<a name="monitor-user-access-disable"></a>

您也可以使用 AWS CLI關閉使用者設定檔名稱為 `sourceIdentity` 的傳播。在網域更新期間，傳遞 `--domain-settings-for-update` 參數的 `ExecutionRoleIdentityConfig=DISABLED` 值做為 `update-domain` API 呼叫的一部分時會發生。

在 中 AWS CLI，使用以下程式碼來停用使用者設定檔名稱的傳播做為 `sourceIdentity`。

```
update-domain
 --domain-id <value>
[--default-user-settings <value>]
[--domain-settings-for-update "ExecutionRoleIdentityConfig=DISABLED"]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
```