Claude Platform Docs
管理設定 CMEK

使用 Admin API 新增並附加加密金鑰

透過三個 Admin API 呼叫,建立、驗證並附加客戶管理的加密金鑰。

這些呼叫適用於 Claude Platform。若您使用 Claude Enterprise 或 Claude Platform on AWS,請依照您的設定頁面操作。

建立外部金鑰,即相當於在 Claude Console 中執行 Add key;驗證該金鑰,即相當於執行 Verify。

開始之前

建立、驗證並附加金鑰

  1. 建立外部金鑰

    將 <friendly-name> 替換為顯示名稱,並將 <key-arn-from-create-key-step> 替換為金鑰 ARN。

    client = 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}")

    回應中的 id 即為外部金鑰 ID。請複製它以用於接下來的兩個步驟。

    {
      "type": "external_key",
      "id": "ekey_<id>",
      "display_name": "<friendly-name>"
    }
  2. 驗證金鑰

    將 ekey_<id> 替換為外部金鑰 ID。

    client = 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。

  3. 將金鑰附加至工作區

    請將 <workspace-id> 替換為以 wrkspc_ 開頭的工作區 ID,並將 ekey_<id> 替換為外部金鑰 ID。

    client = 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?