Compute instance uses the default service account with full access to all Cloud APIs Affecting Compute Engine service in Google


Severity

0.0
medium
0
10
Severity Framework
Snyk CCSS
Rule category
IAM/ Least Privilege

Is your environment 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 IDSNYK-CC-00205
  • creditSnyk Research Team

Description

The default Compute Engine service account "Editor" role is assigned with three possible scopes. Avoid allowing the scope for full access to all Cloud APIs, as this may enable users accessing the Compute Engine instance to perform cloud operations outside the scope of responsibility, or increase the potential impact of a compromised instance. Note that GKE-created instances should be exempted from this.

How to fix?

Set the service_account.scopes attribute to a scope that is not cloud-platform or https://www.googleapis.com/auth/cloud-platform.

Example Configuration

resource "google_service_account" "test" {
  account_id   = "test-service-account"
  display_name = "Test Service Account"
}

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

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

  boot_disk {
    initialize_params {
      image = "debian-10-buster-v20221102"
    }
  }

  network_interface {
    network = "default"
  }
}

References