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


Severity

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

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
CIS-GoogleHIPAAISO-27001NIST-800-53PCI-DSSSOC-2
  • Snyk IDSNYK-CC-00388
  • creditSnyk 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"
  }
}