為沙箱設定客戶自行管理的加密金鑰 (CMEK)

使用您擁有及控管的 Cloud Key Management Service 金鑰,加密沙箱的靜態資料。

總覽

根據預設, Google Cloud 會使用 Google-owned and Google-managed encryption keys加密靜態資料。客戶自行管理的加密金鑰 (CMEK) 可讓您建立及管理 Cloud KMS 加密金鑰,以便稽核金鑰使用情形、輪替金鑰,以及停用或刪除金鑰,讓受保護的資料無法讀取。

Gemini Enterprise Agent Platform 沙箱會在隔離環境中執行代理的程式碼、瀏覽器或自訂容器。該環境會將客戶內容寫入磁碟,並可建立檢查點來建立快照。在沙箱的上層 Gemini Enterprise Agent Platform 執行個體啟用 CMEK 後,CMEK 就會保護這些快照。

您只能在建立 Gemini Enterprise Agent Platform 執行個體時,為 Gemini Enterprise Agent Platform 沙箱設定 CMEK。CMEK 金鑰會保護 Gemini Enterprise Agent Platform 執行個體及其子資源,包括沙箱環境、範本和快照。

CMEK 為沙箱加密的內容

在父項 Gemini Enterprise Agent Platform 執行個體啟用 CMEK 後,沙箱的靜態介面會以您的金鑰加密:

  • GKE 節點開機磁碟/根檔案系統:工作階段在執行階段寫入的檔案,以及分頁至磁碟的記憶體內狀態 (節點開機磁碟 CMEK)。
  • 快照 Cloud Storage bucket:沙箱的磁碟和記憶體檢查點 (快照) (bucket 預設加密)。

資源中繼資料 (名稱、標籤、狀態、連線資訊)、環境變數和服務帳戶電子郵件,則不會以 CMEK 金鑰加密。

如要加密自訂容器映像檔,請在自己的 Artifact Registry 存放區設定 CMEK。

限制和注意事項

  • Gemini Enterprise Agent Platform 的 CMEK 僅支援單一區域金鑰。不支援多區域、雙區域和全域金鑰。
  • 建立 Gemini Enterprise Agent Platform 執行個體後,金鑰即無法變更。如要使用其他金鑰,請建立新的 Gemini Enterprise Agent Platform 執行個體。系統支援輪替至相同金鑰的新版本,並會自動套用。
  • 如果停用或刪除金鑰版本,或撤銷加密者/解密者角色,就無法佈建或繼續使用沙箱,且快照寫入作業會失敗。還原金鑰存取權,即可復原沙箱資源。

事前準備

  • 擁有或建立 Cloud KMS 金鑰環和金鑰。最佳做法是將金鑰與 Gemini Enterprise Agent Platform 工作負載分開,存放在由不同管理員管理的專案中。
  • 確認您具備建立及管理金鑰 (roles/cloudkms.admin) 的角色,以及建立 Gemini Enterprise Agent Platform 執行個體的角色。
  • 如果尚未建立 Agent Runtime 服務代理,請先建立:

    # Create the service agent if needed
    gcloud beta services identity create \
        --service=aiplatform.googleapis.com \
        --project=PROJECT_ID
    

建立 Cloud KMS 金鑰

在 Gemini Enterprise Agent Platform 執行個體所在的區域,建立單一區域金鑰:

# Key ring (once per region)
gcloud kms keyrings create sandbox-keyring \
    --location=REGION

# Key
gcloud kms keys create sandbox-key \
    --location=REGION \
    --keyring=sandbox-keyring \
    --purpose=encryption

更改下列內容:

  • REGION:Gemini Enterprise Agent Platform 執行個體的 Google Cloud 區域 (例如 us-central1)。

授予 Agent Platform 服務代理金鑰存取權

將金鑰的 Cloud KMS CryptoKey 加密者/解密者角色 (roles/cloudkms.cryptoKeyEncrypterDecrypter) 授予 Agent Runtime 服務代理:

# Grant Encrypter/Decrypter on the key
gcloud kms keys add-iam-policy-binding sandbox-key \
    --location=REGION \
    --keyring=sandbox-keyring \
    --member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-aiplatform-re.iam.gserviceaccount.com" \
    --role="roles/cloudkms.cryptoKeyEncrypterDecrypter"

更改下列內容:

  • PROJECT_NUMBER:您的 Google Cloud 專案編號。

在 Agent Platform 執行個體啟用 CMEK

建立 Gemini Enterprise Agent Platform 執行個體時,請設定 encryption_spec.kms_key_name。您建立的每個沙箱範本和沙箱都會沿用這個金鑰。

Python SDK

import vertexai

client = vertexai.Client(project="PROJECT_ID", location="REGION",
                        http_options={"api_version": "v1beta1"})
agent_instance = client.agent_engines.create(
    config={
        "encryption_spec": {
            "kms_key_name":
                "projects/PROJECT_ID/locations/REGION/keyRings/sandbox-keyring/cryptoKeys/sandbox-key"
        }
    },
)

REST

使用 REST API,在建立時將 reasoningEngines.encryptionSpec.kmsKeyName 設為相同的值:

curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  https://REGION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/reasoningEngines \
  -d '{
    "display_name": "cmek-protected-engine",
    "encryption_spec": {
      "kms_key_name": "projects/PROJECT_ID/locations/REGION/keyRings/sandbox-keyring/cryptoKeys/sandbox-key"
    }
  }'

建立沙箱並驗證 CMEK 設定

  1. 在受 CMEK 保護的 Gemini Enterprise Agent Platform 執行個體中,建立沙箱範本和沙箱。
  2. 取得執行個體詳細資料,確認 Gemini Enterprise Agent Platform 執行個體在 encryption_spec.kms_key_name 中回報金鑰。
  3. 您也可以查看 Cloud KMS 稽核記錄,確認沙箱啟動和寫入快照時,是否執行加密和解密作業。

後續步驟