

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

# Amazon SageMaker AI 如何使用 IAM
<a name="security_iam_service-with-iam"></a>

**重要**  
允許 Amazon SageMaker Studio 或 Amazon SageMaker Studio Classic 建立 Amazon SageMaker 資源的自訂 IAM 政策也必須授與許可，才能將標籤新增至這些資源。需要將標籤新增至資源的許可，因為 Studio 和 Studio Classic 會自動標記它們建立的任何資源。如果 IAM 政策允許 Studio 和 Studio Classic 建立資源，但不允許標記，則在嘗試建立資源時可能會發生 "AccessDenied" 錯誤。如需詳細資訊，請參閱[提供標記 SageMaker AI 資源的許可](security_iam_id-based-policy-examples.md#grant-tagging-permissions)。  
提供許可來建立 SageMaker 資源的 [AWS Amazon SageMaker AI 的 受管政策](security-iam-awsmanpol.md) 已包含建立這些資源時新增標籤的許可。

使用 IAM 來管理 SageMaker AI 的存取權之前，您應該先了解哪些 IAM 特徵可與 SageMaker AI 搭配使用。若要全面了解 SageMaker AI 和其他 AWS 服務如何與 IAM 搭配使用，請參閱[AWS 服務授權參考中的與 IAM 搭配使用](https://docs.aws.amazon.com/service-authorization/latest/reference/reference_aws-services-that-work-with-iam.html)*的服務*。

**Topics**
+ [Amazon SageMaker AI 身分型政策](#security_iam_service-with-iam-id-based-policies)
+ [Amazon SageMaker AI 內的資源型政策](#security_iam_service-with-iam-resource-based-policies)
+ [Amazon SageMaker AI 的政策動作](#security_iam_service-with-iam-id-based-policies-actions)
+ [Amazon SageMaker AI 的政策資源](#security_iam_service-with-iam-id-based-policies-resources)
+ [Amazon SageMaker AI 的政策條件金鑰](#security_iam_service-with-iam-id-based-policies-conditionkeys)
+ [基於 SageMaker AI 標籤的授權](#security_iam_service-with-iam-tags)
+ [SageMaker AI IAM 角色](#security_iam_service-with-iam-roles)

## Amazon SageMaker AI 身分型政策
<a name="security_iam_service-with-iam-id-based-policies"></a>

使用 IAM 身分型政策，您可以指定允許或拒絕的動作和資源，以及在何種條件下允許或拒絕動作。SageMaker AI 支援特定動作、資源和條件金鑰。若要了解您在 JSON 政策中使用的所有元素，請參閱《服務授權參考》**中的 [IAM JSON 政策元素參考](https://docs.aws.amazon.com/service-authorization/latest/reference/reference_policies_elements.html)。

## Amazon SageMaker AI 內的資源型政策
<a name="security_iam_service-with-iam-resource-based-policies"></a>

**支援資源型政策：**否 

資源型政策是附加到資源的 JSON 政策文件。資源型政策的最常見範例是 IAM *角色信任政策*和 Amazon S3 *儲存貯體政策*。在支援資源型政策的服務中，服務管理員可以使用它們來控制對特定資源的存取權限。對於附加政策的資源，政策會定義指定的主體可以對該資源執行的動作以及在何種條件下執行的動作。您必須在資源型政策中[指定主體](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html)。委託人可以包括帳戶、使用者、角色、聯合身分使用者 AWS 或服務。

如需啟用跨帳戶存取權，您可以指定在其他帳戶內的所有帳戶或 IAM 實體，做為資源型政策的主體。新增跨帳戶主體至資源型政策，只是建立信任關係的一半。當主體和資源在不同的 AWS 帳戶中時，受信任帳戶中的 IAM 管理員也必須授予主體實體 (使用者或角色) 存取資源的許可。其透過將身分型政策連接到實體來授與許可。不過，如果資源型政策會為相同帳戶中的主體授予存取，這時就不需要額外的身分型政策。如需詳細資訊，請參閱《*IAM 使用者指南*》中的 [IAM 中的快帳戶資源存取](https://docs.aws.amazon.com//IAM/latest/UserGuide/access_policies-cross-account-resource-access.html)。

**注意**  
使用 [AWS Resource Access Manager](https://docs.aws.amazon.com/ram/latest/userguide/what-is.html) 安全地共用支援的 SageMaker AI 資源。若要尋找可共用資源的清單，請參閱[可共用的 Amazon SageMaker AI 資源](https://docs.aws.amazon.com/ram/latest/userguide/shareable.html#shareable-sagemaker)。

## Amazon SageMaker AI 的政策動作
<a name="security_iam_service-with-iam-id-based-policies-actions"></a>

管理員可以使用 AWS JSON 政策來指定誰可以存取內容。也就是說，哪個**主體**在什麼**條件**下可以對什麼**資源**執行哪些**動作**。

JSON 政策的 `Action` 元素描述您可以用來允許或拒絕政策中存取的動作。政策會使用動作來授予執行相關聯動作的許可。

SageMaker AI 中的政策動作會在動作之前使用以下字首：`sagemaker:`。例如，若要授予某人使用 SageMaker AI `CreateTrainingJob` API 操作來執行 SageMaker AI 訓練任務的許可，請在其政策中包括 `sagemaker:CreateTrainingJob` 動作。政策陳述式必須包含 `Action` 或 `NotAction` 元素。SageMaker AI 會定義自己的一組動作，描述您可以使用此服務執行的任務。

若要在單一陳述式中指定多個動作，請用逗號分隔，如下所示：

```
"Action": [
      "sagemaker:action1",
      "sagemaker:action2"
]
```

您也可以使用萬用字元 (\*) 來指定多個動作。例如，若要指定開頭是 `Describe` 文字的所有動作，請包含以下動作：

```
"Action": "sagemaker:Describe*"
```



若要查看 SageMaker AI 動作清單，請參閱《服務授權參考》**中的 [Amazon SageMaker AI 的動作、資源和條件金鑰](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonsagemaker.html)。

## Amazon SageMaker AI 的政策資源
<a name="security_iam_service-with-iam-id-based-policies-resources"></a>



**支援政策資源：**是

管理員可以使用 AWS JSON 政策來指定誰可以存取內容。也就是說，哪個**主體**在什麼**條件**下可以對什麼**資源**執行哪些**動作**。

`Resource` JSON 政策元素可指定要套用動作的物件。陳述式必須包含 `Resource` 或 `NotResource` 元素。最佳實務是使用其 [Amazon Resource Name (ARN)](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html) 來指定資源。您可以針對支援特定資源類型的動作 (*稱為資源層級許可*) 來這麼做。

對於不支援資源層級許可的動作 (例如列出操作)，請使用萬用字元 (\*) 來表示陳述式適用於所有資源。

```
"Resource":  "*"
```

若要查看 Amazon SageMaker AI 資源類型及其 ARN 的清單，請參閱《服務授權參考》**中 Amazon SageMaker AI 所定義動作、資源類型和條件金鑰的下列參考。
+ [Amazon SageMaker AI](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonsagemaker.html)
+ [Amazon SageMaker 地理空間功能](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonsagemakergeospatialcapabilities.html)
+ [Amazon SageMaker Ground Truth Synthetic](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonsagemakergroundtruthsynthetic.html)
+ [Amazon SageMaker AI 與 MLflow](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonsagemakerwithmlflow.html)

若要了解您可以使用哪些動作指定每個資源的 ARN，請參閱 [Amazon SageMaker AI 定義的動作](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonsagemaker.html#amazonsagemaker-actions-as-permissions)。

## Amazon SageMaker AI 的政策條件金鑰
<a name="security_iam_service-with-iam-id-based-policies-conditionkeys"></a>

管理員可以使用 AWS JSON 政策來指定誰可以存取內容。也就是說，哪個**主體**在什麼**條件**下可以對什麼**資源**執行哪些**動作**。

`Condition` 元素會根據定義的條件，指定陳述式的執行時機。您可以建立使用[條件運算子](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html)的條件運算式 (例如等於或小於)，來比對政策中的條件和請求中的值。若要查看所有 AWS 全域條件索引鍵，請參閱《*IAM 使用者指南*》中的[AWS 全域條件內容索引鍵](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)。

SageMaker AI 會定義自己的一組條件金鑰，也支援使用一些全域條件金鑰。若要查看所有 AWS 全域條件金鑰，請參閱*服務授權參考*中的[AWS 全域條件內容金鑰](https://docs.aws.amazon.com/service-authorization/latest/reference/reference_policies_condition-keys.html)。



SageMaker AI 支援多個服務特定條件金鑰，您可以用於下列操作的精細存取控制：
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateProcessingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateProcessingJob.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModel.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModel.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpointConfig.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateEndpointConfig.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTransformJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTransformJob.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateHyperParameterTuningJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateHyperParameterTuningJob.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateNotebookInstance.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateNotebookInstance.html)
+ [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateNotebookInstance.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateNotebookInstance.html)

若要查看 SageMaker AI 條件金鑰的清單，請參閱《服務授權參考》**中的 [Amazon SageMaker AI 的條件金鑰](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonsagemaker.html#amazonsagemaker-policy-keys)。若要了解您可以搭配哪些動作和資源使用條件金鑰，請參閱 [Amazon SageMaker AI 定義的動作](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonsagemaker.html#amazonsagemaker-actions-as-permissions)。

如需使用 SageMaker AI 條件金鑰的範例，請參閱下列資訊：[使用條件金鑰控制 SageMaker AI 資源的建立](security_iam_id-based-policy-examples.md#sagemaker-condition-examples)。

### 範例
<a name="security_iam_service-with-iam-id-based-policies-examples"></a>



若要檢視 SageMaker AI 身分型政策範例，請參閱[Amazon SageMaker AI 身分型政策範例](security_iam_id-based-policy-examples.md)。

## 基於 SageMaker AI 標籤的授權
<a name="security_iam_service-with-iam-tags"></a>

您可以將標籤連接到 SageMaker AI 資源，或是將請求中的標籤傳遞至 SageMaker AI。如需根據標籤控制存取，請使用 `sagemaker:ResourceTag/{{key-name}}`、`aws:RequestTag/{{key-name}}` 或 `aws:TagKeys` 條件索引鍵，在政策的[條件元素](https://docs.aws.amazon.com/service-authorization/latest/reference/reference_policies_elements_condition.html)中，提供標籤資訊。如需標記 SageMaker AI 資源的詳細資訊，請參閱[使用標籤控制對 SageMaker AI 資源的存取](security_iam_id-based-policy-examples.md#access-tag-policy)。

若要檢視身分型政策範例，以根據該資源上的標籤來限制存取資源，請參閱 [使用標籤控制對 SageMaker AI 資源的存取](security_iam_id-based-policy-examples.md#access-tag-policy)。

## SageMaker AI IAM 角色
<a name="security_iam_service-with-iam-roles"></a>

[IAM 角色](https://docs.aws.amazon.com/service-authorization/latest/reference/id_roles.html)是您 AWS 帳戶中具有特定許可的實體。

### 使用臨時憑證搭配 SageMaker AI
<a name="security_iam_service-with-iam-roles-tempcreds"></a>

您可以搭配聯合使用暫時憑證、擔任 IAM 角色，或是擔任跨帳戶角色。您可以透過呼叫 [AssumeRole](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) 或 [GetFederationToken](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetFederationToken.html) 等 AWS STS API 操作來取得臨時安全登入資料。

SageMaker AI 支援使用臨時憑證。

### 服務連結角色
<a name="security_iam_service-with-iam-roles-service-linked"></a>

SageMaker AI 局部支援[服務連結角色](https://docs.aws.amazon.com/service-authorization/latest/reference/id_roles_terms-and-concepts.html#iam-term-service-linked-role)。服務連結角色目前可用於 SageMaker Studio Classic。

### 服務角色
<a name="security_iam_service-with-iam-roles-service"></a>

此功能可讓服務代表您擔任[服務角色](https://docs.aws.amazon.com/service-authorization/latest/reference/id_roles_terms-and-concepts.html#iam-term-service-role)。此角色可讓服務存取其他服務中的資源，以代表您完成動作。服務角色會出現在您的 IAM 帳戶中，且由該帳戶所擁有。這表示 IAM 管理員可以變更此角色的許可。不過，這樣可能會破壞此服務的功能。

SageMaker AI 支援服務角色。

### 選擇 SageMaker AI 中的 IAM 角色
<a name="security_iam_service-with-iam-roles-choose"></a>

當您在 SageMaker AI 中建立筆記本執行個體、處理任務、訓練任務、託管端點或批次轉換任務資源時，您必須選擇一個角色，以允許 SageMaker AI 代表您存取 SageMaker AI。如果您先前已建立服務角色或服務連結角色，SageMaker AI 會提供您角色清單讓您選擇。請務必選擇允許存取您所需 AWS 操作和資源的角色。如需詳細資訊，請參閱[如何使用 SageMaker AI 執行角色](sagemaker-roles.md)。