Compute instance uses the default service account Affecting Compute Engine service in Google


0.0
high
    Severity Framework Snyk CCSS
    Rule category IAM / Access Control

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
    CIS-Google HIPAA ISO-27001 NIST-800-53 PCI-DSS SOC-2
  • Snyk ID SNYK-CC-00388
  • credit Snyk Research Team

Description

To minimize the risk of unauthorized access and compromised instances in Google, avoid using the default Compute Engine service account and create a new service account with minimal necessary permissions when creating Compute Engine instances. The default service account comes with "Editor" role and three scope options, including full access to all Cloud APIs.

How to fix?

Compute instances should not use the default service account with full access to all Cloud APIs.

Example Configuration

resource "google_service_account" "example388" {
  account_id   = "example388-service-account"
  display_name = "example388 SA"
}

resource "google_compute_instance" "allowed" {
  name         = "no-metadata-keys-set"
  machine_type = "e2-micro"
  zone         = "us-east1-b"

  service_account {
    email  = google_service_account.example388.email
    scopes = ["logging-write"]
  }

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-11"
    }
  }

  network_interface {
    network = "default"
  }
}