

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 防止跨服务混淆代理
<a name="security-confused-deputy-prevention"></a>

[混淆代理问题](https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy)是一个安全问题，即没有执行操作权限的实体可能会迫使更具权限的实体执行该操作。在中 AWS，由于跨服务模仿，可能会出现混乱的副手问题。当一个服务（*调用服务*）调用另一个服务（*被调用服务*），并利用被调用服务的高级权限对调用服务无权访问的资源采取行动时，就会发生跨服务冒充。为了防止通过混乱的副手问题进行未经授权的访问， AWS 提供了一些工具来帮助保护您的跨服务数据。这些工具可帮助您控制授予服务主体的权限，限制他们只能访问您账户中必要的资源。通过仔细管理服务主体的访问权限，可以帮助降低服务不当访问其不应有权限的数据或资源的风险。

请继续阅读以获取一般指导或浏览特定 A SageMaker I 功能的示例：

**Topics**
+ [使用全局条件键限制权限](#security-confused-deputy-context-keys)
+ [SageMaker 边缘管理器](#security-confused-deputy-edge-manager)
+ [SageMaker 图片](#security-confused-deputy-images)
+ [SageMaker AI 推理](#security-confused-deputy-inference)
+ [SageMaker AI Batch 转换作业](#security-confused-deputy-batch)
+ [SageMaker 人工智能市场](#security-confused-deputy-marketplace)
+ [SageMaker Neo](#security-confused-deputy-neo)
+ [SageMaker 管道](#security-confused-deputy-pipelines)
+ [SageMaker 处理作业](#security-confused-deputy-processing-job)
+ [SageMaker 工作室](#security-confused-deputy-studio)
+ [SageMaker 培训职位](#security-confused-deputy-training-job)

## 使用全局条件键限制权限
<a name="security-confused-deputy-context-keys"></a>

我们建议在资源策略中使用`[aws:SourceArn](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourcearn)`和`[aws:SourceAccount](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourceaccount)`全局条件密钥来限制 Amazon A SageMaker I 为其他服务提供的资源的权限。如果同时使用全局条件键和包含账户 ID 的 `aws:SourceArn` 值，则 `aws:SourceAccount` 值和 `aws:SourceArn` 值中的账户在同一策略语句中使用时，必须使用相同的账户 ID。如果您只希望将一个资源与跨服务访问相关联，请使用。`aws:SourceArn`如果您想允许该账户中的任何资源与跨服务使用操作相关联，请使用。`aws:SourceAccount`

防范混淆代理问题的有效方法是使用 `aws:SourceArn` 全局条件键和资源的完整 ARN。如果您不知道资源的完整 ARN，或者您正在指定多个资源，请针对 ARN 未知部分使用带有通配符 (`*`) 的 `aws:SourceArn` 全局条件键。例如 `arn:aws:sagemaker:*:123456789012:*`。

以下示例显示了如何在 SageMaker AI 中使用`aws:SourceArn`和`aws:SourceAccount`全局条件键来防止出现混乱的副手问题。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Sid": "ConfusedDeputyPreventionExamplePolicy",
    "Effect": "Allow",
    "Principal": {
      "Service": "sagemaker.amazonaws.com"
    },
    "Action": "sagemaker:StartSession",
    "Resource": "arn:aws:sagemaker:us-east-1:123456789012:ResourceName/*",
    "Condition": {
      "ArnLike": {
        "aws:SourceArn": "arn:aws:sagemaker:us-east-1:123456789012:*"
      },
      "StringEquals": {
        "aws:SourceAccount": "123456789012"
      }
    }
  }
}
```

------

## SageMaker 边缘管理器
<a name="security-confused-deputy-edge-manager"></a>

以下示例显示了如何使用`aws:SourceArn`全局条件密钥来防止 SageMaker Edge Manager 的跨服务混淆代理问题，该问题是由该*us-west-2*区域*123456789012*的账号造成的。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
      "Effect": "Allow",
      "Principal": { "Service": "sagemaker.amazonaws.com" },
      "Action": "sts:AssumeRole",
      "Condition": {
        "ArnLike": {
          "aws:SourceArn": "arn:aws:sagemaker:us-west-2:123456789012:*"
      }
    }
  }
}
```

------

您可以将此模板中的 `aws:SourceArn` 替换为特定打包作业的完整 ARN，以进一步限制权限。

## SageMaker 图片
<a name="security-confused-deputy-images"></a>

以下示例显示了如何使用`aws:SourceArn`全局条件键来防止 I [SageMaker mages](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-byoi.html) 出现跨服务混淆副手问题。将此模板与 `[Image](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_Image.html)` 或 `[ImageVersion](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ImageVersion.html)` 一起使用。此示例使用带有账号的`ImageVersion`记录 ARN。*123456789012*请注意，由于账号是 `aws:SourceArn` 值的一部分，因此您无需指定 `aws:SourceAccount` 值。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": {
        "Effect": "Allow",
        "Principal": {
            "Service": "sagemaker.amazonaws.com"
        },
        "Action": "sts:AssumeRole",
        "Condition": {
            "ArnLike": {
            "aws:SourceArn": "arn:aws:sagemaker:us-east-2:123456789012:image-version/*"
            }
        }
    }
}
```

------

请勿将此模板中的 `aws:SourceArn` 替换为特定映像或映像版本的完整 ARN。ARN 必须采用上面提供的格式，并指定 `image` 或 `image-version`。`partition`占位符应指定 AWS 商业分区 (`aws`) 或中国分区 (`aws-cn`)，具体取决于映像或镜像版本的运行位置。 AWS 同样，ARN 中的`region`占位符可以是[任何有图片可用的有效](https://docs.aws.amazon.com/sagemaker/latest/dg/regions-quotas.html) SageMaker 区域。

## SageMaker AI 推理
<a name="security-confused-deputy-inference"></a>

以下示例显示了如何使用`aws:SourceArn`全局条件键来防止 SageMaker AI [实时](https://docs.aws.amazon.com/sagemaker/latest/dg/realtime-endpoints)、[无服务器](https://docs.aws.amazon.com/sagemaker/latest/dg/serverless-endpoints)和[异步](https://docs.aws.amazon.com/sagemaker/latest/dg/async-inference)推理的跨服务混淆代理问题。请注意，由于账号是 `aws:SourceArn` 值的一部分，因此您无需指定 `aws:SourceAccount` 值。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Effect": "Allow",
    "Principal": { "Service": "sagemaker.amazonaws.com" },
    "Action": "sts:AssumeRole",
    "Condition": {
      "ArnLike": {
        "aws:SourceArn": "arn:aws:sagemaker:us-west-2:123456789012:*"
      }
    }
  }
}
```

------

请勿将此模板中的 `aws:SourceArn` 替换为特定模型或端点的完整 ARN。ARN 必须采用上面提供的格式。ARN 模板中的星号不代表通配符，不应更改。

## SageMaker AI Batch 转换作业
<a name="security-confused-deputy-batch"></a>

以下示例显示了如何使用`aws:SourceArn`全局条件密钥来防止由该*us-west-2*地区账号创建的 SageMaker AI [批量转换作业](https://docs.aws.amazon.com/sagemaker/latest/dg/batch-transform.html)出现跨服务混淆*123456789012*的代理问题。请注意，由于账号在 ARN 中，因此无需指定 `aws:SourceAccount` 值。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "sagemaker.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "ArnLike": {
          "aws:SourceArn": "arn:aws:sagemaker:us-west-2:123456789012:transform-job/*"
        }
      }
    }
  ]
}
```

------

您可以将此模板中的 `aws:SourceArn` 替换为特定批量转换作业的完整 ARN，以进一步限制权限。

## SageMaker 人工智能市场
<a name="security-confused-deputy-marketplace"></a>

以下示例显示了如何使用`aws:SourceArn`全局条件密钥来防止由该*us-west-2*地区账号*123456789012*创建的 SageMaker AI Marketplace 资源出现跨服务混淆代理问题。请注意，由于账号在 ARN 中，因此无需指定 `aws:SourceAccount` 值。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "sagemaker.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "ArnLike": {
          "aws:SourceArn": "arn:aws:sagemaker:us-west-2:123456789012:*"
        }
      }
    }
  ]
}
```

------

请勿将此模板中的 `aws:SourceArn` 替换为特定算法或模型包的完整 ARN。ARN 必须采用上面提供的格式。ARN 模板中的星号确实代表通配符，涵盖了验证步骤中的所有训练作业、模型和批量转换作业，以及发布到 AI Marketplace 的算法和模型包。 SageMaker 

## SageMaker Neo
<a name="security-confused-deputy-neo"></a>

以下示例显示了如何使用`aws:SourceArn`全局条件密钥来防止由该*us-west-2*地区账号创建的 SageMaker Neo 编译任务出现跨服务混淆*123456789012*的代理问题。请注意，由于账号在 ARN 中，因此无需指定 `aws:SourceAccount` 值。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "sagemaker.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "ArnLike": {
          "aws:SourceArn": "arn:aws:sagemaker:us-west-2:123456789012:compilation-job/*"
        }
      }
    }
  ]
}
```

------

您可以将此模板中的 `aws:SourceArn` 替换为特定编译作业的完整 ARN，以进一步限制权限。

## SageMaker 管道
<a name="security-confused-deputy-pipelines"></a>

以下示例显示了如何使用`aws:SourceArn`全局条件键来防止使用来自一个或多个管道的管道执行记录的[SageMaker 管](https://docs.aws.amazon.com/sagemaker/latest/dg/pipelines-overview.html)道出现跨服务混淆副手问题。请注意，由于账号在 ARN 中，因此无需指定 `aws:SourceAccount` 值。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "sagemaker.amazonaws.com"
            },
            "Action": "sts:AssumeRole",
            "Condition": {
                "ArnLike": {
                    "aws:SourceArn": "arn:aws:sagemaker:us-east-1:123456789012:pipeline/mypipeline/*"
                }
            }
        }
    ]
}
```

