Encriptar datos con claves de encriptación administradas por el cliente
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En este documento, se muestra cómo usar claves de encriptación administradas por el cliente (CMEK) para encriptar y controlar los datos en reposo en un servicio de nube a través de Cloud Key Management Service. La CMEK está integrada en la personalización de código. Gemini Code Assist no admite el uso de claves de Cloud EKM.
En este documento, harás lo siguiente:
Aprende a crear una CMEK.
Otorga permisos a la cuenta de servicio de Gemini Code Assist.
Crea un índice de repositorio de código con una CMEK.
Quita el acceso a un repositorio con CMEK.
De forma predeterminada, Gemini para Google Cloud encripta el contenido del cliente en reposo. Gemini controla la encriptación por ti sin que debas realizar ninguna acción adicional. Esta opción se denomina Encriptación predeterminada de Google.
Si deseas controlar tus claves de encriptación, puedes usar las claves de encriptación administradas por el cliente (CMEK) en Cloud KMS con servicios integrados en CMEK, incluido Gemini. El uso de claves de Cloud KMS te permite controlar su nivel de protección, ubicación, programa de rotación, permisos de uso y acceso, y límites criptográficos.
El uso de Cloud KMS también te permite ver los registros de auditoría y controlar los ciclos de vida de las claves.
En lugar de que Google posea y administre las claves de encriptación de claves (KEK) simétricas que protegen tus datos, tú las controlas y administras en Cloud KMS.
Después de configurar tus recursos con CMEK, la experiencia de acceso a tus
recursos de Gemini es similar a usar la encriptación predeterminada de Google.
Para obtener más información sobre tus opciones de encriptación, consulta Claves de encriptación administradas por el cliente (CMEK).
Antes de comenzar
In the Google Cloud console, activate Cloud Shell.
En tu entorno de shell, ejecuta el comando gcloud components update para asegurarte de haber actualizado todos los componentes instalados de la CLI de gcloud a la versión más reciente. Para este paso, puedes instalar y, luego, inicializar gcloud CLI, o bien usar Cloud Shell.
gcloudcomponentsupdate
Crea una CMEK y otorga permisos
Para crear una clave CMEK y otorgar permisos a la cuenta de servicio de Gemini Code Assist en la clave, realiza las siguientes tareas:
En el proyecto Google Cloud en el que deseas administrar tus claves, haz lo siguiente:
Otorga acceso a la cuenta de servicio de Gemini Code Assist:
Haz clic en Agregar principal.
Agrega la cuenta de servicio de Gemini Code Assist. La cuenta de servicio es service-PROJECT_NUMBER@gcp-sa-cloudaicompanions.iam.gserviceaccount.com, en la que PROJECT_NUMBER es el número del proyecto del proyecto Google Cloud en el que está habilitado Gemini Code Assist.
En Selecciona un rol, selecciona Cloud KMS > Encriptador/Desencriptador de CryptoKey de Cloud KMS.
Haz clic en Guardar.
Repite el paso anterior para otorgar acceso a la cuenta que creará el índice del repositorio de código con una CMEK.
JSON_FILE_NAME: Es la ruta de acceso del archivo JSON que creaste en el paso anterior.
PROJECT_ID: Es el ID del proyecto en el que se creará el repositorio.
KEY_LOCATION: Es la ubicación en la que se creará el repositorio, que debe coincidir con la ubicación en la que existe la CMEK.
CODE_REPOSITORY_INDEX_NAME: Es el nombre del nuevo índice del repositorio de código que crearás. Por ejemplo, zg-btf-0001
La respuesta devuelve un conjunto de entradas de registro.
Quita el acceso a un repositorio con CMEK
Existen varias formas de quitar el acceso a un repositorio encriptado mediante una CMEK:
Revoca el rol de encriptador/desencriptador de CryptoKey de Cloud KMS de la cuenta de servicio de Gemini Code Assist con la consola deGoogle Cloud o la CLI de gcloud.
Te recomendamos que revoques los permisos de la cuenta de servicio de Gemini Code Assist antes de inhabilitar o destruir una clave. Los cambios en los permisos son coherentes en cuestión de segundos, por lo que puedes observar el impacto de inhabilitar o destruir una clave.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 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."]]