Criptografar dados com chaves de criptografia gerenciadas pelo cliente
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Este documento mostra como usar chaves de criptografia gerenciadas pelo cliente (CMEK) para
criptografar e controlar dados em repouso em um serviço de nuvem usando o
Cloud Key Management Service. A CMEK é integrada à personalização de código. O Gemini Code Assist não oferece suporte ao uso de chaves do Cloud EKM.
Neste documento, você vai:
Saiba como criar uma CMEK.
Conceda permissões à conta de serviço do Gemini Code Assist.
Crie um índice de repositório de código com uma CMEK.
Remover o acesso a um repositório de CMEK.
Por padrão, o Gemini para Google Cloud criptografa o conteúdo do cliente em
repouso. O Gemini processa a criptografia para você sem que você precise
fazer nada. Essa opção é chamada de Criptografia padrão do Google.
Se você quiser controlar suas chaves de criptografia, use chaves de criptografia gerenciadas pelo cliente
(CMEKs) no Cloud KMS com serviços integrados a CMEKs, incluindo
o Gemini. O uso de chaves do Cloud KMS permite controlar o nível de proteção,
o local, a programação de rotação, as permissões de uso e acesso e os limites criptográficos.
O uso do Cloud KMS também permite
visualizar registros de auditoria e controlar ciclos de vida importantes.
Em vez de o Google ser proprietário e gerente
de chaves de criptografia de chaves (KEKs) simétricas que protegem seus dados, você controla e
gerencia essas chaves no Cloud KMS.
Depois de configurar os recursos com CMEKs, a experiência de acesso aos recursos do
Gemini é semelhante à criptografia padrão do Google.
Para mais informações sobre suas opções de criptografia,
consulte Chaves de criptografia gerenciadas pelo cliente (CMEK).
Antes de começar
In the Google Cloud console, activate Cloud Shell.
No ambiente shell, execute o
comando gcloud components update
para verificar se você atualizou todos os componentes instalados da
CLI gcloud para a versão mais recente. Para
esta etapa, instale e inicialize a CLI gcloud ou use o Cloud Shell.
gcloudcomponentsupdate
Criar uma CMEK e conceder permissões
Para criar uma CMEK e conceder permissões à conta de serviço do Gemini Code Assist
na chave, execute as seguintes tarefas:
No projeto do Google Cloud em que você quer gerenciar as chaves, faça o seguinte:
Conceda acesso à conta de serviço do Gemini Code Assist:
Clique em Adicionar principal.
Adicione a conta de serviço do Gemini Code Assist. A conta de serviço é service-PROJECT_NUMBER@gcp-sa-cloudaicompanions.iam.gserviceaccount.com, em que PROJECT_NUMBER é o número do projeto do projeto Google Cloud em que o Gemini Code Assist está ativado.
Em Selecionar um papel, escolha Cloud KMS >
Criptografador/descriptografador do Cloud KMS CryptoKey.
Clique em Salvar.
Repita a etapa anterior para conceder acesso à conta que vai
criar o índice do repositório de código com uma CMEK.
JSON_FILE_NAME: o caminho para o arquivo
JSON criado na etapa anterior.
PROJECT_ID: o ID do projeto em que o repositório será criado.
KEY_LOCATION: o local em que o repositório será criado, que precisa corresponder ao local em que a CMEK existe.
CODE_REPOSITORY_INDEX_NAME: o nome do
novo índice de repositório de código que você vai criar. Por exemplo, zg-btf-0001.
A resposta retorna um conjunto de entradas de registro.
Remover o acesso a um repositório de CMEK
Há várias maneiras de remover o acesso de um repositório criptografado por CMEKs:
Revogue o papel
de criptografador/descriptografador da CryptoKey do Cloud KMS da
conta de serviço do Gemini Code Assist usando o
consoleGoogle Cloud
ou a CLI gcloud.
Recomendamos revogar as permissões da conta de serviço do
Gemini Code Assist antes de desativar ou destruir
uma chave. As mudanças nas permissões são consistentes em segundos, então é possível observar
os impactos da desativação ou destruição de uma chave.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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."]]