Triage and Remediation
Remediation
Using Console
Using Console
Here are the step-by-step instructions to remediate the “Database Instances Should Not Have Public IPs” misconfiguration in GCP using the GCP console:
- Open the GCP Console and go to the Cloud SQL Instances page.
- Select the instance for which you want to remove the public IP.
- Click the Edit button at the top of the page.
- In the Connectivity section, click on the “Public IP” dropdown and select “None”.
- Click the Save button to apply the changes.
- After removing the public IP, make sure to update your application or services to use the private IP address of the instance for database connectivity.
- Verify that the public IP has been removed by checking the instance details page. The “Public IP” field should show as “None”.
Using CLI
Using CLI
To remediate the misconfiguration “Database Instances Should Not Have Public IPs” for GCP using GCP CLI, follow these steps:Replace
- Open the Cloud Shell from the GCP console.
- Run the following command to list all the database instances in your GCP project:
- Identify the instance that has a public IP address.
- Run the following command to update the instance’s settings and remove the public IP address:
[INSTANCE_NAME]
with the name of the instance that has a public IP address.- Confirm the changes by running the following command:
- Verify that the instance no longer has a public IP address in the output.
Using Python
Using Python
To remediate the misconfiguration of having public IPs on database instances in GCP using Python, follow these steps:Note: This script uses the
-
Identify the database instances that have public IPs assigned to them.
- You can use the
google-cloud-sdk
commandgcloud sql instances list
to list all the database instances in your project. - Then, you can check the
ipAddresses
field of each instance to see if it has a public IP assigned to it.
- You can use the
-
Update the network settings of the database instances to remove the public IP.
- You can use the
google-cloud-sdk
commandgcloud sql instances patch
to update the network settings of the instance. - Set the
authorized-networks
parameter to the list of CIDR blocks that are allowed to access the instance. - Set the
require-ssl
parameter to enforce SSL connections to the instance.
- You can use the
-
Verify that the public IP has been removed from the database instance.
- You can use the
google-cloud-sdk
commandgcloud sql instances describe
to check the network settings of the instance. - Verify that the
ipAddresses
field does not contain a public IP address.
- You can use the
google-cloud-sql
library to interact with the Cloud SQL API. You can install it using pip install google-cloud-sql
. Also, make sure that the service account used by the script has the necessary permissions to update the network settings of the database instances.