01 Before you can set up and manage your Customer-Managed Keys (CMKs), you must create a key ring. A KMS key ring is a grouping of cryptographic keys made available for organizational purposes in a specific Google Cloud location. Run kms keyrings create command (Windows/macOS/Linux) to create a new Cloud KMS key ring in the specified location. If the CMKs created later within this key ring will be used to encrypt/decrypt resources in a given region, select that region as the key ring location:
gcloud kms keyrings create cc-webdata-key-ring
--location=us
--project=cc-web-project-112233
--format="table(name)"
02 The command output should return the identifier (name) of the newly created key ring:
NAME
projects/cc-web-project-112233/locations/us/keyRings/cc-webdata-key-ring
03 Run kms keys create command (Windows/macOS/Linux) to create a new Cloud KMS Customer-Managed Key (CMK) within the KMS key ring created at the previous steps:
gcloud kms keys create cc-webdata-cmk
--location=us
--keyring=cc-webdata-key-ring
--purpose=encryption
--protection-level=software
--rotation-period=90d
--next-rotation-time=2020-10-10T12:00:00.0000Z
--format="table(name)"
04 The command output should return the name (ID) of the new Customer-Managed Key (CMK):
NAME
projects/cc-web-project-112233/locations/us/keyRings/cc-webdata-key-ring/cryptoKeys/cc-webdata-cmk
05 Run projects add-iam-policy-binding command (Windows/macOS/Linux) to assign the Cloud KMS "CryptoKey Encrypter/Decrypter" role to the Cloud Storage service account, in order to give the service account the permission to use your new CMK. Replace <kms-project-id>
with the ID of the Google Cloud project where the Customer-Managed Keys are provisioned, and replace <project-number>
with the project number of the Google Cloud project that is using your Cloud Storage buckets:
gcloud projects add-iam-policy-binding <kms-project-id>
--member serviceAccount:service-<project-number>@gs-project-accounts.iam.gserviceaccount.com
--role roles/cloudkms.cryptoKeyEncrypterDecrypter
06 The command output should return the updated IAM policy (YAML format):
Updated IAM policy for project <kms-project-id>.
bindings:
- members:
- serviceAccount:service-<project-number>@gs-project-accounts.iam.gserviceaccount.com
role: roles/cloudkms.cryptoKeyEncrypterDecrypter
- members:
- user:admin@cloudrealisation.com
role: roles/editor
- members:
- serviceAccount:service-<project-number>@compute-system.iam.gserviceaccount.com
- user:admin@cloudconformity.com
role: roles/owner
etag: abcdabcdabcd
version: 1
07 Run gsutil kms encryption command (using gsutil Python tool) using the name of the Cloud Storage bucket that you want to reconfigure as identifier parameter and the name (ID) of your new Cloud KMS Customer-Managed Key as value for the --k parameter, to enable encryption at rest for the selected bucket, using Customer-Managed Keys (CMKs):
gsutil kms encryption
-k projects/cc-web-project-112233/locations/us/keyRings/cc-webdata-key-ring/cryptoKeys/cc-webdata-cmk gs://cc-webdata-bucket/
08 The output should return the gsutil kms encryption command request status:
Authorized service account service-<project-number>@gs-project-accounts.iam.gserviceaccount.com to use key:
projects/cc-web-project-112233/locations/us/keyRings/cc-webdata-key-ring/cryptoKeys/cc-webdata-cmk
Setting default KMS key for bucket gs://cc-webdata-bucket...
09 Repeat step no. 7 and 8 to configure encryption with Customer-Managed Keys (CMKs) for other storage buckets created for the selected project.
10 Repeat steps no. 1 – 9 for each project available within your Google Cloud account.