Description
Compute Engine encrypts disks with Google-managed keys by default. If you need to control the key, choose a Cloud KMS key (CMEK) or a key that you store and supply yourself (CSEK).
Potential impact
Losing a CSEK or removing required KMS permissions can prevent disk access or recovery.
Remediation
For a CSEK, Base64-encode a random 32-byte key and pass it through the protected disk_csek_base64 input. Keep the key out of code and logs, store it securely and test recovery. Restrict access to the disk separately.
Examples
Replace test_project with the project ID and set service_account_file to the path of the service account JSON file.
Before
- name: Create disk test-disk1
google.cloud.gcp_compute_disk:
name: test-disk1
size_gb: 50
zone: us-central1-a
project: test_project
auth_kind: serviceaccount
service_account_file: "/tmp/auth.pem"
state: present
- name: Create disk test-disk3
google.cloud.gcp_compute_disk:
name: test-disk3
size_gb: 50
disk_encryption_key:
raw_key:
zone: us-central1-a
project: test_project
auth_kind: serviceaccount
service_account_file: "/tmp/auth.pem"
state: present
The first task uses default encryption. The second task’s empty raw_key is not a valid CSEK.
After
- name: Create a disk with a CSEK
google.cloud.gcp_compute_disk:
name: test-disk
size_gb: 50
disk_encryption_key:
raw_key: "{{ disk_csek_base64 }}"
zone: us-central1-a
project: test_project
auth_kind: serviceaccount
service_account_file: /tmp/auth.pem
state: present
no_log: true
no_log: true suppresses the task output. This task creates a new test-disk. To move existing data, use a migration procedure supported for the current key type.