Back to Checks
gcp

Compute Engine instance does not use the default service account

compute_instance_default_service_account_in_use
Service: computeSeverity: medium
OfficialBuilt-inVerified
Categories:identity-access
Resource Type:compute.googleapis.com/Instance

Compute Engine VMs are evaluated for use of the default service account ([PROJECT_NUMBER]-compute@developer.gserviceaccount.com). The finding highlights instances configured with that account rather than a workload-specific service account. GKE node VMs are ignored.

Risk

Using the default service account often grants project-wide rights (e.g., roles/editor). If a VM is compromised, metadata tokens can be abused to read/modify resources, exfiltrate data, and pivot across services, impacting confidentiality and integrity, and potentially availability.

Run this check with Prowler

Run in Prowler Cloud
Run
prowler gcp --checks compute_instance_default_service_account_in_use

Recommendation

Avoid the default service account. Create per-workload service accounts and grant only required roles under least privilege and separation of duties. Remove broad roles like roles/editor. Prefer short-lived credentials and monitor service account usage to enforce defense in depth.

Remediation

Terraform

# Create a non-default service account
resource "google_service_account" "<example_resource_name>" {
  account_id = "<example_resource_id>"  # CRITICAL: custom SA to avoid default "-compute@developer.gserviceaccount.com"
}

# Attach the non-default service account to the VM
resource "google_compute_instance" "<example_resource_name>" {
  name         = "<example_resource_name>"
  machine_type = "e2-micro"
  zone         = "<ZONE>"

  boot_disk { initialize_params { image = "debian-cloud/debian-12" } }
  network_interface { network = "default" }

  service_account {
    email = google_service_account.<example_resource_name>.email  # CRITICAL: use non-default SA so the check passes
  }
}

Other

1In Google Cloud console, go to Compute Engine > VM instances
2Click the VM, then click Stop and wait until it is stopped
3Click Edit
4Under Service account, select a non-default service account (not ending with "-compute@developer.gserviceaccount.com")
5Click Save, then click Start to power the VM back on
6If no suitable service account exists: IAM & Admin > Service Accounts > Create service account, grant only required roles, then repeat steps 2-5

Check Code

from prowler.lib.check.models import Check, Check_Report_GCP
from prowler.providers.gcp.services.compute.compute_client import compute_client


class compute_instance_default_service_account_in_use(Check):
    def execute(self) -> Check_Report_GCP:
        findings = []
        for instance in compute_client.instances:
            report = Check_Report_GCP(metadata=self.metadata(), resource=instance)
            report.status = "PASS"
            report.status_extended = f"The default service account is not configured to be used with VM Instance {instance.name}."
            if (
                any(
                    [
                        ("-compute@developer.gserviceaccount.com" in sa["email"])
                        for sa in instance.service_accounts
                    ]
                )
                and instance.name[:4] != "gke-"
            ):
                report.status = "FAIL"
                report.status_extended = f"The default service account is configured to be used with VM Instance {instance.name}."
            findings.append(report)

        return findings