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

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

總覽

預設會使用 Cloud de Confiance by S3NS 對靜態資料加密 Google Cloud-powered encryption keys。客戶管理的加密金鑰 (CMEK) 可讓您建立及管理 Cloud Key Management Service 加密金鑰,以便稽核金鑰的使用情形、輪替金鑰,以及停用或刪除金鑰,讓受保護的資料無法讀取。

Gemini Enterprise Agent Platform 沙箱會在獨立環境中執行代理的程式碼、瀏覽器或自訂容器。該環境會將客戶內容寫入磁碟,並可檢查點至快照,當您在沙箱的父項 Gemini Enterprise Agent Platform 執行個體上啟用 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 Key Management Service 金鑰環和金鑰。最佳做法是將金鑰放在與 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 Key Management Service 金鑰

在與 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 執行個體的 Cloud de Confiance 區域 (例如 us-central1)。

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

將 Cloud Key Management Service CryptoKey Encrypter/Decrypter 角色 (roles/cloudkms.cryptoKeyEncrypterDecrypter) 授予 Agent 執行階段服務代理人:

# 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.s3ns-system.iam.gserviceaccount.com" \
    --role="roles/cloudkms.cryptoKeyEncrypterDecrypter"

更改下列內容:

  • PROJECT_NUMBER:您的 Cloud de Confiance by S3NS 專案編號。

在 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. encryption_spec.kms_key_name取得執行個體詳細資料,確認 Gemini Enterprise Agent Platform 執行個體會回報金鑰。
  3. 您也可以查看 Cloud Key Management Service 稽核記錄,確認加密和解密作業是在沙箱啟動和寫入快照時執行。

後續步驟