管理设置 CMEK
使用 Admin API 添加并附加加密密钥
通过三次 Admin API 调用创建、验证并附加客户管理的加密密钥。
这些调用适用于 Claude Platform。在 Claude Enterprise 或 Claude Platform on AWS 上,请按照您的设置页面操作。
创建外部密钥即 Claude Console 中 Add key 所执行的操作,验证外部密钥即 Verify 所执行的操作。
开始之前
- 已为您的组织启用 "customer-managed encryption keys"(客户管理的加密密钥),即 CMEK。
- 您拥有一个 Admin API 密钥。示例从
ANTHROPIC_API_KEY读取该密钥。 - 您已在 AWS KMS、Google Cloud KMS 或 Azure Key Vault 中创建了您的密钥,并保存了设置步骤中要求您复制的值。
- 您有一个保留数据的工作区,最好是新工作区,因为现有数据仍受 Anthropic 的密钥保护。
创建、验证并附加您的密钥
创建外部密钥
将
<friendly-name>替换为显示名称,将<key-arn-from-create-key-step>替换为密钥 ARN。Pythonclient = anthropic.Anthropic() external_key = client.organization.external_keys.create( display_name="<friendly-name>", geo="us", provider_config={"type": "aws", "kms_arn": "<key-arn-from-create-key-step>"}, ) print(f"id: {external_key.id}") print(f"display_name: {external_key.display_name}")将
<friendly-name>替换为显示名称。将以projects/开头的值替换为完整的密钥资源名称。Pythonclient = anthropic.Anthropic() external_key = client.organization.external_keys.create( display_name="<friendly-name>", geo="us", provider_config={ "type": "gcp", "key_name": "projects/<your-project-id>/locations/<region>/keyRings/<your-keyring-name>/cryptoKeys/<your-key-name>", }, ) print(f"id: {external_key.id}") print(f"display_name: {external_key.display_name}")替换以下占位符:
<friendly-name>:显示名称https://<your-vault-name>.vault.azure.net/:保管库 URI<your-key-name>:密钥名称<your-tenant-id>:保管库的租户 ID
Pythonclient = anthropic.Anthropic() external_key = client.organization.external_keys.create( display_name="<friendly-name>", geo="us", provider_config={ "type": "azure", "vault_uri": "https://<your-vault-name>.vault.azure.net/", "key_name": "<your-key-name>", "tenant_id": "<your-tenant-id>", }, ) print(f"id: {external_key.id}") print(f"display_name: {external_key.display_name}")响应中的
id即外部密钥 ID。请复制它,以用于接下来的两个步骤。{ "type": "external_key", "id": "ekey_<id>", "display_name": "<friendly-name>" }验证密钥
将
ekey_<id>替换为外部密钥 ID。Pythonclient = anthropic.Anthropic() validation = client.organization.external_keys.validate("ekey_<id>") print(f"status: {validation.status}") print(f"error: {validation.error}")成功的响应如下所示:
{ "type": "external_key_validation", "status": "success", "error": null }如果
status为failure,error字段会说明原因。请参阅 CMEK 故障排除。将密钥附加到工作区
将
<workspace-id>替换为工作区 ID(以wrkspc_开头),并将ekey_<id>替换为外部密钥 ID。Pythonclient = anthropic.Anthropic() workspace = client.organization.workspaces.update( "<workspace-id>", external_key_id="ekey_<id>" ) print(f"id: {workspace.id}") print(f"external_key_id: {workspace.external_key_id}")响应会在
external_key_id中显示已附加密钥的 ID。如果请求被拒绝,请查找该错误。
Was this page helpful?