

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

# 使用客戶自管金鑰 (CMK)
<a name="import-model-using-cmk"></a>

如果您打算使用客戶自管金鑰來加密自訂匯入的模型，請完成下列步驟：

1. 使用 AWS Key Management Service 建立客戶自管金鑰。

1. 連接具有指定角色許可的[資源型政策](https://docs.aws.amazon.com//IAM/latest/UserGuide/access_policies_identity-vs-resource.html)，以建立及使用自訂匯入模型。

**建立客戶自管金鑰**

請先確定您具備 `CreateKey` 許可。然後遵循[建立金鑰](https://docs.aws.amazon.com//kms/latest/developerguide/create-keys.html)的步驟，在AWS KMS主控台或 [CreateKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateKey.html) API 操作中建立客戶受管金鑰。請確保建立對稱加密金鑰。

建立金鑰會傳回金鑰的 `Arn`，您可以在匯入具有自訂模型匯入的自訂模型時，用來作為 `importedModelKmsKeyId `。

**建立金鑰政策並將其連接至客戶自管金鑰**

金鑰政策是您連接至客戶自管金鑰以控制其存取的[資源型政策](https://docs.aws.amazon.com//IAM/latest/UserGuide/access_policies_identity-vs-resource.html)。每個客戶自管金鑰都必須只有一個金鑰政策，其中包含決定誰可以使用金鑰及其使用方式的陳述式。在建立客戶自管金鑰時，可以指定金鑰政策。您可以隨時修改金鑰政策，但變更在整個 AWS KMS 中變成可用之前，可能會有短暫的延遲。如需詳細資訊，請參閱《*AWS Key Management Service 開發人員指南*》中的[管理客戶自管金鑰的存取](https://docs.aws.amazon.com//kms/latest/developerguide/control-access-overview.html#managing-access)。

**加密匯入的自訂模型**

若要使用客戶受管金鑰來加密匯入的自訂模型，您必須在金鑰政策中包含下列AWS KMS操作：
+ [kms:CreateGrant](https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateGrant.html)：允許 Amazon Bedrock 服務主體透過[授予操作](https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#terms-grant-operations)存取指定的 KMS 金鑰，藉此為客戶自管金鑰建立授予。如需授予的詳細資訊，請參閱《AWS Key Management Service 開發人員指南》**中的 [AWS KMS 中的授予](https://docs.aws.amazon.com/kms/latest/developerguide/grants.html)。
**注意**  
Amazon Bedrock 也會設定淘汰主體，並在不再需要後自動淘汰授予。
+ [kms:DescribeKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_DescribeKey.html)：提供客戶自管金鑰的詳細資訊，以便 Amazon Bedrock 可以驗證金鑰。
+ [kms:GenerateDataKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKey.html)：提供客戶自管金鑰詳細資訊，以允許 Amazon Bedrock 驗證使用者存取。Amazon Bedrock 會將產生的密文與匯入的自訂模型一起存放，用作為對匯入的自訂模型使用者的額外驗證檢查。
+ [kms:Decrypt](https://docs.aws.amazon.com/kms/latest/APIReference/API_Decrypt.html)：解密儲存的密文，以驗證角色對加密匯入的自訂模型 KMS 金鑰是否具有適當的存取權。

以下是您可以連接到角色金鑰的範例政策，用於加密您匯入的模型：

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Id": "KMS key policy for a key to encrypt an imported custom model",
    "Statement": [
        {
            "Sid": "Permissions for model import API invocation role",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::111122223333:user/role"
            },
            "Action": [
                "kms:Decrypt",
                "kms:GenerateDataKey",
                "kms:DescribeKey",
                "kms:CreateGrant"
            ],
            "Resource": "*"
        }
    ]
}
```

------

**將加密的匯入自訂模型解密**

如果您要匯入已由其他客戶自管金鑰加密的自訂模型，則必須新增相同角色的 `kms:Decrypt` 許可，如下列政策中所示：

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Id": "KMS key policy for a key that encrypted a custom imported model",
    "Statement": [
        {
            "Sid": "Permissions for model import API invocation role",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::111122223333:user/role"
            },
            "Action": [
                "kms:Decrypt"
            ],
            "Resource": "*"
        }
    ]
}
```

------