Google Compute Firewall Rules have unnecessary port ranges opened for inbound traffic Affecting Compute Engine service in Google


Severity

0.0
medium
0
10
    Severity Framework
    Snyk CCSS
    Rule category
    Network / Ports

Is your enviroment affected by this misconfiguration?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
    Frameworks
  • Snyk ID SNYK-CC-00718
  • credit Snyk Research Team

Description

Opening unnecessary port ranges in Compute Engine/GCE Firewall Rules for inbound traffic increases the attack surface and potential risk of unauthorized access. It is important to restrict the range of ports to only those that are required for legitimate traffic to minimize the exposure to potential threats.

How to fix?

Set allow.ports to a specific port number instead of a range of ports where the direction is INGRESS.

Example Configuration


resource "google_compute_network" "default" {
  name = "example718"
}
resource "google_compute_firewall" "allowed1" {
  name      = "example718a1"
  network   = google_compute_network.default.name
  direction = "INGRESS"
  allow {
    protocol = "tcp"
    ports    = ["80", "443"]
  }

  source_ranges = ["192.168.0.0/24"]
}