This document provides information about how to use manually-created Cloud Key Management Service Cloud KMS keys to encrypt disks and other storage-related resources. Keys managed in Cloud KMS are known as customer-managed encryption keys (CMEKs). You can use CMEKs to encrypt Compute Engine resources, such as disks, machine images, instant snapshots, and standard snapshots.
Enable the Cloud KMS API.
Roles required to enable APIs
To enable APIs, you need the serviceusage.services.enable permission. If you
created the project, then you likely already have this permission through the
Owner role (roles/owner). Otherwise, you can get this permission through the
Service Usage Admin role (roles/serviceusage.serviceUsageAdmin).
Learn how to grant roles.
Select the tab for how you plan to use the samples on this page:
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud initIf you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
The Compute Engine Service Agent has the following form:
service-PROJECT_NUMBER@compute-system.iam.gserviceaccount.com
You can use the Google Cloud CLI to assign the role:
gcloud projects add-iam-policy-binding KMS_PROJECT_ID \
--member serviceAccount:service-PROJECT_NUMBER@compute-system.iam.gserviceaccount.com \
--role roles/cloudkms.cryptoKeyEncrypterDecrypter
Replace the following:
KMS_PROJECT_ID: the ID of your
Google Cloud project that runs Cloud KMS (even if this is the
same project running Compute Engine)PROJECT_NUMBER: the project number
(not Google Cloud project ID) of your Google Cloud project that runs
the Compute Engine resources
To ensure that the Compute Engine Service Agent has the necessary
permissions to protect resources by using Cloud KMS keys,
ask your administrator to grant the
Cloud KMS CryptoKey Encrypter/Decrypter (roles/cloudkms.cryptoKeyEncrypterDecrypter) IAM role to the Compute Engine Service Agent on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the permissions required to protect resources by using Cloud KMS keys. To see the exact permissions that are required, expand the Required permissions section:
The following permissions are required to protect resources by using Cloud KMS keys:
compute.disks.updateKmsKey
compute.snapshots.updateKmsKey
Your administrator might also be able to give the Compute Engine Service Agent these permissions with custom roles or other predefined roles.
The Cloud KMS keys used to help protect your data in Compute Engine are AES-256 keys. These keys are key encryption keys, and they encrypt the data encryption keys that encrypt your data, not the data itself.
The data on the disks is encrypted using Google-owned and Google-managed encryption keys. For specifications related to the default encryption in Google Cloud, see Default encryption at rest in the Security documentation.
With Confidential mode for Hyperdisk Balanced and Cloud HSM, the data encryption key (DEK) has additional security properties with hardware-backed enclaves.
You can't encrypt existing resources with CMEKs. You can only encrypt disks, images, and snapshots with CMEKs when you create them.
When you create a disk from a CMEK-encrypted instant snapshot, you must specify the key used to encrypt the source disk. You don't have to specify the key when working with other CMEK-encrypted resources such as disk clones and standard snapshots.
When you create a regionally scoped snapshot (Preview) from a disk encrypted with a CMEK, you must create the snapshot with a regional CMEK that's in the same location as the snapshot. This ensures regional isolation of your snapshot and increases your snapshot's reliability.
You can't use your own keys with Local SSD disks because the keys are managed by Google Cloud infrastructure and deleted when the VM is terminated.
Regional resources (disks) can only be encrypted by a key in one of the following Cloud KMS locations:
For example, a disk in zone us-west1-a can be encrypted by a key in the
global location, the us-west1 region, or the us multi-region.
Global resources (such as images and snapshots) can be encrypted by keys in any location. For more information, see Types of locations for Cloud KMS.
You can't change or remove the encryption key for an image or instant snapshot.
You can't remove a disk or snapshot's encryption key, or change the key from a CMEK to a Google-owned and managed key. Instead, create a copy of the disk or snapshot and specify a new encryption type for the copy.
For more information, see Remove the CMEK from a disk and Remove the CMEK from a snapshot.
You can't rotate or change the CMEK of online Confidential Hyperdisk volumes or online Hyperdisk volumes that are attached to unsupported machine types.
You can rotate or change the CMEK on only the following disk types:
Online Hyperdisk volumes that are attached to the following third- or fourth-generation machine types:
You can't change the key for Hyperdisk volumes that you created by cloning a disk, unless you have deleted the source disk and all other clones of the source disk.
You can either create Cloud KMS keys manually or use Cloud KMS Autokey. Autokey simplifies creating and managing Cloud KMS keys by automating provisioning and assignment. With Autokey, you don't need to provision key rings, keys, and service accounts ahead of time. Instead, they are generated on demand as part of Compute Engine resource creation. For more information, see the Autokey overview.
For the Google Cloud project that runs Cloud KMS, create a key ring and a key as described in Creating key rings and keys.
You can encrypt a new Persistent Disk by supplying a key during VM or disk creation.
Create an encrypted disk by using the
gcloud compute disks create command,
and specify the key using the --kms-key flag.
gcloud compute disks create DISK_NAME \ --kms-key projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY
Replace the following:
DISK_NAME: the name of the new diskKMS_PROJECT_ID: the project that owns the
Cloud KMS keyREGION: the region where the key is locatedKEY_RING: the name of the key ring that includes
the keyKEY: the name of the key used to encrypt the diskConstruct a POST request to the
instances.insert method.
To encrypt a disk, use the diskEncryptionKey property with the
kmsKeyName property. For example, you can encrypt a new disk during
VM creation with your Cloud KMS key by using the following:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances
{
"machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
"disks": [
{
"type": "PERSISTENT",
"diskEncryptionKey": {
"kmsKeyName": "projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY"
},
"initializeParams": {
"sourceImage": "SOURCE_IMAGE"
},
"boot": true
}
],
...
}
Replace the following:
PROJECT_ID: the ID of the
Google Cloud project running Compute EngineZONE: the zone to create the VM inMACHINE_TYPE: the machine type, for example
c3-standard-4KMS_PROJECT_ID: the project that owns the
Cloud KMS keyREGION: the region where the disk is locatedKEY_RING: the name of the key ring that
includes the keyKEY: the name of the key used to
encrypt the diskSOURCE_IMAGE: the image to use when creating the
VM, for example,
projects/debian-cloud/global/images/debian-11-bullseye-v20231115Similarly, you can use the
disks.insert method
to create a new standalone Persistent Disk and encrypt it with your
Cloud KMS key:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks?sourceImage=SOURCE_IMAGE
{
"name": "DISK_NAME",
"diskEncryptionKey": {
"kmsKeyName": "projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY"
},
"type": "projects/PROJECT_ID/zones/ZONE/diskTypes/DISK_TYPE"
}
Replace the following:
PROJECT_ID: the ID of the
Google Cloud project running Compute EngineZONE: the zone to create the disk inSOURCE_IMAGE: the image to use when creating the
disk, for example,
projects/debian-cloud/global/images/debian-11-bullseye-v20231115DISK_NAME: a name for the new diskKMS_PROJECT_ID: the project that owns the
Cloud KMS keyREGION: the region where the disk is locatedKEY_RING: the name of the key ring that
includes the keyKEY: the name of the key used to
encrypt the diskDISK_TYPE: the
type of disk to createYou can create a new Hyperdisk Balanced disk in Confidential mode with the Google Cloud console, Google Cloud CLI, or REST. To create a disk that isn't in confidential mode, follow the steps in Create a Persistent Disk from a snapshot encrypted with CMEK.
Encrypt a new disk with Confidential mode for Hyperdisk Balanced by using the
gcloud compute disks create command.
Enable Confidential mode with the --confidential-compute flag and specify
the key using the --kms-key flag.
gcloud compute disks create DISK_NAME \ --type=hyperdisk-balanced \ --kms-key projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY \ --confidential-compute
Replace the following:
DISK_NAME: the name of the new diskKMS_PROJECT_ID: the project that owns the
Cloud HSM keyREGION: the region where the key is locatedKEY_RING: the name of the key ring that includes
the keyKEY: the name of the key used to encrypt the diskConstruct a POST request to the
instances.insert method.
To encrypt a disk with Confidential mode for Hyperdisk Balanced, use the diskEncryptionKey property with the
kmsKeyName property and set the enableConfidentialCompute flag. For example,
you can encrypt a new disk during VM creation with your Cloud HSM key by
using the following:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances
{
"machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
"disks": [
{
"type": "DISK_TYPE",
"diskEncryptionKey": {
"kmsKeyName": "projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY"
},
"initializeParams": {
"sourceImage": "SOURCE_IMAGE",
"enableConfidentialCompute": true
},
"boot": true
}
],
"networkInterfaces": [
{
"network": "global/networks/default"
}
]
}
Replace the following:
DISK_TYPE: the type of disk to create, for
example, hyperdisk-balancedPROJECT_ID: the ID of the Google Cloud project
running Compute EngineZONE: the zone to create the VM inMACHINE_TYPE: the machine type, for example
n2d-standard-4KMS_PROJECT_ID: the project that owns the
Cloud HSM keyREGION: the region where the disk is locatedKEY_RING: the name of the key ring that includes
the keyKEY: the name of the key used to encrypt the diskSOURCE_IMAGE: the image that supports
Confidential VM to use when creating the VM, for example,
projects/debian-cloud/global/images/debian-11-bullseye-v20231115Similarly, you can use the disks.insert method
to create a new Confidential mode for Hyperdisk Balanced:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks?sourceImage=SOURCE_IMAGE
{
"name": "DISK_NAME",
"diskEncryptionKey": {
"kmsKeyName": "projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY"
},
"type": "projects/PROJECT_ID/zones/ZONE/diskTypes/DISK_TYPE",
"enableConfidentialCompute": true
}
Replace the following:
PROJECT_ID: the ID of the
Google Cloud project running Compute EngineZONE: the zone to create the disk inSOURCE_IMAGE: the image that supports Confidential VM when creating the
disk, for example,
projects/debian-cloud/global/images/debian-11-bullseye-v20231115DISK_NAME: a name for the new diskKMS_PROJECT_ID: the project that owns the
Cloud HSM keyREGION: the region where the disk is locatedKEY_RING: the name of the key ring that
includes the keyKEY: the name of the key used to
encrypt the diskDISK_TYPE: the type of disk to create, for
example, hyperdisk-balanced.To create a snapshot from a disk that is encrypted with CMEK, you must create the snapshot with the same encryption key that you used to encrypt the disk.
You can't create a snapshot that uses a CMEK unless the source disk uses CMEK as well. Also, you can't convert CMEK-encrypted disks or snapshots to use Google Cloud default encryption unless you create a completely new disk image and a new persistent disk.
Snapshots from disks encrypted with CMEK are incremental.
For customer-managed encryption, the Cloud KMS key that was used to encrypt the disk is also used to encrypt the snapshot.
You can create your snapshot in the storage location policy defined by your snapshot settings or using an alternative storage location of your choice. For more information, see Choose your snapshot storage location.
To create a snapshot in the predefined or customized default location
configured in your snapshot settings, use the
gcloud compute snapshots create command.
gcloud compute snapshots create SNAPSHOT_NAME \
--source-disk-zone=SOURCE_ZONE \
--source-disk=SOURCE_DISK_NAME \
--snapshot-type=SNAPSHOT_TYPE
Alternatively, to override the snapshot settings and create a snapshot in
a custom storage location, include the
--storage-location flag to indicate where to store your snapshot.
gcloud compute snapshots create SNAPSHOT_NAME \
--source-disk-zone=SOURCE_ZONE \
--source-disk=SOURCE_DISK_NAME \
--snapshot-type=SNAPSHOT_TYPE \
--storage-location=STORAGE_LOCATION
(Preview) To create a regionally scoped
snapshot in an allowed region, include the --region
flag to indicate where to create your snapshot.
gcloud beta compute snapshots create SNAPSHOT_NAME \
--region=SNAPSHOT_SCOPE_REGION
--source-disk=SOURCE_DISK_NAME \
--source-disk-zone=SOURCE_ZONE \
--snapshot-type=SNAPSHOT_TYPE \
--kms-key=projects/KMS_PROJECT_ID/locations/KEY_REGION/keyRings/KEY_RING/cryptoKeys/SNAPSHOT_KEY
Replace the following:
STANDARD snapshot is created.STORAGE_LOCATION: Optional: For globally scoped snapshots, the Cloud Storage multi-region or the Cloud Storage region where you want to store your snapshot. You can specify only one storage location.
Use the --storage-location parameter only when you want to override the
predefined or customized default storage location configured in your snapshot
settings.
SNAPSHOT_SCOPE_REGION: Optional: For regionally scoped snapshots, the
region that the snapshot is scoped to. If you include this parameter, you can't use the
--storage-location parameter. The STORAGE_LOCATION is automatically
set to the SNAPSHOT_SCOPE_REGION.
You can create your snapshot in the storage location policy defined by your snapshot settings or using an alternative storage location of your choice. For more information, see Choose your snapshot storage location.
To create a snapshot in the predefined or customized default location
configured in your snapshot settings, make a POST request to the
snapshots.insert method:
POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots
{
"name": "SNAPSHOT_NAME",
"sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME",
"snapshotEncryptionKey": {
"kmsKeyName": "projects/KMS_PROJECT_ID/locations/KEY_REGION/keyRings/KEY_RING/cryptoKeys/SNAPSHOT_KEY"
},
"snapshotType": "SNAPSHOT_TYPE"
}
Alternatively, to override the snapshot settings and create a snapshot in
a custom storage location, make a POST request to the
snapshots.insert method and include the storageLocations property
in your request:
POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots
{
"name": "SNAPSHOT_NAME",
"sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME",
"snapshotEncryptionKey": {
"kmsKeyName": "projects/KMS_PROJECT_ID/locations/KEY_REGION/keyRings/KEY_RING/cryptoKeys/SNAPSHOT_KEY"
},
"snapshotType": "SNAPSHOT_TYPE",
"storageLocations": [
"STORAGE_LOCATION"
],
}
(Preview) To create a regionally scoped
snapshot in an allowed region, make a POST request to the
snapshots.insert method and define the creation region:
POST https://compute.googleapis.com/compute/beta/projects/DESTINATION_PROJECT_ID/regions/SNAPSHOT_SCOPE_REGION/snapshots
{
"name": "SNAPSHOT_NAME",
"sourceDisk": "projects/SOURCE_PROJECT_ID/regions/SOURCE_REGION/disks/SOURCE_DISK_NAME",
"snapshotType": "SNAPSHOT_TYPE",
"snapshotEncryptionKey": {
"kmsKeyName":"projects/KMS_PROJECT_ID/locations/KEY_REGION/keyRings/KEY_RING/cryptoKeys/SNAPSHOT_KEY",
},
}
Replace the following:
STANDARD snapshot is created.STORAGE_LOCATION: Optional: For globally scoped snapshots, the Cloud Storage multi-region or the Cloud Storage region where you want to store your snapshot. You can specify only one storage location.
Use the storageLocations parameter only when you want to override the
predefined or customized default storage location configured in your snapshot
settings.
SNAPSHOT_SCOPE_REGION: Optional: For regionally scoped snapshots, the
region that the snapshot is scoped to. If you include this parameter, you can't use the
storageLocations parameter. The STORAGE_LOCATION is automatically
set to the SNAPSHOT_SCOPE_REGION.
You can encrypt a new image when you import a custom image to Compute Engine. Before you can import an image, you must create and compress a disk image file and upload that compressed file to Cloud Storage.
To import and encrypt an image, use the
gcloud compute images create command.
For customer-managed encryption, specify the Cloud KMS key for
the image.
gcloud compute images create IMAGE_NAME \
--source-disk=SOURCE_DISK \
--kms-key projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY
Replace the following:
IMAGE_NAME: the name of the image you're creatingSOURCE_DISK: the name of the disk to create a snapshot
ofKMS_PROJECT_ID: the project that contains the
Cloud KMS keyREGION: the region the Cloud KMS key is
located inKEY_RING: the key ring that contains the
Cloud KMS keyKEY: the name of the key to use to encrypt the new diskTo encrypt an imported image, construct a POST request to the
images.insert method.
Specify the URI to the compressed file, add
the imageEncryptionKey property to the image creation request, and specify
the key to encrypt the image in the kmsKeyName property.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images
{
"rawDisk": {
"source": "http://storage.googleapis.com/example-image/example-image.tar.gz"
},
"name": "IMAGE_NAME",
"sourceType": "RAW",
"imageEncryptionKey": {
"kmsKeyName": "projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY"
}
}
Replace the following:
PROJECT_ID: the project to create the encrypted image
inIMAGE_NAME: the name of the image you're creatingKMS_PROJECT_ID: the project that contains the
Cloud KMS keyREGION: the region the Cloud KMS key is
located inKEY_RING: the key ring that contains the
Cloud KMS keyKEY: the name of the key that you used to
encrypt the source diskTo create a new disk from an encrypted snapshot, do the following:
Optional: If you want to specify a new encryption key, for Encryption, specify the type of encryption key to use, and then provide the encryption key information.
If you want to remove the customer managed or customer supplied encryption key, for Encryption, use the default value Google-managed encryption key.
Continue with the disk creation process.
To create a new disk from a globally scoped
encrypted snapshot, use the gcloud compute disks create command.
gcloud compute disks create DISK_NAME \ --zone=ZONE \ --source-snapshot=SNAPSHOT_NAME \ --kms-key=projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY
(Preview) To create a new
disk from a regionally scoped encrypted snapshot, use
the gcloud compute disks create command
and specify the source snapshot region.
gcloud compute disks create DISK_NAME \ --zone=ZONE \ --source-snapshot=SNAPSHOT_NAME \ --source-snapshot-region=SOURCE_REGION \ --kms-key=projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY
Replace the following:
DISK_NAME: the name of the new diskSNAPSHOT_NAME: the name of the encrypted snapshot
To use an image instead of a snapshot, replace
--source-snapshot SNAPSHOT_NAME with
--image IMAGE_NAME.
KMS_PROJECT_ID: Optional: the project that contains
the Cloud KMS key
REGION: Optional: the region the Cloud KMS
key is located in
SOURCE_REGION: The region that the source snapshot
is scoped to
ZONE: The zone where the new disk will reside
KEY_RING: Optional: the key ring that contains the
Cloud KMS key
KEY: Optional: the name of the Cloud KMS key
to use to encrypt the new disk
To encrypt the new disk, you can do one of the following:
--kms-key flag.--kms-key flag.To create a new disk from a globally scoped
encrypted snapshot, construct a POST request to the
compute.disks.insert method.
Use the sourceSnapshot property to specify the snapshot.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks
{
"name": "DISK_NAME",
"sourceSnapshot": "projects/SNAPSHOT_PROJECT_ID/global/snapshots/SNAPSHOT_NAME",
"diskEncryptionKey": {
"kmsKeyName": "projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY"
}
}
(Preview) To create a new
disk from a regionally scoped
encrypted snapshot, construct a POST request to the
compute.disks.insert method.
Use the sourceSnapshot property to specify the snapshot.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks
{
"name": "DISK_NAME",
"sourceSnapshot": "projects/SNAPSHOT_PROJECT_ID/regions/SOURCE_REGION/snapshots/SNAPSHOT_NAME",
"type": "projects/PROJECT_ID/zones/ZONE/diskTypes/DISK_TYPE",
"zone": "projects/PROJECT_ID/zones/ZONE"
"diskEncryptionKey": {
"kmsKeyName": "projects/KMS_PROJECT_ID/locations/REGION/keyRings/KEY_RING/cryptoKeys/KEY"
}
}
Replace the following:
PROJECT_ID: The project to create the new disk inZONE: The zone to create the new disk inSOURCE_REGION: The region that the source snapshot
is scoped toDISK_NAME: The name of the new diskDISK_TYPE: The full or partial URL for the
type
of the disk, for example,
PROJECT_ID/zones/ZONE/diskTypes/pd-ssdSNAPSHOT_PROJECT_ID: The project that contains the
snapshotSNAPSHOT_NAME: The name of the encrypted snapshot
To use an image instead of a snapshot, replace
sourceSnapshot with sourceImage.
KMS_PROJECT_ID: Optional: the project that contains
the Cloud KMS key
REGION: Optional: the region the Cloud KMS
key is located in
KEY_RING: Optional: the key ring that contains the
Cloud KMS key
KEY: Optional: the name of the Cloud KMS key
to use to encrypt the new disk
If you include diskEncryptionKey, then the disk is encrypted with
the specified Cloud KMS key. If you don't include
diskEncryptionKey, then the disk is encrypted using a Google-owned and Google-managed encryption key.
In the Google Cloud console, go to the Create an instance page.
Specify the VM details, and in the Boot disk section, click Change. Then, do the following:
Continue with the VM creation process.
To attach an encrypted disk when you create a new VM, use the
gcloud compute instances create command.
Use the --disk flag to specify the encrypted boot disk, as shown in the
following example:
gcloud compute instances create VM_NAME \ ... --disk name=DISK_NAME,boot=yes
Replace the following:
VM_NAME: the name of the VM you are creatingDISK_NAME: the name of the encrypted diskConstruct a POST request to the
compute.instances.insert method.
Use the disks property to specify the encrypted boot disk, as shown in the
following example:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances
{
...
"disks": [
{
"deviceName": "DISK_ALIAS",
"source": "projects/PROJECT_ID/zones/ZONE/disks/DISK_NAME"
}
]
}
Replace the following:
PROJECT_ID: the project to create the new VM inZONE: the zone to create the new VM inDISK_ALIAS: a unique device name to use as the disk
alias in the /dev/disk/by-id/google-* directory of VM that runs a
Linux operating system. This name can be used to reference the disk for
operations such as mounting or resizing from within the instance. If you don't
specify a device name, the VM chooses a default device name to apply to
this disk, in the form persistent-disk-x, where x is a number
assigned by Compute Engine. This field is only applicable for
Persistent Disk volumes.DISK_NAME: the name of the encrypted diskTo reduce the potential consequences of your key being compromised, we recommend that you rotate Cloud KMS encryption keys on a regular schedule using one of the following methods.
To rotate the Cloud KMS key that's used to encrypt a disk, an archive snapshot, or a standard snapshot to a new key version, use the
gcloud compute disks update-kms-key command
or
gcloud compute snapshots update-kms-key command.
To rotate the key version encrypting a disk:
gcloud compute disks update-kms-key DISK_NAME \ --zone ZONE
To rotate the key version encrypting a standard snapshot:
gcloud compute snapshots update-kms-key SNAPSHOT_NAME
Replace the following:
DISK_NAME: the name of the encrypted diskZONE: the zone where the encrypted disk is locatedSNAPSHOT_NAME: the name of the encrypted snapshotTo rotate the Cloud KMS key that's used to encrypt a disk, archive
snapshot, or standard snapshot to a new key version, construct a PATCH
request to the
compute.disks.updateKmsKey method
or
compute.snapshots.updateKmsKey method.
To rotate the key version encrypting a zonal disk:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks/DISK_NAME/updateKmsKey
To rotate the key version encrypting a regional disk:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/disks/DISK_NAME/updateKmsKey
To rotate the key version encrypting a globally scoped standard snapshot:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/snapshots/SNAPSHOT_NAME/updateKmsKey
(Preview) To rotate the key version encrypting a regionally scoped standard snapshot:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/snapshots/SNAPSHOT_NAME/updateKmsKey
Replace the following:
PROJECT_ID: the project where the encrypted disk or
snapshot is locatedZONE: the zone where the encrypted disk is locatedREGION: the region where the regional disk or
regionally scoped snapshot is locatedDISK_NAME: the name of the encrypted diskSNAPSHOT_NAME: the name of the encrypted snapshotREGION: the region where the regional disk or
regionally scoped snapshot is locatedThe response will include a name item with an operation value that
represents the key rotation:
"name": "operation-YYYYYYYYYYYYY-YYYYYYYYYYYYY-YYYYYYYY-YYYYYYYY"
You can then poll the status for the operation to determine if your API call
was successful by making a GET request:
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/operations/OPERATION_NAME
Replace the following:
PROJECT_ID: the project where the encrypted disk or
snapshot is locatedZONE: the zone where the encrypted disk is locatedOPERATION_NAME: the name of the CMEK rotation
operation, in the format operation-YYYYYYYYYYYYY-YYYYYYYYYYYYY-YYYYYYYY-YYYYYYYYThe response will include a progress value that represents the status of
the key rotation. When progress is 100, the operation succeeded.
Rotating keys doesn't disable or delete previous key versions. For more information, see After you rotate keys.
You can change the encryption of a disk, an archive snapshot, or a standard snapshot to a different CMEK (for example, during a project migration or to meet new compliance requirements) without downtime.
Changing the CMEK re-encrypts the resource's data encryption key (DEK) with the new key. This process doesn't change the DEK and doesn't impact performance on running workloads.
To change the Cloud KMS key you can use either the gcloud CLI or REST.
To change the Cloud KMS key for a disk or standard snapshot, use
the --kms-key flag with the
gcloud compute disks update-kms-key command
or
gcloud compute snapshots update-kms-key command.
To change the key for a zonal disk:
gcloud compute disks update-kms-key DISK_NAME \ --kms-key=projects/KEY_PROJECT_ID/locations/global/keyRings/KEY_RING/cryptoKeys/NEW_KEY_NAME \ --zone=ZONE
To change the key for a regional disk:
gcloud compute disks update-kms-key DISK_NAME \ --kms-key=projects/KEY_PROJECT_ID/locations/global/keyRings/KEY_RING/cryptoKeys/NEW_KEY_NAME \ --region=REGION
To change the key for a global snapshot:
gcloud compute snapshots update-kms-key SNAPSHOT_NAME \ --kms-key=projects/KEY_PROJECT_ID/locations/global/keyRings/KEY_RING/cryptoKeys/NEW_KEY_NAME
To change the key for a regionally scoped snapshot:
gcloud beta compute snapshots update-kms-key SNAPSHOT_NAME \ --kms-key=projects/KEY_PROJECT_ID/locations/global/keyRings/KEY_RING/cryptoKeys/NEW_KEY_NAME \ --regions=REGION
Replace the following:
DISK_NAME: the name of the encrypted disk.NEW_KMS_KEY: the full resource ID of the new CMEK.ZONE: the zone where the disk is located.REGION: the region where the disk or snapshot is located.SNAPSHOT_NAME: the name of the encrypted snapshot.To change the key, send a POST request to the
compute.disks.updateKmsKey method
or
compute.snapshots.updateKmsKey method
and include the kmsKeyName in the request body.
To change the key for a zonal disk:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks/DISK_NAME/updateKmsKey
{
"kmsKeyName": "projects/KEY_PROJECT_ID/locations/global/keyRings/KEY_RING/cryptoKeys/NEW_KEY_NAME"
}
To change the key for a regional disk:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/disks/DISK_NAME/updateKmsKey
{
"kmsKeyName": "projects/KEY_PROJECT_ID/locations/global/keyRings/KEY_RING/cryptoKeys/NEW_KEY_NAME"
}
To change the key for a global snapshot:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/snapshots/SNAPSHOT_NAME/updateKmsKey
{
"kmsKeyName": "projects/KEY_PROJECT_ID/locations/global/keyRings/KEY_RING/cryptoKeys/NEW_KEY_NAME"
}
To change the key for a regionally scoped snapshot:
POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/regions/REGION/snapshots/SNAPSHOT_NAME/updateKmsKey
{
"kmsKeyName": "projects/KEY_PROJECT_ID/locations/global/keyRings/KEY_RING/cryptoKeys/NEW_KEY_NAME"
}
Replace the following:
PROJECT_ID: the project containing the disk or
snapshot.ZONE: the zone where the disk is located.REGION: the region where the disk or snapshot is
located.DISK_NAME: the name of the disk.NEW_KEY_NAME: the name of the new CMEK.SNAPSHOT_NAME: the name of the encrypted snapshot.You can't remove a CMEK from a disk or change the encryption key's type. You can do one of the following:
Decrypt the contents of a CMEK-encrypted disk and create a new disk that uses Google Cloud default encryption instead. By default, Google Cloud encrypts all data at rest.
To create a disk that uses Google-owned and managed key from a CMEK-encrypted disk, follow these steps:
After you create the new disk, it uses Google Cloud default encryption to help protect the disk contents. Any snapshots that you create from that disk must also use default encryption.
You can't remove a CMEK from a snapshot or change the encryption key's type. You can change the snapshot to use a different CMEK, or create a copy of the snapshot and encrypt the copy with a Google-owned and managed key.
To create a snapshot that uses Google-owned and managed key from a CMEK-encrypted snapshot, follow these steps:
Create a new disk from the snapshot. When you create the new disk, select the encryption type that you want.
Create a snapshot of the new disk:
If the new disk is encrypted with a CMEK, see Create a disk from a snapshot encrypted with CMEK.
If the new disk is encrypted with a Google-owned and managed key, see Create disk snapshots.
If you no longer need a CMEK or want to prevent its use, disable or destroy the key. Deleting, disabling, or removing IAM permissions on a key is also referred to as revoking the key.
When you revoke an encryption key, resources that the key protects are affected as follows:
If you disable the key, you can reverse the preceding effects by enabling the key. If you destroy the key, you cannot reverse the preceding effects.
You can configure your VM to shutdown automatically when you revoke the Cloud KMS key that is helping to protect a disk attached to the VM. You can revoke a key by disabling or deleting it. With this setting enabled, the VM shuts down within 7 hours of key revocation.
If you enable the key again, you can restart the VM with the attached disk that the key helps to protect. The VM does not automatically restart after you enable the key.
To configure a VM to shutdown when a Cloud KMS key is revoked, do the following:
Use the gcloud compute instances create
command to create a VM, and
include --key-revocation-action-type=stop.
gcloud compute instances createVM_NAME\ --imageIMAGE\ --key-revocation-action-type=stop
Use the instances.insert method
to create a VM, and set the property
"keyRevocationActionType" to "STOP". The following example creates the
VM from a public image.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances
{
"machineType": "zones/MACHINE_TYPE_ZONE/machineTypes/MACHINE_TYPE",
"name": "VM_NAME",
"disks": [
{
"initializeParams": {
"sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
},
"boot": true
}
],
"keyRevocationActionType": "STOP"
}
Alternatively, you can configure an instance template to create VMs that shut down on key revocation by using the Google Cloud CLI or REST.
You can use an instance template to create VMs that shutdown when a Cloud KMS key is revoked.
Create an instance template by using the
gcloud compute instance-templates create command,
and include --key-revocation-action-type=stop.
gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
--key-revocation-action-type=stop
Construct a POST request to the
instanceTemplates.insert method.
In the request body, you must explicitly define all of the
required configuration fields. If you want VMs created from this template to
shut down on key revocation, specify "keyRevocationActionType":"STOP".
For example, an instance template with the minimal
required fields that will create VMs that shut down on key revocation looks
like the following:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceTemplates { "name": "example-template", "properties": { "machineType": "e2-standard-4", "networkInterfaces": [ { "network": "global/networks/default", "accessConfigs": [ { "name": "external-IP", "type": "ONE_TO_ONE_NAT" } ] } ], "disks": [ { "type": "PERSISTENT", "boot": true, "mode": "READ_WRITE", "initializeParams": { "sourceImage": "projects/debian-cloud/global/images/family/debian-11" } } ], "keyRevocationActionType": "STOP" } }
After you create a VM that is configured to shut down on Cloud KMS revocation, create and attach a Persistent Disk encrypted with a Cloud KMS key.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-07-17 UTC.