Google Cloud SQL network settings need review

Review Cloud SQL connection paths and authorized client addresses, and restrict unnecessary public access.

Description

authorized_networks controls which IPv4 clients can attempt a direct public-IP connection. Cloud SQL Auth Proxy and language connectors can use either public or private IP with the appropriate IAM permissions, without an authorized-network entry.

Potential impact

An overly broad range admits unnecessary database login attempts. Clients that also have valid credentials and database permissions may read or change data.

Remediation

For direct public connections, allow only the actual client ranges. For private-only access, establish and test private connectivity, such as private IP or Private Service Connect, before explicitly disabling public IPv4. Omitting ipv4_enabled does not turn it off. Check IAM and database permissions, test legitimate connections and confirm unapproved direct connections are blocked.

Examples

Both examples use POSTGRES_11. Check support for your provider and database versions. The private example needs google_compute_network.private and private services access. Its resource and instance names identify a different database. To keep the existing instance, change its network settings and review the plan. To switch to the separate instance, migrate and verify the data first.

Before

hcl
resource "google_sql_database_instance" "public_sql_instance" {
  name             = "postgres-instance-2"
  database_version = "POSTGRES_11"

  settings {
    tier = "db-f1-micro"

    ip_configuration {
      authorized_networks {
        name  = "pub-network"
        value = "0.0.0.0/0"
      }
    }
  }
}

0.0.0.0/0 allows every IPv4 address to attempt a direct connection. Database authentication still applies.

After

hcl
resource "google_sql_database_instance" "private_sql_instance" {
  name             = "private-instance-1"
  database_version = "POSTGRES_11"

  settings {
    tier = "db-f1-micro"

    ip_configuration {
      ipv4_enabled    = false
      private_network = google_compute_network.private.id
    }
  }
}

ipv4_enabled = false disables public IPv4. Verify clients can reach the instance on the VPC specified by private_network.

References