管理設定 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>替換為以wrkspc_開頭的工作區 ID,並將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?