GCP Introduction
GCP Pricing
GCP Threats
GCP Misconfigurations
- Getting Started with GCP Audit
- CloudSql Audit
- Cloud Tasks Monitoring
- Dataflow Monitoring
- Function Monitoring
- Monitoring Compliance
- PubSubLite Monitoring
- Spanner Monitoring
- NoSQL Monitoring
- Compute Audit
- IAM Audit
- BigQuery Monitoring
- CDN Monitoring
- DNS Monitoring
- KMS Monitoring
- Kubernetes Audit
- Load Balancer Monitoring
- Log Monitoring
- Storage Audit
- Pub/Sub Monitoring
- VPC Audit
- IAM Deep Dive
GCP Threats
SQL Instances Should Be Encrypted Using Customer Managed Keys (CMKs)
More Info:
Ensure that SQL Instances are encrypted using Customer Managed Keys (CMKs).
Risk Level
Medium
Address
Security
Compliance Standards
HITRUST, GDPR, SOC2, NISTCSF, PCIDSS
Triage and Remediation
Remediation
Sure! Here are the step by step instructions to remediate the misconfiguration “SQL Instances Should Be Encrypted Using Customer Managed Keys (CMKs)” for GCP using GCP console:
- Open the GCP console and navigate to the Cloud SQL instances page.
- Select the SQL instance that you want to encrypt.
- Click on the “Edit” button at the top of the page.
- Scroll down to the “Encryption” section and select the option “Customer-managed key”.
- Choose the key ring and key that you want to use for encryption. If you don’t have a key, create one by clicking on the “Create” button.
- Click on the “Save” button to save the changes.
Once you have completed these steps, your SQL instance will be encrypted using the customer-managed key that you selected. It is important to note that this process requires the appropriate permissions to create and manage keys in your GCP project.
To remediate the misconfiguration of SQL instances not being encrypted using customer managed keys (CMKs) in GCP using GCP CLI, follow these steps:
-
Open the Cloud Shell in the GCP console.
-
Use the following command to list all the Cloud SQL instances in your project:
gcloud sql instances list
-
Choose the instance that you want to encrypt and note down its instance name.
-
Use the following command to encrypt the SQL instance using a customer-managed encryption key:
gcloud sql instances patch [INSTANCE_NAME] --backup-start-time 02:00 --require-ssl --storage-auto-increase --storage-size [SIZE] --storage-type [STORAGE_TYPE] --authorized-networks [NETWORK_NAME] --database-version [DATABASE_VERSION] --maintenance-window-day [DAY_OF_WEEK] --maintenance-window-hour [HOUR_OF_DAY] --maintenance-release-channel [RELEASE_CHANNEL] --encryption-key-name [KEY_NAME]
Replace
[INSTANCE_NAME]
with the name of your SQL instance,[SIZE]
with the desired storage size in GB,[STORAGE_TYPE]
with the desired storage type,[NETWORK_NAME]
with the name of the authorized network,[DATABASE_VERSION]
with the desired database version,[DAY_OF_WEEK]
with the preferred day of the week for maintenance,[HOUR_OF_DAY]
with the preferred hour of the day for maintenance,[RELEASE_CHANNEL]
with the preferred release channel for maintenance, and[KEY_NAME]
with the name of the customer-managed encryption key. -
Once you have executed the command, the SQL instance will be encrypted using the customer-managed encryption key.
-
Verify the encryption status of the SQL instance using the following command:
gcloud sql instances describe [INSTANCE_NAME]
You should see the
encryptionKeyName
property set to the name of your customer-managed encryption key.
By following these steps, you can remediate the misconfiguration of SQL instances not being encrypted using customer-managed keys (CMKs) in GCP using GCP CLI.
To remediate the misconfiguration of SQL instances not being encrypted using customer-managed keys (CMKs) in GCP, you can use the following steps:
- Create a new Cloud KMS key ring and key to use as the CMK. You can do this using the following Python code:
from google.cloud import kms_v1
kms_client = kms_v1.KeyManagementServiceClient()
parent = kms_client.key_ring_path(project_id, location_id, key_ring_id)
response = kms_client.create_crypto_key(parent, crypto_key_id, kms_v1.CryptoKey())
print(f'Created key {response.name}')
Replace project_id
, location_id
, key_ring_id
, and crypto_key_id
with your own values.
- Update the SQL instance to use the newly created CMK. You can do this using the following Python code:
from google.cloud import sql_v1beta4
sql_client = sql_v1beta4.CloudSqlInstanceServiceClient()
instance_name = f'projects/{project_id}/instances/{instance_id}'
settings = sql_v1beta4.Settings()
settings.ip_configuration.require_ssl = True
settings.ip_configuration.authorized_networks.enabled = True
encryption_settings = sql_v1beta4.EncryptionSettings()
encryption_settings.kms_key_name = f'projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}/cryptoKeys/{crypto_key_id}'
settings.encryption_configuration = encryption_settings
request = sql_v1beta4.SqlInstancesUpdateRequest(instance=instance_name, project=project_id, body={'settings': settings})
response = sql_client.update(request=request)
print(f'Updated instance {instance_name} with encryption settings')
Replace project_id
, instance_id
, location_id
, key_ring_id
, and crypto_key_id
with your own values.
- Verify that the SQL instance is now using the CMK for encryption. You can do this using the following Python code:
response = sql_client.get(instance_name)
encryption_settings = response.settings.encryption_configuration
print(f'Instance {instance_name} is now using CMK {encryption_settings.kms_key_name} for encryption')
Replace instance_name
with your own value.
These steps will remediate the misconfiguration of SQL instances not being encrypted using customer-managed keys (CMKs) in GCP.