Skip to main content

Triage and Remediation

Remediation

Using Console

To remediate the misconfiguration “PubSub Topics Should Be Encrypted Using CMEK” for GCP using GCP console, you can follow the below steps:
  1. Login to your GCP console.
  2. Navigate to the Pub/Sub page from the left-hand side menu.
  3. Select the topic that you want to encrypt using CMEK.
  4. Click on the “Edit” button present at the top of the page.
  5. Scroll down to the “Encryption” section.
  6. Click on the “Enable encryption” checkbox.
  7. Select the “Customer-managed key” option from the dropdown.
  8. Choose the CMEK key that you want to use for encryption from the “Key name” dropdown.
  9. Click on the “Save” button to save the changes.
Once you have completed these steps, your Pub/Sub topic will be encrypted using the selected CMEK key.

To remediate the misconfiguration in GCP using GCP CLI, follow these steps:
  1. Open the Cloud Shell in the GCP Console.
  2. Set the project where the Pub/Sub topic is located:
  1. Retrieve the list of Pub/Sub topics in the project:
  1. For each topic that does not have encryption enabled, enable encryption using the following command:
Replace [TOPIC_NAME] with the name of the Pub/Sub topic that needs to be encrypted, and replace [PROJECT_ID], [LOCATION], [KEYRING_NAME], and [KEY_NAME] with the appropriate values for your project.
  1. Verify that the encryption has been enabled for the topic by running the following command:
The output should include the following line:
This indicates that the topic is now encrypted using a customer-managed encryption key (CMEK).
To remediate the misconfiguration where PubSub topics should be encrypted using CMEK in GCP using Python, you can follow these step-by-step instructions:
  1. First, ensure that you have the necessary permissions to create a new key ring and key in the Cloud KMS service.
  2. Next, you will need to create a new key ring and key in the Cloud KMS service. You can do this using the following Python code:
  1. Once you have created the key ring and key, you can use it to encrypt your PubSub topics. You can do this using the following Python code:
  1. Finally, you can verify that your PubSub topic is encrypted using CMEK by checking the topic details in the GCP Console or by using the following Python code:
These steps will help you remediate the misconfiguration where PubSub topics should be encrypted using CMEK in GCP using Python.
Changing or adding kms_key_name on an existing google_pubsub_topic forces replacement of the topic, which may cause a brief outage and loss of unacknowledged messages during the recreate.To verify, terraform plan should show the google_pubsub_topic either being created with kms_key_name = google_kms_crypto_key.pubsub_cmek.id or updated by replacing the existing topic to set that kms_key_name.