Other Articles
- Cloud SQL – Configure Private IP
- Cloud SQL – Monitor CPU Utilization
- Cloud SQL – Enable Deletion Protection
- Cloud SQL – Enable Disk Encryption
- Cloud SQL – Enable Automated Backups
- Cloud SQL – Enable Log Export
- Cloud SQL – Enforce Password Validation
- Cloud SQL – Protect From Internet Access
- Cloud SQL – Enforce Secure Transport
- Compute Engine – Block Project-Wide SSH Keys
- Compute Engine – Disable IP Forwarding
- Compute Engine – Disable Public IP Addresses
- Compute Engine – Disable Serial Port Access
- Compute Engine – Enable Confidential Computing
- Compute Engine – Enable OS Login
- Compute Engine – Enable Shielded VM
- Compute Engine – Restrict Default Service Account
- General – Deny Public Access to KMS Keys
- General – Enforce Duties Separation
- General – Enforce KMS Key Rotation
- General – Restrict Admin Roles on Service Accounts
- Cloud Run – Configure Timeout Settings
- Cloud Storage – Enable Bucket Encryption
- Cloud Storage – Enable Bucket Logging
- Cloud Storage – Enable Bucket Versioning
- Cloud Storage – Enforce Uniform Bucket-Level Access
- Cloud Storage – Restrict Public Access
- IAM Users – Enforce GCP-Managed Keys
- IAM Users – Rotate External User-Managed Service Account Keys
- GKE – Enable Private Nodes
- GKE – Restrict Control Plane Access
- GKE – Enable Workload Identity
- GKE – Disable Legacy ABAC
- GKE – Enable Network Policy
- GKE – Enable Shielded Nodes
- GKE – Enable Node Auto-Upgrade and Auto-Repair
- GKE Cluster – Enable Cluster Logging
- General – Enable Cloud Audit Logs
- General – Configure a Log Sink
- General – Configure Log Bucket Retention
- Cloud SQL – Enable High Availability
- Cloud SQL – Configure Maintenance Window
- Cloud Storage – Configure Bucket Retention or Lifecycle
- General – Enable Security Command Center
- Compute Engine – Enable Instance Deletion Protection
- VPC Firewall – Restrict Public SSH and RDP Access
- VPC Network – Avoid the Default Network
- VPC Network – Enable Subnet Flow Logs
VPC Firewall – Restrict Public Database Access
Secure Configuration Checks > GCP
This check ensures that no VPC firewall rule allows common database ports to be reached from the entire internet.
The ports are MySQL (3306), PostgreSQL (5432), SQL Server (1433),
MongoDB (27017), Redis (6379) and Elasticsearch (9200, 9300).
Check Details
- Resource: VPC Network (firewall rules)
- Check: Restrict public database access
- Risk: Exposed databases are a leading cause of data theft and ransom attacks. Attackers can read, change or delete the data.
Remediation via Google Cloud Console
-
Log in to the Google Cloud Console and navigate to
VPC network > Firewall.
-
Find enabled ingress allow rules that expose database
ports to
0.0.0.0/0or::/0. Also check rules that allow all TCP ports or all protocols. -
Click the firewall rule name and then click Edit.
-
Under Source filter, replace the public source range
with trusted application IP ranges or appropriate source tags or
service accounts. Check the IPv4 and IPv6 source ranges separately
where applicable.
- Review Protocols and ports to ensure that only the required database ports are allowed. Click Save.
- If the firewall rule is not required, select it and click Delete instead.
- Repeat these steps for every affected firewall rule.
Remediation via Google Cloud CLI
-
Open the Google Cloud Console and launch
Cloud Shell.
-
List the enabled ingress rules that allow a database port from the internet:
PORTS="3306 5432 1433 27017 6379 9200 9300" gcloud compute firewall-rules list --format=json | \ jq -r --arg ports "$PORTS" ' ($ports | split(" ") | map(tonumber)) as $p | .[] | select(.direction == "INGRESS" and (.disabled | not)) | select((.sourceRanges // []) | any(. == "0.0.0.0/0" or . == "::/0")) | select(any(.allowed[]?; .IPProtocol == "all" or (.IPProtocol == "tcp" and (.ports == null or any((.ports[] | split("-") | map(tonumber)) as $r | $p[]; . >= $r[0] and . <= $r[-1]))))) | [.name, (.network | split("/") | last)] | @tsv'The output shows the rule name and its network. Cloud SQL instances with a public IP are not covered by firewall rules. See Cloud SQL – Protect From Internet Access.
-
Limit the source of the rule to the range of your application subnet:
gcloud compute firewall-rules update <RULE_NAME> --source-ranges=<TRUSTED_CIDR>
Replace
<RULE_NAME>with the rule name and<TRUSTED_CIDR>with an internal range, for example10.0.1.0/24. If the rule also allows other ports, create a separate rule for them first. -
Or delete the rule if it is not needed:
gcloud compute firewall-rules delete <RULE_NAME>
-
Verify the rule:
gcloud compute firewall-rules describe <RULE_NAME> \ --format="yaml(name,sourceRanges,allowed)"
Default Value
By default, no database port is open to the internet. Ingress traffic is denied unless a rule allows it.
Updated on 09 November, 2026