Skip to main content

Triage and Remediation

Remediation

Using Console

To allow public (external) access to a Cloud SQL for PostgreSQL instance in GCP using the Console, you need to add a public IP (you can keep the private IP as well if needed).

Step-by-step in GCP Console

  1. Go to Cloud SQL
    • In the Google Cloud Console, go to:
      Navigation menu → Databases → SQL
    • Click on your PostgreSQL instance.
  2. Open the Connections settings
    • In the instance page, click the Edit button at the top.
    • In the left or central tabs, find and click Connections.
  3. Enable Public IP
    • Scroll to the Connectivity or IP addresses section.
    • Under Public IP, check Assign a public IP address (or Add network / Add public IP depending on UI version).
    • The Console will show that a public IP will be assigned on save.
  4. Configure Authorized Networks (Firewall for DB)
    • Still under Public IP, find Authorized networks.
    • Click Add Network.
    • Enter:
      • Name: A label for the client/network (e.g., office-network or dev-laptop).
      • Network: The IP or CIDR that should be allowed (e.g., 203.0.113.10/32 for a single IP).
    • Repeat for all client IPs that need access.
    • Avoid 0.0.0.0/0 unless this is a controlled test environment and you fully understand the risk.
  5. Save changes
    • Scroll down and click Save.
    • Wait for the instance to finish updating (status changes back to RUNNABLE).
  6. Get the public IP and connect
    • In the instance Overview page, under Connect to this instance or Instance IP addresses, note the Public IP address.
    • Use this host in your PostgreSQL client connection string:
      • Host: the public IP
      • Port: default 5432 unless you changed it
      • User/password / database as configured.
  7. (Optional) Keep or remove Private IP
    • If you no longer want private-only access:
      • Go back to Edit → Connections.
      • Under Private IP, uncheck / remove private IP assignment (if your design allows).
      • Save again.
This remediates the configuration from “private-only” to “private + public” (or public-only) access using the GCP Console.
To remediate “PostgreSQL Instance IP Assignment Set To Private” in GCP (i.e., enable a public IPv4 address) via gcloud, do the following:

1. Make sure you have the right project and auth


2. Check current IP configuration of the instance

Confirm it only has PRIVATE and no PRIMARY / PUBLIC IPv4.
Decide which client IPs should be allowed to connect to the public IP.Example: allow only one office IP and one VPN IP:

4. Enable public IPv4 on the instance

Use gcloud sql instances patch with --assign-ip. You can optionally add authorized networks at the same time.
Notes:
  • --assign-ip adds a public IPv4 address (keeps private IP if already enabled).
  • If you don’t want to set authorized networks now, just omit the flag and add them later.

5. Verify that a public IP was assigned

You should now see an entry like:

6. (Optional) Adjust or add authorized networks later

To update the allowed IP ranges:
This overwrites the existing list with the one you provide.
These commands will change the instance from “private-only” to having a public IPv4 endpoint while retaining the private IP if it was already configured.
Below is how to change a Cloud SQL for PostgreSQL instance so it has a public IP (in addition to or instead of private IP) using Python.

1. Prerequisites

  1. Cloud SQL Admin API must be enabled:
  2. Authentication:
    • Use a service account with the roles/cloudsql.admin role.
    • Set GOOGLE_APPLICATION_CREDENTIALS to point to its JSON key, or run this from an environment with default credentials (e.g., Cloud Shell, Cloud Run with attached service account).
  3. Install libraries:

2. Python code to add a public IP

This example:
  • Adds a public IP to an existing PostgreSQL instance.
  • Keeps existing private IP settings intact (if any).
  • Optionally restricts access with authorizedNetworks.
Replace:
  • PROJECT_ID with your project ID
  • INSTANCE_NAME with your Cloud SQL instance name
  • NETWORK_CIDR with your allowed CIDR (or remove authorizedNetworks block if not needed)

3. Notes / Variations

  • Keep both private and public IP:
    The code above leaves any existing privateNetwork and pscConfig untouched; it just enables ipv4Enabled. That gives you dual (private + public) connectivity.
  • Remove public IP later (if needed): Set ip_config["ipv4Enabled"] = False and patch again.
  • No network restriction: If you omit authorizedNetworks, any IP can attempt to connect (still needs DB auth). For better security, always define authorizedNetworks.
This is the standard remediation path if your security policy requires a publicly reachable PostgreSQL Cloud SQL instance instead of only private IP.
Changing an existing Cloud SQL instance from public IP to private IP (private_network plus ipv4_enabled = false) can force replacement of the instance, which may cause downtime; review the terraform plan carefully before applying.For verification, terraform plan should show the google_sql_database_instance gaining settings.ip_configuration.private_network and ipv4_enabled = false, and (for an existing public-only instance) it may show the instance being replaced along with creation of the networking/peering resources if they are new.