Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Below are step‑by‑step console instructions to properly configure and remediate cryptographic key issues for GCP Compute Engine using Cloud KMS (CMEK). This covers the most common misconfigurations: using default Google‑managed keys only, not rotating keys, and incorrect IAM on keys.
1. Create or Verify a Cloud KMS Key (CMEK)
- In the Google Cloud Console, go to:
Security → Key Management (or search “Key Management”). - Ensure you’re in the correct project (top nav).
- Click Create key ring:
- Name: e.g.
compute-keyring - Location type: usually Regional
- Location: choose the same region as your Compute Engine resources.
- Click Create.
- Name: e.g.
- On the new key ring, click Create key:
- Name: e.g.
compute-disk-key - Protection level: Software (or HSM if required by policy).
- Purpose: Symmetric encryption/decryption.
- Rotation period: set per your policy (e.g.
90 days) and enable automated rotation. - Click Create.
- Name: e.g.
2. Grant Compute Engine Permission to Use the Key
You must allow the Compute Engine service account to use the key.- Identify the service account:
- For project‑wide default, it’s usually:
PROJECT_NUMBER-compute@developer.gserviceaccount.com - To confirm, go to IAM & Admin → Service Accounts and find:
- “Compute Engine default service account” or
- The custom service account attached to your VM(s).
- For project‑wide default, it’s usually:
- In the console, go to Security → Key Management → Key rings.
- Click the key ring, then click your key (e.g.
compute-disk-key). - Go to the Permissions tab.
- Click Grant access:
- New principals: add the Compute service account from step 1.
- Role:
- Prefer fine‑grained: Cloud KMS CryptoKey Encrypter/Decrypter
(or at minimum what your policy requires).
- Prefer fine‑grained: Cloud KMS CryptoKey Encrypter/Decrypter
- Click Save.
3. Use CMEK for New Disks / New VMs
You cannot change the encryption key of an existing disk in place; you must create a new disk or snapshot+disk using the CMEK.3.1 New VM with CMEK‑encrypted boot disk
- Go to Compute Engine → VM instances.
- Click Create instance.
- Under Boot disk, click Change.
- Select your image as usual.
- Expand the Advanced options or Encryption section.
- Select Customer‑managed key (CMEK).
- Click Browse and select your key:
- Choose the correct Key ring and Key created earlier.
- Click Select (for the disk), then Create (for the VM).
3.2 New additional data disk with CMEK
- While creating or editing a VM, under Additional disks, click Add new disk.
- Configure disk type/size.
- Expand Encryption options.
- Choose Customer‑managed key (CMEK) and select your KMS key.
- Save and create/update the VM.
4. Migrate Existing Disks to CMEK
To remediate existing disks not using CMEK:4.1 Using snapshots
- Go to Compute Engine → Disks.
- Select the disk you want to remediate.
- Click Create snapshot:
- Name the snapshot (e.g.
disk1-snap-cmek-migrate). - Encryption:
- Choose Customer‑managed key (CMEK).
- Select your KMS key.
- Click Create.
- Name the snapshot (e.g.
- After snapshot is ready, go to Compute Engine → Disks → Create disk:
- Source type: Snapshot.
- Source snapshot: select the snapshot you just created.
- Under Encryption, choose Customer‑managed key (CMEK) and select the same key.
- Click Create.
- Stop the VM that used the original disk.
- Detach the old disk and attach the new CMEK‑encrypted disk:
- VM details → Edit → detach old disk, add existing disk (the new CMEK disk).
- Start the VM and verify it functions correctly.
- Once confirmed, delete the old, non‑CMEK disk if no longer needed.
5. Fix Key Rotation and Lifecycle
If the misconfiguration is about non‑rotating or long‑lived keys:- Go to Security → Key Management.
- Click your key.
- Under Rotation schedule:
- Ensure Automatic rotation is enabled.
- Set a rotation period that complies with policy (e.g. 30–90 days).
- If you need a new primary key version immediately:
- On the Versions tab, click Add new version.
- (Optional) After validation, Disable or Destroy older key versions according to your retention policy.
6. Tighten IAM on Keys
To remediate over‑permissive KMS IAM:- Go to Security → Key Management → Key rings → [your key] → Permissions.
- Remove broad roles from wide groups/principals:
- Avoid
roles/owner,roles/editor, orroles/cloudkms.adminfor large groups.
- Avoid
- Only keep:
- Service accounts that need
Encrypter/Decrypterto read/write disks. - Limited admins for
Cloud KMS Adminif required.
- Service accounts that need
- Click Save.
7. Validate the Remediation
- For each VM:
- Go to Compute Engine → VM instances → [VM].
- Under Boot disk / Additional disks, check Encryption shows your CMEK key.
- For the KMS key:
- Confirm Rotation is enabled.
- Confirm IAM is appropriately restricted.
- Optionally, run Security Command Center or Policy Scanner (if in use) to confirm findings about “cryptographic keys” are cleared.
Using CLI
Using CLI
Below is a practical, step‑by‑step way to remediate common “Cryptographic Keys” misconfigurations for GCP Compute Engine using the gcloud CLI, focused on moving from default Google‑managed encryption to Cloud KMS CMEK and tightening key controls.If your specific finding text is different (e.g., about service account keys or SSH keys), tell me the exact finding and I’ll adapt.
You’ll need an IAM identity with (at least):
Grant it If you use a custom service account for VMs, also grant that account:
For boot disks, safest route is:Then migrate traffic and delete the old instance.
KMS handles key versions; CMEK resources continue to work with new versions automatically.
Remove any (where
If you can paste the exact “Cryptographic Keys” finding text (e.g., from Security Command Center or CIS benchmark), I’ll tailor these commands exactly to that control (disks, snapshots, images, etc.).
1. Prerequisites
roles/ownerorroles/compute.admin+roles/cloudkms.admin+roles/cloudkms.cryptoKeyEncrypterDecrypter
2. Create a KMS Key Ring and Crypto Key
3. Grant Compute Engine Access to the Key
Identify the Compute Engine service agents (at project level):cryptoKeyEncrypterDecrypter:4. Create New Disks/VMs Encrypted with CMEK
4.1 New Disk with CMEK
4.2 New VM with CMEK Root Disk
5. Migrate Existing Disks to CMEK
You can’t flip an existing disk’s key in place; you must recreate it from a snapshot or image using CMEK.5.1 Snapshot the Existing Disk
5.2 Create a New Disk from Snapshot Using CMEK
5.3 Attach New Disk / Replace Boot Disk
For data disks, detach the old one and attach the new:- Stop VM.
- Create an image from the existing boot disk.
- Create a new VM from that image with
--boot-disk-kms-key=.... - Re‑apply network/metadata settings and delete the old VM.
6. Enforce Key Rotation
Set rotation period and next rotation time:7. Harden KMS IAM
Review and remove overly broad access:allUsers, allAuthenticatedUsers, or unnecessary roles, and keep to:roles/cloudkms.cryptoKeyEncrypterDecrypterfor only required service accounts.roles/cloudkms.adminfor a small admin group.
policy.json is your edited IAM policy).If you can paste the exact “Cryptographic Keys” finding text (e.g., from Security Command Center or CIS benchmark), I’ll tailor these commands exactly to that control (disks, snapshots, images, etc.).
Using Python
Using Python
Below is a concise, step‑by‑step approach to remediate cryptographic key misconfigurations for Google Compute Engine (GCE) using Python, focusing on:
Any disk equal to
If you paste a specific current configuration (disk/instance JSON or output of
- Moving from Google‑managed to customer‑managed encryption keys (CMEK)
- Correct IAM permissions on keys
- Enforcing proper key rotation and usage
1. Identify Where CMEK Should Be Used
Common targets:- Boot disks and data disks on VM instances
- Images and snapshots
Google managed in encryptionKey is a remediation target.2. Set Up KMS for CMEK
2.1. Enable APIs (one time)
2.2. Create a Key Ring and Crypto Key
Using Python (Cloud KMS client):3. Grant the Compute Service Account Access to the Key
Each instance uses a service account. That SA needsroles/cloudkms.cryptoKeyEncrypterDecrypter on the crypto key.Typical default GCE service account:PROJECT_NUMBER-compute@developer.gserviceaccount.com4. Create New Disks/VMs with CMEK (Python)
CMEK cannot be applied in-place to an existing disk. You must create new disks with CMEK and migrate.4.1. Create a CMEK‑Encrypted Disk
4.2. Create a VM Using CMEK for Boot Disk
5. Migrate Existing Disks to CMEK
For each non‑CMEK disk:- Create a snapshot of the disk.
- Create a new disk from that snapshot with CMEK.
- Detach the old disk from the instance.
- Attach the new CMEK disk.
- Delete the old disk when verified.
5.1. Snapshot the Existing Disk
5.2. Create New Disk from Snapshot with CMEK
5.3. Detach Old Disk and Attach New Disk
6. Harden Key Management
- Restrict IAM on KMS keys:
- Only necessary service accounts:
roles/cloudkms.cryptoKeyEncrypterDecrypter - Admins:
roles/cloudkms.adminwith least privilege.
- Only necessary service accounts:
- Enable key rotation (already set in Step 2.2).
- Disable or destroy old keys only after:
- All disks/images/snapshots no longer depend on them.
- Audit:
- Enable Cloud Logging & Cloud Audit Logs for KMS.
-
Periodically verify disks use CMEK:
If you paste a specific current configuration (disk/instance JSON or output of
gcloud compute instances describe), I can give tailored Python snippets to fix exactly that setup.Using Terraform
Using Terraform
- Substitute:
COMPUTE_KMS_KEY_RING_NAME,KMS_LOCATION,COMPUTE_KMS_KEY_NAME,DISK_NAME,COMPUTE_ZONE,INSTANCE_NAME,MACHINE_TYPE,BOOT_IMAGE_SELF_LINK,NETWORK_SELF_LINK,SUBNETWORK_SELF_LINKwith your actual values and project via thegoogleprovider.
- Changing an existing disk’s encryption key typically forces disk replacement; any instance using that disk may be recreated or require reattachment, so plan for downtime or data migration.
- Verification:
terraform planshould show thedisk_encryption_key.kms_key_self_linkbeing added (or changed) on eachgoogle_compute_diskandgoogle_compute_instance.boot_disk/attached_diskthat needs CMEK.

