Cifre datos con claves de cifrado administradas por el cliente
Organízate con las colecciones
Guarda y clasifica el contenido según tus preferencias.
Este documento muestra cómo usar claves de cifrado administradas por el cliente (CMEK) para cifrar y controlar los datos en reposo en un servicio en la nube mediante el Servicio de Gestión de Claves en la Nube . CMEK está integrada con la personalización de código para Gemini Code Assist.
Gemini Code Assist no admite el uso de claves Cloud EKM .
Si no usa una CMEK, Google administra automáticamente las claves que cifran los datos de forma predeterminada. Este comportamiento se conoce como cifrado predeterminado de Google . Con este comportamiento predeterminado, no tiene control sobre las claves de cifrado.
En este documento, harás lo siguiente:
Aprenda cómo crear un CMEK.
Otorgar permisos a la cuenta de servicio Gemini Code Assist.
Cree un índice de repositorio de código con un CMEK.
Eliminar el acceso a un repositorio CMEK.
De forma predeterminada, Gemini para Google Cloud Cifra el contenido del cliente en reposo . Gemini gestiona el cifrado automáticamente sin que usted tenga que hacer nada más. Esta opción se denomina cifrado predeterminado de Google .
Si desea controlar sus claves de cifrado, puede usar claves de cifrado administradas por el cliente (CMEK) en Cloud KMS con servicios integrados de CMEK, como Gemini. Usar las claves de Cloud KMS le permite controlar su nivel de protección, ubicación, programación de rotación, permisos de uso y acceso, y límites criptográficos. Cloud KMS también le permite ver registros de auditoría y controlar el ciclo de vida de las claves. En lugar de que Google posea y administre las claves de cifrado de clave simétrica (KEK) que protegen sus datos, usted controla y administra estas claves en Cloud KMS.
Después de configurar sus recursos con claves CMEK, acceder a ellos es similar a usar el cifrado predeterminado de Google. Para obtener más información sobre las opciones de cifrado, consulte Claves de cifrado administradas por el cliente (CMEK) .
Antes de empezar
In the Google Cloud console, activate Cloud Shell.
En su entorno de shell, ejecute el comando gcloud components update para asegurarse de haber actualizado todos los componentes instalados de la CLI de gcloud a la última versión. Para este paso, puede instalar e inicializar la CLI de gcloud o usar Cloud Shell .
gcloudcomponentsupdate
Crear una CMEK y otorgar permisos
Para crear una CMEK y otorgarle permisos a la cuenta de servicio Gemini Code Assist en la clave, realice las siguientes tareas:
En el Google Cloud proyecto donde desea administrar sus claves, haga lo siguiente:
Otorgar acceso a la cuenta de servicio Gemini Code Assist:
Haga clic en Agregar principal .
Agregue la cuenta de servicio de Gemini Code Assist. La cuenta de servicio es service- PROJECT_NUMBER @gcp-sa-cloudaicompanions.iam.gserviceaccount.com , donde PROJECT_NUMBER es el número de proyecto del Google Cloud Proyecto donde está habilitado Gemini Code Assist.
En Seleccionar un rol , seleccione Cloud KMS > Cifrador/descifrador de claves criptográficas de Cloud KMS .
Haga clic en Guardar .
Repita el paso anterior para otorgar acceso a la cuenta que creará el índice del repositorio de código con un CMEK.
JSON_FILE_NAME : la ruta del archivo JSON que creó en el paso anterior.
PROJECT_ID : el ID del proyecto en el que se creará el repositorio.
KEY_LOCATION : la ubicación donde crear el repositorio, que debe coincidir con la ubicación donde existe el CMEK.
CODE_REPOSITORY_INDEX_NAME : el nombre del nuevo índice del repositorio de código que creará. Por ejemplo, zg-btf-0001 .
La respuesta devuelve un conjunto de entradas de registro.
Eliminar el acceso a un repositorio CMEK
Hay varias formas de eliminar el acceso a un repositorio cifrado con CMEK:
Revocar la función de cifrador/descifrador de CryptoKey de Cloud KMS de la cuenta de servicio Gemini Code Assist mediante el Google Cloud consola o la CLI de gcloud .
Le recomendamos revocar los permisos de la cuenta de servicio de Gemini Code Assist antes de deshabilitar o destruir una clave. Los cambios en los permisos se realizan en segundos, por lo que puede observar el impacto de deshabilitar o destruir una clave.
[[["Es fácil de entender","easyToUnderstand","thumb-up"],["Me ofreció una solución al problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Es difícil de entender","hardToUnderstand","thumb-down"],["La información o el código de muestra no son correctos","incorrectInformationOrSampleCode","thumb-down"],["Me faltan las muestras o la información que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-06-11 (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."]]