terraform.gcp.security.gcp-compute-public-ip.gcp-compute-public-ip

profile photo of semgrepsemgrep
Author
unknown
Download Count*

Ensure that Compute instances do not have public IP addresses

Run Locally

Run in CI

Defintion

rules:
  - id: gcp-compute-public-ip
    patterns:
      - pattern: resource
      - pattern-inside: |
          resource "google_compute_instance" "..." {
          ...
          network_interface {
            ...
            network = "default"
            ...
          }
          ...
          }
    message: "Ensure that Compute instances do not have public IP addresses\t"
    metadata:
      owasp:
        - A05:2017 - Broken Access Control
        - A01:2021 - Broken Access Control
      cwe:
        - "CWE-284: Improper Access Control"
      category: security
      technology:
        - terraform
        - gcp
      references:
        - https://docs.bridgecrew.io/docs/google-cloud-policy-index
      subcategory:
        - audit
      likelihood: LOW
      impact: LOW
      confidence: LOW
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]
      vulnerability_class:
        - Improper Authorization
    languages:
      - hcl
    severity: WARNING

Examples

gcp-compute-public-ip.tf

# fail
# ruleid: gcp-compute-public-ip
resource "google_compute_instance" "fail" {
  name         = "test"
  machine_type = "n1-standard-1"
  zone         = "us-central1-a"
  boot_disk {
    auto_delete = true
  }

  network_interface {
    network = "default"
    access_config {
    }
  }
}

# ok: gcp-compute-public-ip
resource "google_compute_instance" "pass" {
  name         = "test"
  machine_type = "n1-standard-1"
  zone         = "us-central1-a"
  boot_disk {
    auto_delete = true
  }
  network_interface {

  }
}