

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

# 使用客戶自管金鑰 (CMK) 加密代理程式資源
<a name="cmk-agent-resources"></a>

您可以隨時使用建置代理程式時提供的下列代理程式資訊，建立客戶自管金鑰來加密代理程式的資訊。

**注意**  
系統只會針對 2025 年 1 月 22 日之後建立的代理程式加密下列代理程式資源。


****  


- **[CreateAgent](https://docs.aws.amazon.com//bedrock/latest/APIReference/API_agent_CreateAgent.html)**
  - **已啟用 CMK 的欄位:** instruction / **說明:** 指示代理程式應做什麼，以及其應如何與使用者互動
  - **已啟用 CMK 的欄位:** basePromptTemplate / **說明:** 定義要取代預設提示範本的提示範本

- **[CreateAgentActionGroup](https://docs.aws.amazon.com//bedrock/latest/APIReference/API_agent_CreateAgentActionGroup.html)**
  - **已啟用 CMK 的欄位:** description / **說明:** 動作群組的描述
  - **已啟用 CMK 的欄位:** [apiSchema](https://docs.aws.amazon.com//bedrock/latest/APIReference/API_agent_APISchema.html) / **說明:** 包含代理程式動作群組的 apiSchema 詳細資訊，或定義結構描述的 JSON 或 YAML 格式承載
  - **已啟用 CMK 的欄位:** [s3](https://docs.aws.amazon.com//bedrock/latest/APIReference/API_agent_APISchema.html) / **說明:** 包含 Amazon S3 物件的詳細資訊，其中包含代理程式動作群組的 apiSchema
  - **已啟用 CMK 的欄位:** functionSchema / **說明:** 包含代理程式動作群組的函數結構描述詳細資訊，或定義結構描述的 JSON-YAML 格式承載

- **[AssociateAgentKnowledgeBase](https://docs.aws.amazon.com//bedrock/latest/APIReference/API_agent_AssociateAgentKnowledgeBase.html)**
  - **已啟用 CMK 的欄位:** description
  - **說明:** 代理程式應如何使用知識庫的說明

- **[AssociateAgentCollaborator](https://docs.aws.amazon.com//bedrock/latest/APIReference/API_agent_AssociateAgentCollaborator.html)**
  - **已啟用 CMK 的欄位:** collaborationInstruction
  - **說明:** 協作者代理程式的指示



若要使用客戶自管金鑰，請完成下列步驟：

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

1. 建立金鑰政策並連接至客戶自管金鑰

## 建立客戶自管金鑰
<a name="create-cmk-agent"></a>

您可以使用 AWS 管理主控台或 AWS Key Management Service APIs 來建立對稱客戶受管金鑰。

 首先確定您擁有 `CreateKey` 許可，然後遵循《AWS Key Management Service 開發人員指南》**中的[建立對稱客戶自管金鑰](https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html#create-symmetric-cmk)步驟。

**金鑰政策**：金鑰政策會控制客戶自管金鑰的存取權限。每個客戶受管金鑰都必須只有一個金鑰政策，其中包含決定誰可以使用金鑰及其使用方式的陳述式。在建立客戶受管金鑰時，可以指定金鑰政策。如需詳細資訊，請參閱《AWS Key Management Service 開發人員指南》**中的[管理客戶自管金鑰的存取權限](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html)。

如果您在 2025 年 1 月 22 日之後建立代理程式，並想要使用客戶自管金鑰來加密代理程式的資訊，請確定呼叫代理程式 API 操作的使用者或角色在金鑰政策中具有下列許可：
+ [kms:GenerateDataKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKey.html)：傳回可在 AWS KMS 外部使用的唯一對稱資料金鑰。
+ [kms:Decrypt](https://docs.aws.amazon.com/kms/latest/APIReference/API_Decrypt.html)：解密 KMS 金鑰加密的密文。

建立金鑰會傳回 `Arn` 作為金鑰，您可以在建立代理程式時使用該金鑰作為 `customerEncryptionKeyArn`。

## 建立金鑰政策並將其連接至客戶自管金鑰
<a name="attach-policy-agent"></a>

如果使用客戶自管金鑰加密代理程式資源，您必須設定身分型政策和資源型政策，以允許 Amazon Bedrock 代表您加密和解密代理程式資源。

**身分型政策**

將下列身分型政策連接至具有許可的 IAM 角色或使用者，以呼叫代表您加密和解密代理程式資源的代理程式 API。此政策會驗證發出 API 呼叫的使用者具有 AWS KMS 許可。將 `${region}`、`${account-id}`、`${agent-id}` 和 `${key-id}` 取代為適當的值。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "EncryptAgents",
            "Effect": "Allow",
            "Action": [
                "kms:GenerateDataKey",
                "kms:Decrypt"
            ],
            "Resource": "arn:aws:kms:{{us-east-1}}:{{123456789012}}:key/${key-id}",
            "Condition": {
                "StringEquals": {
                    "kms:EncryptionContext:aws:bedrock:arn": "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:agent/${agent-id}"
                }
            }
        }
    ]
}
```

------

**以資源為基礎的政策**

*只有在*您建立 Amazon S3 中結構描述已加密的動作群組時，才能將下列資源型政策連接至您的 AWS KMS 金鑰。您不需要為任何其他使用案例連接資源型政策。

若要連接下列資源型政策，請視需要變更許可範圍，並以適當的值取代 `${region}`、`${account-id}`、`${agent-id}` 和 `${key-id}`。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "Allow account root to modify the KMS key, not used by Amazon Bedrock.",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::{{111122223333}}:root"
            },
            "Action": "kms:*",
            "Resource": "arn:aws:kms:{{us-east-1}}:{{123456789012}}:key/${key-id}"
        },
        {
            "Sid": "Allow Amazon Bedrock to encrypt and decrypt Agent resources on behalf of authorized users",
            "Effect": "Allow",
            "Principal": {
                "Service": "bedrock.amazonaws.com"
            },
            "Action": [
                "kms:GenerateDataKey",
                "kms:Decrypt"
            ],
            "Resource": "arn:aws:kms:{{us-east-1}}:{{123456789012}}:key/${key-id}",
            "Condition": {
                "StringEquals": {
                    "kms:EncryptionContext:aws:bedrock:arn": "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:agent/${agent-id}"
                }
            }
        }
    ]
}
```

------

## 變更客戶自管金鑰
<a name="change-cmk"></a>

當與 *DRAFT* 代理程式相關聯的客戶受管金鑰變更時，或當您從客戶受管金鑰移至 AWS 擁有的金鑰時，Amazon Bedrock 代理程式不支援版本控制的代理程式重新加密。只會使用新金鑰重新加密 *DRAFT* 資源的資料。

如果使用版本控制的代理程式來提供生產資料，請確定您不會刪除或移除其任何金鑰的許可。

若要檢視和驗證版本所使用的金鑰，請呼叫 [GetAgentVersion](https://docs.aws.amazon.com//bedrock/latest/APIReference/API_agent_GetAgentVersion.html) 並檢查回應中的 `customerEncryptionKeyArn`。