Review access allowed by GCP default firewall rules

Review actual sources, targets, protocols and ports rather than relying on a rule name.

Description

Check which sources, target VMs, protocols and ports the firewall rule allows. The name default alone does not describe its permissions.

Potential impact

A broad rule can let clients with a network path connect to services they do not need.

Remediation

Renaming a firewall rule replaces it. To stage the change, create the restricted rule as a separate Terraform resource. Check priorities and overlapping rules. After removing the old allowance, test new connections from both approved and excluded sources.

Examples

The first excerpt shows only the name and network. A Terraform ingress rule requires a source condition and an allow or deny block.

Before

hcl
resource "google_compute_firewall" "example" {
  name    = "default"
  network = google_compute_network.example.name
}

resource "google_compute_network" "example" {
  name = "test-network"
}

After

hcl
resource "google_compute_firewall" "example" {
  name    = "web-ingress-firewall"
  network = google_compute_network.example.name

  source_ranges = ["192.0.2.0/24"]
  target_tags   = ["web-server"]

  allow {
    protocol = "tcp"
    ports    = ["80", "8080"]
  }
}

resource "google_compute_network" "example" {
  name = "test-network"
}

Replace 192.0.2.0/24 with the approved client range and apply the web-server tag to the intended VMs. Keep TCP ports 80 and 8080 only if the service uses them.

References