Daten mit vom Kunden verwalteten Verschlüsselungsschlüsseln verschlüsseln
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
In diesem Dokument wird beschrieben, wie Sie mit vom Kunden verwalteten Verschlüsselungsschlüsseln (Customer Managed Encryption Keys, CMEKs) ruhende Daten in einem Cloud-Dienst über Cloud Key Management Service verschlüsseln und steuern. CMEK ist in die Codeanpassung integriert.
Gemini Code Assist unterstützt die Verwendung von Cloud EKM-Schlüsseln nicht.
In diesem Dokument tun Sie Folgendes:
Informationen zum Erstellen eines CMEK.
Gewähren Sie dem Gemini Code Assist-Dienstkonto Berechtigungen.
Erstellen Sie einen Code-Repository-Index mit einem CMEK.
Zugriff auf ein CMEK-Repository entfernen
Standardmäßig werden inaktive Kundendaten in Gemini für Google Cloud verschlüsselt. Die Verschlüsselung wird von Gemini durchgeführt. Zusätzliche Maßnahmen Ihrerseits sind nicht erforderlich. Diese Option wird Google-Standardverschlüsselung genannt.
Wenn Sie Ihre Verschlüsselungsschlüssel selbst verwalten möchten, können Sie vom Kunden verwaltete Verschlüsselungsschlüssel (CMEKs, Customer-Managed Encryption Keys) in Cloud KMS mit CMEK-integrierten Diensten wie Gemini verwenden. Mit Cloud KMS-Schlüsseln haben Sie die Kontrolle über Schutzlevel, Speicherort, Rotationszeitplan, Nutzungs- und Zugriffsberechtigungen sowie über kryptografische Grenzen.
Mit Cloud KMS können Sie außerdem Audit-Logs aufrufen und den Lebenszyklus von Schlüsseln steuern.
Statt es Google zu überlassen und zu verwalten, das die symmetrischen Schlüsselverschlüsselungsschlüssel (Key Encryption Keys, KEKs) zum Schutz Ihrer Daten enthält, können Sie diese auch über Cloud KMS steuern und verwalten.
Nachdem Sie Ihre Ressourcen mit CMEKs eingerichtet haben, ähnelt der Zugriff auf Ihre Gemini-Ressourcen der Verwendung der Google-Standardverschlüsselung.
Weitere Informationen zu Ihren Verschlüsselungsoptionen finden Sie unter Vom Kunden verwaltete Verschlüsselungsschlüssel (CMEK).
Hinweise
In the Google Cloud console, activate Cloud Shell.
Führen Sie in Ihrer Shell-Umgebung den gcloud components update-Befehl aus, um sicherzustellen, dass Sie alle installierten Komponenten der gcloud CLI auf die neueste Version aktualisiert haben. Für diesen Schritt können Sie die gcloud CLI installieren und initialisieren oder Cloud Shell verwenden.
gcloudcomponentsupdate
CMEK erstellen und Berechtigungen erteilen
So erstellen Sie einen CMEK und erteilen dem Gemini Code Assist-Dienstkonto Berechtigungen für den Schlüssel:
Gehen Sie im Google Cloud Projekt, in dem Sie Ihre Schlüssel verwalten möchten, so vor:
Weisen Sie dem Gemini Code Assist-Dienstkonto die IAM-Rolle „CryptoKey-Verschlüsseler/Entschlüsseler“ (roles/cloudkms.cryptoKeyEncrypterDecrypter) zu. Erteilen Sie diese Berechtigung für den von Ihnen erstellten Schlüssel.
Wählen Sie den von Ihnen erstellten Schlüssel aus.
Gewähren Sie Zugriff auf das Gemini Code Assist-Dienstkonto:
Klicken Sie auf Hauptkonto hinzufügen.
Fügen Sie das Gemini Code Assist-Dienstkonto hinzu. Das Dienstkonto ist service-PROJECT_NUMBER@gcp-sa-cloudaicompanions.iam.gserviceaccount.com, wobei PROJECT_NUMBER die Projektnummer des Google Cloud -Projekts ist, in dem Gemini Code Assist aktiviert ist.
Wählen Sie unter Rolle auswählen die Option Cloud KMS > Cloud KMS CryptoKey-Verschlüsseler/Entschlüsseler aus.
Klicken Sie auf Speichern.
Wiederholen Sie den vorherigen Schritt, um Zugriff auf das Konto zu gewähren, mit dem der Code-Repository-Index mit einem CMEK erstellt wird.
Kehren Sie zur Seite Schlüsselverwaltung zurück und wählen Sie den Schlüssel noch einmal aus.
Wählen Sie Infofeld anzeigen aus. In der Spalte Rolle/Mitglied sollten die Rollen angezeigt werden.
gcloud-CLI
Wenn Sie dem Dienstkonto für Gemini Code Assist Zugriff gewähren möchten, verwenden Sie in einer Shell-Umgebung den Befehl kms keys add-iam-policy-binding:
JSON_FILE_NAME: der Pfad für die JSON-Datei, die Sie im vorherigen Schritt erstellt haben.
PROJECT_ID: die ID des Projekts, in dem das Repository erstellt werden soll.
KEY_LOCATION: der Speicherort, an dem das Repository erstellt werden soll. Er muss mit dem Speicherort übereinstimmen, an dem sich der CMEK befindet.
CODE_REPOSITORY_INDEX_NAME: Der Name des neuen Code-Repository-Index, den Sie erstellen. Beispiel: zg-btf-0001
Die Antwort gibt eine Reihe von Logeinträgen zurück.
Zugriff auf ein CMEK-Repository entfernen
Es gibt verschiedene Möglichkeiten, um den Zugriff auf ein mit CMEK verschlüsseltes Repository wieder aufzuheben:
Widerrufen Sie die Rolle „Cloud KMS CryptoKey-Verschlüsseler/Entschlüsseler“ aus dem Gemini Code Assist-Dienstkonto mithilfe der Google Cloud -Konsole oder der gcloud CLI.
Wir empfehlen, die Berechtigungen des Gemini Code Assist-Dienstkontos zu widerrufen, bevor Sie einen Schlüssel deaktivieren oder löschen. Die Änderung von Berechtigungen wird innerhalb von Sekunden wirksam, sodass Sie sofort nachvollziehen können, wie sich das Deaktivieren oder Löschen eines Schlüssels auswirkt.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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."]]