For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/terraform-gcp-sql-db-instance-is-publicly-accessible.md.
A documentation index is available at /llms.txt.
A Google Cloud SQL instance becomes publicly accessible when it has public IP addressing enabled without proper network restrictions, creating a potential attack vector for unauthorized access. This can occur when ipv4_enabled is set to true (default), or when authorized_networks is configured with overly permissive CIDR ranges such as 0.0.0.0/0, which allows connections from any IP address.
To secure Cloud SQL instances, either disable public IP by setting ipv4_enabled to false and specifying a private_network (for example, ipv4_enabled = false and private_network = "your-network-id"), or restrict authorized_networks to specific trusted IP ranges (for example, authorized_networks { name = "trusted-network", value = "10.0.0.0/24" }) rather than using 0.0.0.0/0.
resource"google_sql_database_instance""positive1"{name="master-instance"database_version="POSTGRES_11"region="us-central1"settings{ # Second-generation instance tiers are based on the machine
# type. See argument reference below.
tier="db-f1-micro"}}resource"google_sql_database_instance""positive2"{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"}}}}resource"google_sql_database_instance""positive3"{name="master-instance"database_version="POSTGRES_11"region="us-central1"settings{ # Second-generation instance tiers are based on the machine
# type. See argument reference below.
tier="db-f1-micro"ip_configuration{ipv4_enabled=true}}}resource"google_sql_database_instance""positive4"{name="master-instance"database_version="POSTGRES_11"region="us-central1"settings{ # Second-generation instance tiers are based on the machine
# type. See argument reference below.
tier="db-f1-micro"ip_configuration{}}}
1
2
rulesets:- Terraform / GCP # Rules to enforce / GCP.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.