------

请勿将此模板中的 `aws:SourceArn` 替换为特定管道执行的完整 ARN。ARN 必须采用上面提供的格式。`partition`占位符应指定 AWS 商业分区 (`aws`) 或中国分区 (`aws-cn`)，具体取决于管道的运行位置。 AWS 同样，ARN 中的`region`占位符可以是[任何可用管道的有效](https://docs.aws.amazon.com/sagemaker/latest/dg/regions-quotas.html) SageMaker 区域。

ARN 模板中的星号代表通配符，涵盖名为 `mypipeline` 的管道的所有管道执行。如果要允许账户 `123456789012` 中的所有管道而不是某个特定管道使用 `AssumeRole` 权限，则 `aws:SourceArn` 应为 `arn:aws:sagemaker:*:123456789012:pipeline/*`。

## SageMaker 处理作业
<a name="security-confused-deputy-processing-job"></a>

以下示例显示了如何使用`aws:SourceArn`全局条件键来防止 SageMaker 处理由该*us-west-2*地区账号创建的作业时出现跨服务混淆*123456789012*的代理问题。请注意，由于账号在 ARN 中，因此无需指定 `aws:SourceAccount` 值。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "sagemaker.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "ArnLike": {
          "aws:SourceArn": "arn:aws:sagemaker:us-west-2:123456789012:processing-job/*"
        }
      }
    }
  ]
}
```

------

您可以将此模板中的 `aws:SourceArn` 替换为特定处理作业的完整 ARN，以进一步限制权限。

## SageMaker 工作室
<a name="security-confused-deputy-studio"></a>

以下示例显示了如何使用`aws:SourceArn`全局条件密钥来防止 SageMaker Studio 出现跨服务混淆代理问题，该问题是由该*123456789012**us-west-2*地区的账号造成的。请注意，由于账号是 `aws:SourceArn` 值的一部分，因此您无需指定 `aws:SourceAccount` 值。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "sagemaker.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "ArnLike": {
          "aws:SourceArn": "arn:aws:sagemaker:us-west-2:123456789012:*"
        }
      }
    }
  ]
}
```

------

请勿将此模板中的 `aws:SourceArn` 替换为特定 Studio 应用程序、用户配置文件或域的完整 ARN。ARN 必须采用前面示例中提供的格式。ARN 模板中的星号不代表通配符，不应更改。

## SageMaker 培训职位
<a name="security-confused-deputy-training-job"></a>

以下示例显示了如何使用`aws:SourceArn`全局条件密钥来防止在 SageMaker 培训由该*us-west-2*地区账号创建的作业时出现跨服务混淆*123456789012*的代理问题。请注意，由于账号在 ARN 中，因此无需指定 `aws:SourceAccount` 值。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "sagemaker.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "ArnLike": {
          "aws:SourceArn": "arn:aws:sagemaker:us-west-2:123456789012:training-job/*"
        }
      }
    }
  ]
}
```

------

您可以将此模板中的 `aws:SourceArn` 替换为特定训练作业的完整 ARN，以进一步限制权限。

**后续步骤**  
有关管理执行角色的更多信息，请参阅 [SageMaker AI 角色](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-roles)。