01 Before you can set up and manage your Customer-Managed Encryption Keys (CMEKs), you must create a KMS key ring. 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-pubsub-key-ring
--location=global
--project=cc-dataflow-project-123123
--format="table(name)"
02 The command output should return the full ID of the newly created key ring:
NAME
projects/cc-dataflow-project-123123/locations/global/keyRings/cc-pubsub-key-ring
03 Run kms keys create command (Windows/macOS/Linux) to create a new Cloud KMS Customer-Managed Encryption Keys (CMEKs) within the KMS key ring created at the previous steps:
gcloud kms keys create cc-pubsub-topic-cmk
--location=global
--keyring=cc-pubsub-key-ring
--purpose=encryption
--protection-level=software
--rotation-period=90d
--next-rotation-time=2020-7-12T10:00:00.0000Z
--format="table(name)"
04 The command output should return the name of the new Customer-Managed Encryption Key (CMEK):
NAME
projects/cc-dataflow-project-123123/locations/global/keyRings/ccc-pubsub-key-ring/cryptoKeys/cc-pubsub-topic-cmk
05 Run projects add-iam-policy-binding command (Windows/macOS/Linux) to assign the Cloud KMS "CryptoKey Encrypter/Decrypter" role to the necessary service account. Replace <kms-project-id>
with the ID of the Google Cloud project where the Customer-Managed Encryption Keys are provisioned, and replace <project-number>
with the project number (not the project ID) of the Google Cloud project that is running your Pub/Sub topics:
gcloud projects add-iam-policy-binding <kms-project-id>
--member serviceAccount:service-<project-number>@gcp-sa-pubsub.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>@gcp-sa-pubsub.iam.gserviceaccount.com
role: roles/cloudkms.cryptoKeyEncrypterDecrypter
- members:
- user:admin@cloudconformity.com
role: roles/owner
etag: abcdabcdabcd
version: 1
07 Run pubsub topics list-subscriptions command (Windows/macOS/Linux) using the name of the Pub/Sub topic that you want to re-create as identifier parameter and custom query filters to describe the subscriptions created for the selected topic:
gcloud pubsub topics list-subscriptions cc-dataflow-app-topic
--format=json
08 The command output should return the requested topic information:
[
"projects/cc-dataflow-project-123123/subscriptions/cc-dataflow-public-subscription",
"projects/cc-dataflow-project-123123/subscriptions/cc-dataflow-client-subscription"
]
09 Run pubsub topics create command (Windows/macOS/Linux) to create the new Google Cloud Pub/Sub topic that encrypts published messages with the Customer-Managed Encryption Key (CMEK) created at step no. 3:
gcloud pubsub topics create cc-encrypted-dataflow-topic
--topic-encryption-key=projects/cc-dataflow-project-123123/locations/global/keyRings/ccc-pubsub-key-ring/cryptoKeys/cc-pubsub-topic-cmk
10 The command output should return the full resource identifier of the newly created topic:
Created topic [projects/cc-dataflow-project-123123/topics/cc-encrypted-dataflow-topic].
11 Run pubsub subscriptions create command (Windows/macOS/Linux) to create the required subscription for the newly created Pub/Sub topic so that subscribers can receive messages published to the new CMK-encrypted topic. Repeat this step to create as many subscriptions as needed:
gcloud pubsub subscriptions create cc-encrypted-dataflow-subscription
--topic=cc-encrypted-dataflow-topic
--topic-project=cc-dataflow-project-123123
12 The command output should return the resource ID of the newly created subscription:
Created subscription [projects/cc-dataflow-project-123123/subscriptions/cc-encrypted-dataflow-subscription].
13 If required, update your application to point to the new Pub/Sub topic and subscriptions.
14 To stop adding unnecessary charges to your Google Cloud monthly bill you can remove the source topic from your GCP project. Run pubsub topics delete command (Windows/macOS/Linux) using the ID of the resource that you want to delete (see Audit section part II to identify the source topic), to delete the specified Pub/Sub topic:
gcloud pubsub topics delete cc-dataflow-app-topic
15 The command output should return the resource ID of the deleted Pub/Sub topic:
Deleted topic [projects/massive-woods-273512/topics/cc-dataflow-app-topic]
16 Run pubsub subscriptions delete command (Windows/macOS/Linux) using the name of the topic subscription that you want to delete (see Audit section part II to identify the right resource), to delete the specified subscription:
gcloud pubsub subscriptions delete cc-dataflow-public-subscription
17 The command output should return the resource ID of the deleted topic subscription:
Deleted subscription [projects/cc-dataflow-project-123123/subscriptions/cc-dataflow-public-subscription]
18 Repeat steps no. 7 – 17 to enable encryption with Customer-Managed Encryption Keys (CMEKs) for other Pub/Sub topic provisioned in the selected project.
19 Repeat steps no. 1 – 18 for each GCP project deployed in your Google Cloud account.