Crittografare i dati con chiavi di crittografia gestite dal cliente
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questo documento mostra come utilizzare le chiavi di crittografia gestite dal cliente (CMEK) per
criptare e controllare i dati archiviati in un servizio cloud tramite
Cloud Key Management Service. CMEK è integrato con la
personalizzazione del codice
Gemini Code Assist non supporta l'utilizzo di chiavi
Cloud EKM.
In questo documento imparerai a:
Scopri come creare una chiave CMEK.
Concedi le autorizzazioni al account di servizio Gemini Code Assist.
Crea un indice del repository di codice con una CMEK.
Rimuovi l'accesso a un repository CMEK.
Per impostazione predefinita, Gemini in Google Cloud cripta i contenuti inattivi dei clienti. Gemini gestisce la crittografia per conto tuo senza che tu debba fare altro. Questa opzione è denominata Crittografia predefinita di Google.
Se vuoi controllare le tue chiavi di crittografia, puoi utilizzare le chiavi di crittografia gestite dal cliente (CMEK) in Cloud KMS con servizi integrati con CMEK, tra cui Gemini. L'utilizzo delle chiavi Cloud KMS ti consente di controllare il livello di protezione, la posizione, la pianificazione della rotazione, l'utilizzo e le autorizzazioni di accesso e i limiti crittografici.
L'utilizzo di Cloud KMS consente anche di visualizzare i log di controllo e controllare i cicli di vita delle chiavi.
Anziché essere di proprietà di Google e gestite da Google, le chiavi di crittografia delle chiavi (KEK) simmetriche che proteggono i tuoi dati sono controllate e gestite da te in Cloud KMS.
Dopo aver configurato le risorse con le chiavi CMEK, l'esperienza di accesso alle risorse Gemini è simile all'utilizzo della crittografia predefinita di Google.
Per saperne di più sulle opzioni di crittografia, consulta Chiavi di crittografia gestite dal cliente (CMEK).
Prima di iniziare
In the Google Cloud console, activate Cloud Shell.
Nell'ambiente shell, esegui il
comando gcloud components update
per assicurarti di aver aggiornato tutti i componenti installati di
gcloud CLI all'ultima versione. Per
questo passaggio, puoi installare e inizializzare gcloud CLI oppure puoi
utilizzare Cloud Shell.
gcloudcomponentsupdate
Crea una chiave CMEK e concedi le autorizzazioni
Per creare una chiave CMEK e concedere all'account di servizio Gemini Code Assist
le autorizzazioni sulla chiave, esegui le seguenti attività:
Nel progetto Google Cloud in cui vuoi gestire le chiavi, procedi come segue:
Concedi l'accesso al account di servizio Gemini Code Assist:
Fai clic su Aggiungi entità.
Aggiungi il account di servizio Gemini Code Assist. L'account di servizio è service-PROJECT_NUMBER@gcp-sa-cloudaicompanions.iam.gserviceaccount.com,
dove PROJECT_NUMBER è il
numero di progetto
del progetto Google Cloud in cui
è abilitato Gemini Code Assist.
In Seleziona un ruolo, seleziona Cloud KMS >
Autore crittografia/decrittografia CryptoKey Cloud KMS.
Fai clic su Salva.
Ripeti il passaggio precedente per concedere l'accesso all'account che creerà l'indice del repository di codice con una chiave di crittografia gestita dal cliente.
Torna alla pagina Gestione chiavi e seleziona di nuovo la chiave.
Seleziona Mostra riquadro informazioni. Dovresti visualizzare i ruoli nella
colonna Ruolo/Membro.
Interfaccia a riga di comando gcloud
Per concedere l'accesso all'account di servizio Gemini Code Assist, in un ambiente shell, utilizza il comando kms keys add-iam-policy-binding:
PROJECT_ID: l'ID del progetto che contiene la chiave.
LOCATION: la posizione della chiave.
KEYRING_NAME: il nome del keyring.
PROJECT_NUMBER: il numero di progetto
del progetto Google Cloud con
Gemini Code Assist abilitato.
Ripeti il passaggio precedente per concedere l'accesso all'account che creerà l'indice del repository di codice con una chiave di crittografia gestita dal cliente.
JSON_FILE_NAME: il percorso del file JSON che hai creato nel passaggio precedente.
PROJECT_ID: l'ID del progetto in cui creare
il repository.
KEY_LOCATION: la località in cui creare il
repository, che deve corrispondere alla località in cui esiste la chiave CMEK.
CODE_REPOSITORY_INDEX_NAME: il nome del
nuovo indice del repository di codice che creerai. Ad esempio,
zg-btf-0001.
La risposta restituisce un insieme di voci di log.
Rimuovere l'accesso a un repository CMEK
Esistono diversi modi per rimuovere l'accesso a un repository criptato con CMEK:
Revoca il ruolo Autore crittografia/decriptazione CryptoKey Cloud KMS dall'account di servizio Gemini Code Assist utilizzando la consoleGoogle Cloud ogcloud CLI.
Ti consigliamo di revocare le autorizzazioni dall'account di servizio
Gemini Code Assist prima di disattivare o eliminare
una chiave. Le modifiche alle autorizzazioni sono coerenti in pochi secondi, quindi puoi osservare
gli effetti della disattivazione o dell'eliminazione di una chiave.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eCustomer-managed encryption keys (CMEKs) allow users to encrypt and control their data-at-rest in cloud services, offering greater control over encryption than the default Google encryption.\u003c/p\u003e\n"],["\u003cp\u003eTo use CMEKs with Gemini Code Assist, users must create a CMEK, grant the Gemini Code Assist service account the CryptoKey Encrypter/Decrypter IAM role, and then create a code repository index using the CMEK.\u003c/p\u003e\n"],["\u003cp\u003eCMEK setup provides users with control over the key's protection level, location, rotation, usage, access permissions, cryptographic boundaries, audit logs, and key life cycles.\u003c/p\u003e\n"],["\u003cp\u003eRemoving access to a CMEK repository can be achieved by revoking the necessary permissions from the Gemini Code Assist service account, temporarily disabling the CMEK, or permanently destroying it.\u003c/p\u003e\n"],["\u003cp\u003eGemini Code Assist code customization is only available in Gemini Code Assist Enterprise edition, as a side note.\u003c/p\u003e\n"]]],[],null,["| **Note:** Gemini Code Assist code customization is available only in Gemini Code Assist Enterprise. For more information, see [Gemini Code Assist supported features](/gemini/docs/codeassist/overview#supported-features).\n\nThis document shows how to use customer-managed encryption keys (CMEK) to\nencrypt and control data-at-rest in a cloud service through\n[Cloud Key Management Service](https://cloud.google.com/kms/docs). CMEK is integrated with\n\n[code customization](/gemini/docs/codeassist/code-customization-overview) for\nGemini Code Assist.\nGemini Code Assist doesn't support the use of\n[Cloud EKM](https://cloud.google.com/kms/docs/ekm) keys.\n\nIn this document, you do the following:\n\n- Learn how to create a CMEK.\n- Grant permissions to the Gemini Code Assist service account.\n- Create a code repository index with a CMEK.\n- Remove access to a CMEK repository.\n\nBy default, Gemini for Google Cloud encrypts customer content at\nrest. Gemini handles encryption for you without any\nadditional actions on your part. This option is called *Google default encryption*.\n\nIf you want to control your encryption keys, then you can use customer-managed encryption keys\n(CMEKs) in [Cloud KMS](/kms/docs) with CMEK-integrated services including\nGemini. Using Cloud KMS keys gives you control over their protection\nlevel, location, rotation schedule, usage and access permissions, and cryptographic boundaries.\nUsing Cloud KMS also lets\nyou view audit logs and control key lifecycles.\n\nInstead of Google owning and managing the symmetric\n[key encryption keys (KEKs)](/kms/docs/envelope-encryption#key_encryption_keys) that protect your data, you control and\nmanage these keys in Cloud KMS.\n\nAfter you set up your resources with CMEKs, the experience of accessing your\nGemini resources is similar to using Google default encryption.\nFor more information about your encryption\noptions, see [Customer-managed encryption keys (CMEK)](/kms/docs/cmek).\n\nBefore you begin\n\n1. In the Google Cloud console, activate Cloud Shell.\n\n [Activate Cloud Shell](https://console.cloud.google.com/?cloudshell=true)\n2. In the development environment where you set up the gcloud CLI, run the\n [`gcloud components update` command](/sdk/gcloud/reference/components/update)\n to make sure that you have updated all installed components of the\n [gcloud CLI](/sdk/gcloud) to the latest version.\n\n gcloud components update\n\nCreate a CMEK and grant permissions\n\nTo create a CMEK and grant the Gemini Code Assist service account\npermissions on the key, perform the following tasks:\n\n1. In the Google Cloud project where you want to manage your keys, do the\n following:\n\n 1. [Enable the Cloud Key Management Service API](https://console.cloud.google.com/flows/enableapi?apiid=cloudkms.googleapis.com&redirect=https://console.cloud.google.com).\n\n 2. Create the [key ring](https://cloud.google.com/kms/docs/create-key-ring) and\n [key](https://cloud.google.com/kms/docs/create-key) directly in\n Cloud KMS.\n\n2. Grant the [CryptoKey Encrypter/Decrypter IAM role](https://cloud.google.com/iam/docs/roles-permissions/cloudkms#cloudkms.cryptoKeyEncrypterDecrypter)\n (`roles/cloudkms.cryptoKeyEncrypterDecrypter`) to the\n Gemini Code Assist service account. Grant this permission on\n the key that you created.\n\n Console\n 1. Go to **Key management**.\n\n [Go to Key management](https://console.cloud.google.com/security/kms)\n 2. Select the key that you created.\n\n 3. Grant access to the Gemini Code Assist service account:\n\n 1. Click **Add principal**.\n 2. Add the Gemini Code Assist service account. The service account is `service-`\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e`@gcp-sa-cloudaicompanions.iam.gserviceaccount.com`, where \u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e is the [project number](https://cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects) of the Google Cloud project where Gemini Code Assist is enabled.\n 3. In **Select a role** , select **Cloud KMS** \\\u003e **Cloud KMS CryptoKey Encrypter/Decrypter**.\n 4. Click **Save**.\n 4. Repeat the previous step to grant access to the account that will\n create the code repository index with a CMEK.\n\n 5. Return to the **[Key management](https://console.cloud.google.com/security/kms)**\n page and select the key again.\n\n 6. Select **Show info panel** . You should see roles in the\n **Role/Member** column.\n\n gcloud CLI\n 1. To grant access to the Gemini Code Assist service\n account, in a shell environment, use the\n [`kms keys add-iam-policy-binding`command](https://cloud.google.com/sdk/gcloud/reference/projects/add-iam-policy-binding):\n\n gcloud kms keys add-iam-policy-binding \u003cvar translate=\"no\"\u003eKEY_NAME\u003c/var\u003e \\\n --project=\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --location=\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e \\\n --keyring=\u003cvar translate=\"no\"\u003eKEYRING_NAME\u003c/var\u003e \\\n --member=\"serviceAccount:service-\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e@gcp-sa-cloudaicompanion.iam.gserviceaccount.com\" \\\n --role=\"roles/cloudkms.cryptoKeyEncrypterDecrypter\"\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eKEY_NAME\u003c/var\u003e: the key name.\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of the project that contains the key.\n - \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: the key location.\n - \u003cvar translate=\"no\"\u003eKEYRING_NAME\u003c/var\u003e: the key ring name.\n - \u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e: the [project number](/resource-manager/docs/creating-managing-projects#identifying_projects) of the Google Cloud project with Gemini Code Assist enabled.\n 2. Repeat the previous step to grant access to the account that will\n create the code repository index with a CMEK.\n\n For more information about this command, see the\n [`gcloud kms keys add-iam-policy-binding` documentation](https://cloud.google.com/sdk/gcloud/reference/kms/keys/add-iam-policy-binding).\n\nYou can now\n[create a code repository index with a CMEK](#create_a_code_repository_index_with_a_cmek)\nusing the API, and specify the key to use for encryption.\n\nCreate a code repository index with a CMEK\n\nTo create a new repository that has CMEK protection, do one of the following: \n\ngcloud CLI\n\nUse the [`gemini code-repository-indexes create` command](https://cloud.google.com/sdk/gcloud/reference/gemini/code-repository-indexes/create): \n\n gcloud gemini code-repository-indexes create \u003cvar translate=\"no\"\u003eCODE_REPOSITORY_INDEX_NAME\u003c/var\u003e \\\n --location=\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e \\\n --kms-key=\"projects/\u003cvar translate=\"no\"\u003eKEY_PROJECT_ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e/keyRings/\u003cvar translate=\"no\"\u003eKEYRING_NAME\u003c/var\u003e/cryptoKeys/\u003cvar translate=\"no\"\u003eKEY_NAME\u003c/var\u003e\"\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eCODE_REPOSITORY_INDEX_NAME\u003c/var\u003e: the name of the new code repository index that you'll create.\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: the key location.\n- \u003cvar translate=\"no\"\u003eKEY_PROJECT_ID\u003c/var\u003e: the key project ID.\n- \u003cvar translate=\"no\"\u003eKEYRING_NAME\u003c/var\u003e: the key ring name.\n- \u003cvar translate=\"no\"\u003eKEY_NAME\u003c/var\u003e: the key name.\n\nAPI\n\n1. Create a JSON file that contains the following information:\n\n ```\n {\n \"kmsKey\": \"projects/KEY_PROJECT_ID/locations/KEY_LOCATION/keyRings/KEYRING_NAME/cryptoKeys/KEY_NAME\"\n }\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eKEY_PROJECT_ID\u003c/var\u003e: the key project ID\n - \u003cvar translate=\"no\"\u003eKEY_LOCATION\u003c/var\u003e: the key location\n - \u003cvar translate=\"no\"\u003eKEYRING_NAME\u003c/var\u003e: the key ring name\n - \u003cvar translate=\"no\"\u003eKEY_NAME\u003c/var\u003e: the key name\n2. Use a [`cURL`](http://curl.haxx.se/) command to call the\n [`projects.locations.codeRepositoryIndexes.create` method](https://cloud.google.com/gemini/docs/api/reference/rest/v1/projects.locations.codeRepositoryIndexes/create):\n\n ```\n curl -X POST --data-binary @JSON_FILE_NAME \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Content-Type: application/json\" \\\n \"https://cloudaicompanion.googleapis.com/v1/projects/PROJECT_ID/locations/KEY_LOCATION/codeRepositoryIndexes?codeRepositoryIndexId=CODE_REPOSITORY_INDEX_NAME\"\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eJSON_FILE_NAME\u003c/var\u003e: the path for the JSON file that you created in the preceding step.\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of the project to create the repository in.\n - \u003cvar translate=\"no\"\u003eKEY_LOCATION\u003c/var\u003e: the location to create the repository in, which must match the location where the CMEK exists.\n - \u003cvar translate=\"no\"\u003eCODE_REPOSITORY_INDEX_NAME\u003c/var\u003e: the name of the new code repository index that you'll create. For example, `zg-btf-0001`.\n\nThe response returns a set of log entries.\n\nRemove access to a CMEK repository **Warning:** If you disable the CMEK, Google Cloud removes the instance and the service will no longer be available, even if you re-enable the key.\n\nThere are several ways to remove access to a CMEK-encrypted repository:\n\n- Revoke the Cloud KMS CryptoKey Encrypter/Decrypter [role](https://cloud.google.com/kms/docs/reference/permissions-and-roles#predefined_roles) from the Gemini Code Assist service account using the [Google Cloud console](https://cloud.google.com/iam/docs/granting-changing-revoking-access#revoke_access) or the [gcloud CLI](https://cloud.google.com/iam/docs/granting-changing-revoking-access#revoking-gcloud-manual).\n- [Temporarily disable](https://cloud.google.com/kms/docs/enable-disable#disable_an_enabled_key_version) the CMEK.\n- [Permanently destroy](https://cloud.google.com/kms/docs/destroy-restore#schedule_a_key_version_for_destruction_destroy_a_key_version) the CMEK.\n\nWe recommend that you revoke the permissions from the\nGemini Code Assist service account before disabling or destroying\na key. Changes to permissions are consistent within seconds, so you can observe\nthe impacts of disabling or destroying a key."]]