Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Proteggere i dati con CMEK
Questa pagina fornisce informazioni supplementari per proteggere i tuoi dati con le chiavi di crittografia gestite dal cliente (CMEK) per le funzioni create utilizzando i comandi gcloud functions o l'API Cloud Functions v2.
Per una descrizione dettagliata di CMEK, inclusa la configurazione manuale, l'utilizzo di Autokey e il test della protezione CMEK, consulta la documentazione di Cloud Run.
I seguenti tipi di dati delle funzioni Cloud Run vengono criptati quando si utilizza una
chiave CMEK:
Codice sorgente della funzione caricato per il deployment e archiviato da Google in Cloud Storage, utilizzato nel processo di compilazione.
I risultati del processo di compilazione della funzione, tra cui:
L'immagine container creata dal codice sorgente della funzione.
Ogni istanza della funzione di cui è stato eseguito il deployment.
Il processo di compilazione della funzione stessa è protetto da una chiave temporanea generata in modo univoco per ogni compilazione. Per ulteriori informazioni, consulta la sezione Conformità CMEK in Cloud Build. Inoltre, tieni presente quanto segue:
I metadati dei file, ad esempio i percorsi del file system o i timestamp di modifica,
non vengono criptati.
Se una chiave è disattivata, l'immagine del contenitore non può essere dispiattata e le nuove istanze non possono essere avviate.
La protezione CMEK delle funzioni Cloud Run si applica solo alle risorse delle funzioni Cloud Run gestite da Google. Sei responsabile della protezione dei dati e delle risorse gestite da te, come i repository di codice sorgente, i canali di eventi presenti nel progetto del cliente o qualsiasi servizio utilizzato dalle tue funzioni.
Prima di iniziare
Crea una chiave per una singola regione da utilizzare per criptare le funzioni. Per scoprire come creare una chiave, consulta la pagina relativa alla creazione di chiavi di crittografia simmetrica.
Concedere agli account di servizio l'accesso alla chiave
Per tutte le funzioni, devi concedere alla chiave l'accesso ai seguenti service account:
Agente di servizio Cloud Run Functions (service-PROJECT_NUMBER@gcf-admin-robot.iam.gserviceaccount.com)
Agente di servizio Artifact Registry (service-PROJECT_NUMBER@gcp-sa-artifactregistry.iam.gserviceaccount.com)
Agente di servizio Cloud Storage (service-PROJECT_NUMBER@gs-project-accounts.iam.gserviceaccount.com)
Agente di servizio Cloud Run (service-PROJECT_NUMBER@serverless-robot-prod.iam.gserviceaccount.com)
Agente di servizio Eventarc (service-PROJECT_NUMBER@gcp-sa-eventarc.iam.gserviceaccount.com)
Per concedere a questi account di servizio l'accesso alla chiave, aggiungi ogni account di servizio come entità della chiave e poi concedi all'account di servizio il ruolo Cloud KMS CryptoKey Encrypter/Decrypter:
Fai clic sul nome del mazzo di chiavi che contiene la chiave scelta.
Fai clic sul nome della chiave per visualizzarne i dettagli.
Nella scheda Autorizzazioni, fai clic su Concedi accesso.
Nel campo Nuove entità, inserisci gli indirizzi email di tutti e tre gli account di servizio discussi in precedenza per assegnare le autorizzazioni a tutti e tre gli account contemporaneamente.
Nel menu Seleziona un ruolo, seleziona Autore crittografia/decrittografia CryptoKey Cloud KMS.
Fai clic su Salva.
gcloud
Per ogni account di servizio discusso in precedenza, esegui il seguente comando:
KEY_RING: il nome del mazzo di chiavi. Ad esempio,
my-keyring.
LOCATION: la posizione della chiave. Ad esempio,
us-central1.
SERVICE_AGENT_EMAIL: l'indirizzo email dell'account di servizio.
Attivazione di CMEK per una funzione
Dopo aver configurato un repository Artifact Registry con CMEK abilitato e aver concesso alle funzioni Cloud Run l'accesso alla chiave, puoi abilitare CMEK per la tua funzione.
Per abilitare CMEK per una funzione, esegui il seguente comando:
FUNCTION: il nome della funzione per attivare CMEK. Ad esempio, cmek-function.
KEY: il nome della chiave completo, nel seguente formato:
projects/PROJECT_NAME/locations/LOCATION/keyRings/KEYRING_NAME/cryptoKeys/KEY_NAME.
REPOSITORY: il nome del repository Artifact Registry completamente qualificato, nel seguente formato:projects/PROJECT_NAME/locations/LOCATION/repositories/REPOSITORY.
YOUR_SOURCE_LOCATION: quando attivi il CMEK per una funzione preesistente, assicurati che il codice sorgente previsto venga reimplementato specificando questo parametro esplicitamente.
FLAGS...: flag aggiuntivi che potrebbero essere necessari per eseguire il deployment della funzione, in particolare per creare i deployment. Per maggiori dettagli, consulta Eseguire il deployment di una funzione Cloud Run.
CMEK è attivato per la funzione. Se vuoi, attiva le policy dell'organizzazione CMEK per applicare a tutte le nuove funzioni la conformità a CMEK.
Tieni presente che le funzioni Cloud Run utilizzano sempre la versione principale di una chiave per la protezione CMEK. Non puoi specificare una versione della chiave specifica da utilizzare quando attivi CMEK per le tue funzioni.
Se una chiave viene eliminata o disattivata o se le autorizzazioni richieste vengono revocate, le istanze attive delle funzioni protette da quella chiave non vengono arrestate.
Le esecuzioni di funzioni già in corso continueranno a essere eseguite, ma le nuove esecuzioni non andranno a buon fine finché le funzioni Cloud Run non avranno accesso alla 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-05 UTC."],[[["\u003cp\u003eCloud Run functions encrypts customer content at rest by default using Google default encryption, but offers the option to use customer-managed encryption keys (CMEKs) for greater control.\u003c/p\u003e\n"],["\u003cp\u003eUsing CMEKs with Cloud Run functions allows you to manage key protection level, location, rotation schedule, access permissions, and cryptographic boundaries, and view audit logs.\u003c/p\u003e\n"],["\u003cp\u003eCMEK protection in Cloud Run functions encrypts function source code, container images, and deployed function instances, while file metadata remains unencrypted.\u003c/p\u003e\n"],["\u003cp\u003eEnabling CMEK requires granting specific service accounts (Cloud Run, Artifact Registry, Cloud Storage, etc.) access to the encryption key and creating a CMEK-protected Artifact Registry repository.\u003c/p\u003e\n"],["\u003cp\u003eDisabling the CMEK key will prevent new function instances from starting and new executions from occurring, but existing function executions will continue until completion.\u003c/p\u003e\n"]]],[],null,["# Protect your data with CMEK\n===========================\n\nThis page provides supplemental information for protecting your data with\ncustomer-managed encryption keys (CMEKs) for functions created using\n[`gcloud functions`](/sdk/gcloud/reference/functions) commands or the\n[Cloud Functions v2 API](/functions/docs/reference/rest).\n\nFor a detailed description of CMEK, including manual setup, using Autokey,\nand testing CMEK protection, refer to [Cloud Run documentation](/run/docs/securing/using-cmek).\n\nThe following types of Cloud Run functions data are encrypted when using a\nCMEK:\n\n- Function source code uploaded for deployment and stored by Google in Cloud Storage, used in the build process.\n- The results of the function build process, including:\n - The container image built from your function source code.\n - Each instance of the function that is deployed.\n\nThe function build process itself is protected by an ephemeral key uniquely\ngenerated for each build. See\n[CMEK compliance in Cloud Build](/build/docs/securing-builds/cmek) for more\ninformation. Additionally, note the following:\n\n- File metadata, such as file system paths or modification timestamps,\n is not encrypted.\n\n- If a key is disabled, the container image cannot be deployed and new\n instances cannot start.\n\n- Cloud Run functions CMEK protection only applies to Google-managed\n Cloud Run functions resources; you are responsible for protecting data and\n resources managed by you, such as your source code repositories,\n [event channels](/eventarc/docs/third-parties/third-parties-overview#subscription-terms)\n that live in the customer project, or any services used by your\n functions.\n\nBefore you begin\n----------------\n\n1. Create a single-region key to use to encrypt your functions. To learn how to\n create a key, see\n [Creating symmetric encryption keys](/kms/docs/creating-keys).\n\n2. [Create an Artifact Registry repository](/artifact-registry/docs/manage-repos#create)\n that has [CMEK enabled](/artifact-registry/docs/cmek). You must use the same\n key for the Artifact Registry repository as you do when enabling CMEK for a\n function.\n\n3. For event-driven functions, follow the additional setup steps\n outlined in\n [Enable CMEK for a Google channel](/eventarc/docs/use-cmek#enable-cmek-google-channel).\n\nGranting service accounts access to the key\n-------------------------------------------\n\nFor all functions, you must grant the following service accounts access to the key:\n\n- Cloud Run functions service agent (`service-`\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e`@gcf-admin-robot.iam.gserviceaccount.com`)\n\n- Artifact Registry service agent (`service-`\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e`@gcp-sa-artifactregistry.iam.gserviceaccount.com`)\n\n- Cloud Storage service agent (`service-`\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e`@gs-project-accounts.iam.gserviceaccount.com`)\n\n- Cloud Run service agent (`service-`\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e`@serverless-robot-prod.iam.gserviceaccount.com`)\n\n- Eventarc service agent (`service-`\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e`@gcp-sa-eventarc.iam.gserviceaccount.com`)\n\nTo grant these service accounts access to the key, add each service account as a\nprincipal of the key and then grant the service account the\n`Cloud KMS CryptoKey Encrypter/Decrypter` role: \n\n### Console\n\n1. Go to the Cloud Key Management Service page in the Google Cloud console: \n\n [Go to the Cloud KMS page](https://console.cloud.google.com/security/kms)\n\n2. Click the name of the key ring that contains the chosen key.\n\n3. Click the name of the key to view the key details.\n\n4. In the **Permissions** tab, click **Grant access**.\n\n5. In the **New principals** field, enter the email addresses of all three\n service accounts discussed earlier to assign permissions to all three\n accounts at once.\n\n6. In the **Select a role** menu, select **Cloud KMS CryptoKey\n Encrypter/Decrypter**.\n\n7. Click **Save**.\n\n### gcloud\n\nFor each service account discussed earlier, run the following command: \n\n```bash\ngcloud kms keys add-iam-policy-binding KEY \\\n --keyring KEY_RING \\\n --location LOCATION \\\n --member serviceAccount:SERVICE_AGENT_EMAIL \\\n --role roles/cloudkms.cryptoKeyEncrypterDecrypter\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eKEY\u003c/var\u003e: The name of the key. For example, `my-key`.\n\n- \u003cvar translate=\"no\"\u003eKEY_RING\u003c/var\u003e: The name of the key ring. For example,\n `my-keyring`.\n\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: The location of the key. For example,\n `us-central1`.\n\n- \u003cvar translate=\"no\"\u003eSERVICE_AGENT_EMAIL\u003c/var\u003e: The email address of the\n service account.\n\n| **Important:** Some service agents, such as the Cloud Storage service agent (including its email address), are not initially available when you create a project. Instead, they are activated the first time you access them. For example, to activate the Cloud Storage service agent, you can [retrieve its email address](/storage/docs/getting-service-agent). The service agent must be activated prior to assigning permissions to it.\n\nEnabling CMEK for a function\n----------------------------\n\nAfter setting up an Artifact Registry repository with CMEK enabled and\ngranting Cloud Run functions access to your key, you're ready to enable\nCMEK for your function.\n\nTo enable CMEK for a function, run the following command: \n\n```bash\ngcloud functions deploy FUNCTION \\\n --kms-key=KEY \\\n --docker-repository=REPOSITORY \\\n --source=YOUR_SOURCE_LOCATION\n FLAGS...\n \n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eFUNCTION\u003c/var\u003e: The name of the function to enable CMEK\n on. For example, `cmek-function`.\n\n- \u003cvar translate=\"no\"\u003eKEY\u003c/var\u003e: The fully qualified key name, in the following\n format:\n `projects/`\u003cvar translate=\"no\"\u003ePROJECT_NAME\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\n- \u003cvar translate=\"no\"\u003eREPOSITORY\u003c/var\u003e: The fully qualified Artifact Registry\n repository name, in the following format:\n `projects/`\u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e`/locations/`\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`/repositories/`\u003cvar translate=\"no\"\u003eREPOSITORY\u003c/var\u003e.\n\n- \u003cvar translate=\"no\"\u003eYOUR_SOURCE_LOCATION\u003c/var\u003e: When enabling CMEK for a\n pre-existing function, make sure that the intended source code is being\n re-deployed by specifying this parameter explicitly.\n\n- \u003cvar translate=\"no\"\u003eFLAGS\u003c/var\u003e`...`: Additional flags that may be\n required to deploy your function, particularly for create deployments. For\n details, see\n [Deploy a Cloud Run function](/functions/docs/deploy#basics).\n\nCMEK is enabled for the function. Optionally, enable\n[CMEK organization policies](/kms/docs/cmek-org-policy) to enforce all new\nfunctions to be CMEK compliant.\n| **Note:** First-time function deployments with CMEK enabled might fail due to IAM propagation delays. If you encounter an error upon deployment, ensure the permissions are set correctly and try again after a short period.\n\nNote that Cloud Run functions always uses the primary version of a key for CMEK\nprotection. You cannot specify a particular key version to use when enabling\nCMEK for your functions.\n\nIf a key is [destroyed](/kms/docs/destroy-restore) or\n[disabled](/kms/docs/enable-disable), or the requisite permissions on it are\nrevoked, active instances of functions protected by that key are not shut down.\nFunction executions already in progress will continue to run, but new executions\nwill fail as long as Cloud Run functions does not have access to the key."]]