

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

# 为 Amazon SageMaker 模型卡设置跨账户支持
<a name="model-cards-xaccount"></a>

使用 Amazon SageMaker 模型卡片中的跨账户支持在 Amazon 账户之间共享模型卡。创建模型卡的账户是*模型卡账户*。模型卡账户中的用户与*共享账户* 共享模型卡。共享账户中的用户可以更新模型卡片或创建 PDFs 模型卡。

模型卡账户中的用户通过 Amazon Resource Access Manager (Amazon RAM) 共享他们的模型卡。 Amazon RAM 帮助您跨 Amazon 账户共享资源。有关简介 Amazon RAM，请参阅[什么是 Amazon Resource Access Manager？](https://docs.amazonaws.cn/ram/latest/userguide/what-is.html)

以下是共享模型卡的过程：

1. 模型卡账户中的用户使用 Amazon Resource Access Manager设置跨账户模型卡共享。

1. 如果模型卡使用 Amazon KMS 密钥加密，则设置模型共享的用户还必须为共享账户中的用户提供 Amazon KMS 权限。

1. 共享账户中的用户接受资源共享的邀请。

1. 共享账户中的用户向其他用户提供访问模型卡的权限。

如果您是模型卡账户中的用户，请参阅以下章节：
+ [设置跨账户模型卡共享](#model-cards-xaccount-set-up)
+ [为共享账户设置 Amazon KMS 权限](#model-cards-xaccount-kms)
+ [获取对资源共享邀请的回复](#model-cards-xaccount-set-up-responses)

如果您是共享账户中的用户，请参阅[在共享账户中设置 IAM 用户权限](#model-cards-xaccount-shared-account-permissions)，了解如何为自己和账户中的其他用户设置权限。

## 设置跨账户模型卡共享
<a name="model-cards-xaccount-set-up"></a>

使用 Amazon Resource Access Manager (Amazon RAM) 授予您 Amazon 账户中的用户查看或更新在其他 Amazon 账户中创建的模型卡片的权限。

要设置模型卡共享，必须创建资源共享。资源共享指定：
+ 所共享的资源
+ 有权访问资源的人或物
+ 资源的托管权限

有关资源共享的更多信息，请参阅 [Amazon RAM的术语和概念](https://docs.amazonaws.cn/ram/latest/userguide/getting-started-terms-and-concepts.html)。我们建议您在完成创建资源共享的过程之前，花点时间 Amazon RAM 从概念上进行理解。

**重要**  
您必须拥有创建资源共享的权限。有关权限的更多信息，请参阅[如何 Amazon RAM 使用 IAM](https://docs.amazonaws.cn/ram/latest/userguide/security-iam-policies.html)。

有关创建资源共享的过程以及有关这些过程的其他信息，请参阅[创建资源共享](https://docs.amazonaws.cn/ram/latest/userguide/getting-started-sharing.html#getting-started-sharing-create)。

在创建资源共享的过程中，您需要指定 `sagemaker:ModelCard` 作为资源类型。您还必须指定基于资源的策略的 Amazon 资源编号 (ARN)。 Amazon RAM 您可以指定默认策略，也可以指定具有创建模型卡 PDF 的其他权限的策略。

使用默认的基于 `AWSRAMPermissionSageMakerModelCards` 资源的策略，共享账户中的用户有权执行以下操作：
+  [DescribeModelCard](https://docs.amazonaws.cn/sagemaker/latest/APIReference/API_DescribeModelCard.html)
+ [ListModelCardVersions](https://docs.amazonaws.cn/sagemaker/latest/APIReference/API_ListModelCardVersions.html)
+ [UpdateModelCard](https://docs.amazonaws.cn/sagemaker/latest/APIReference/API_UpdateModelCard.html)

使用基于 `AWSRAMPermissionSageMakerModelCardsAllowExport` 资源的策略，共享账户中的用户有权执行上述所有操作。他们还有权创建模型卡导出作业并通过以下操作对其进行描述：
+ [CreateModelCardExportJob](https://docs.amazonaws.cn/sagemaker/latest/APIReference/API_CreateModelCardExportJob.html)
+ [DescribeModelCardExportJob](https://docs.amazonaws.cn/sagemaker/latest/APIReference/API_DescribeModelCardExportJob.html)

共享账户中的用户可以创建导出作业以生成模型卡的 PDF。他们还可以描述为查找 PDF 的 Amazon S3 URI 而创建的导出作业。

模型卡和导出作业是资源。模型卡账户拥有共享账户中的用户创建的导出作业。例如，账户 A 中的用户与共享账户 B 共享模型卡 X。账户 B 中的用户为模型卡 X 创建导出作业 Y，将输出结果存储在账户 B 中用户指定的 Amazon S3 位置。尽管账户 B 创建了导出作业 Y，但它属于账户 A。

每个 Amazon 账户都有资源配额。有关与模型卡相关的配额的信息，请参阅 [Amazon A SageMaker I 终端节点和配额](https://docs.amazonaws.cn/general/latest/gr/sagemaker.html#limits_sagemaker)。

### 为共享账户设置 Amazon KMS 权限
<a name="model-cards-xaccount-kms"></a>

如果您共享的模型卡已使用 Amazon Key Management Service 密钥加密，则还需要与共享帐户共享对密钥的访问权限。否则，共享账户中的用户将无法查看、更新或导出模型卡。有关概述 Amazon KMS，请参阅[Amazon Key Management Service](https://docs.amazonaws.cn/kms/latest/developerguide/overview.html)。

要向共享账户中的用户提供 Amazon KMS 权限，请使用以下声明更新您的密钥策略：

```
{
    "Effect": "Allow",
    "Principal": {
        "AWS": [
            "arn:aws:iam::shared-account-id::role/example-IAM-role"
        ]
    },
    "Action": [
        "kms:GenerateDataKey",
        "kms:Decrypt",
    ]
    "Resource": "arn:aws:kms:Amazon-Region-of-model-card-account:model-card-account-id:key/Amazon KMS-key-id"
    "Condition": {
        "Bool": {"kms:GrantIsForAWSResource": true },
        "StringEquals": {
            "kms:ViaService": [
                "sagemaker.Amazon-Region.amazonaws.com", 
                "s3.Amazon-Region.amazonaws.com"
            ],
        },
        "StringLike": {
          "kms:EncryptionContext:aws:sagemaker:model-card-arn": "arn:aws:sagemaker:Amazon-Region:model-card-account-id:model-card/model-card-name"
        }
    }    
}
```

上述语句为共享账户中的用户提供了 `kms:Decrypt` 和 `kms:GenerateDataKey` 权限。使用 `kms:Decrypt`，用户可以解密模型卡。使用`kms:GenerateDataKey`，用户可以加密他们更新的或他们创建 PDFs 的模型卡。

### 获取对资源共享邀请的回复
<a name="model-cards-xaccount-set-up-responses"></a>

创建资源共享后，您在资源共享中指定的共享账户会收到加入该共享的邀请。这些账户必须接受邀请才能访问资源。

有关接受资源共享邀请的信息，请参阅 [Resource Acc *ess Manager 用户指南*中的使用共享 Amazon 资源](https://docs.amazonaws.cn/ram/latest/userguide/getting-started-shared.html)。Amazon 

### 在共享账户中设置 IAM 用户权限
<a name="model-cards-xaccount-shared-account-permissions"></a>

以下信息假设您已接受模型卡账户发出的资源共享邀请。有关接受资源共享邀请的更多信息，请参阅[使用共享 Amazon 资源](https://docs.amazonaws.cn/ram/latest/userguide/getting-started-shared.html)。

您和您账户中的其他用户使用 IAM 角色访问从模型卡账户共享的模型卡。使用以下模板更改 IAM 角色的策略。您可以根据自己的使用案例修改模板。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:DescribeModelCard",
                "sagemaker:UpdateModelCard",
                "sagemaker:CreateModelCardExportJob",
                "sagemaker:ListModelCardVersions",
                "sagemaker:DescribeModelCardExportJob"
            ],
            "Resource": [
                "arn:aws:sagemaker:us-east-1:111122223333:model-card/example-model-card-name-0",
                "arn:aws:sagemaker:us-east-1:111122223333:model-card/example-model-card-name-1/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket-storing-the-pdf-of-the-model-card/model-card-name/*"
        }
    ]
}
```

------

要访问使用加密的模型卡 Amazon KMS，您必须为账户中的用户提供以下 Amazon KMS 权限。

```
{
     "Effect": "Allow",
     "Action": [
         "kms:GenerateDataKey",
         "kms:Decrypt",
     ],
     "Resource": "arn:aws:kms:Amazon-Region:Amazon-account-id-where-the-model-card-is-created:key/Amazon Key Management Service-key-id"
}
```