Skip to content

Lesson 7 of 14 · 12m

Default Service Accounts: Editor by Another Name

GCP's default compute and App Engine identities are granted project Editor — every workload attached to them carries the project.

What enable creates

The first time you enable the Compute Engine API on a project, GCP creates PROJECT_NUMBER-compute@developer.gserviceaccount.com and — unless something stops it — grants it roles/editor on the project. Enable App Engine and PROJECT_ID@appspot.gserviceaccount.com appears, carrying the same grant, inherited by Cloud Functions and older App Engine runtimes. The grant predates today's threat model — Editor-on-project was the fast path to "it just works," and the org policy that disables it is the provider admitting it. GKE node pools default the same way unless overridden — check them separately. These are the identities VMs, Cloud Run services, and functions run as unless you explicitly choose otherwise, because "default" is exactly what the name says — every console deploy dialog preselects them.

Two distinctions worth keeping straight. Default service accounts are user-visible identities you can re-role. Google-managed service agents — service-NUMBER@compute-system.iam.gserviceaccount.com and siblings — are internal plumbing Google uses to operate the service; leave them alone. The problem is the former.

Now run the causal chain. A workload runs as the default compute SA. The metadata server mints access tokens for it:

curl -H 'Metadata-Flavor: Google'   http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token

roles/editor covers most of the project: storage, compute, secret reads, IAM reads, instance creation, Pub/Sub, SQL. One RCE in one workload equals a project-scoped Editor token in the attacker's hand — minted by the infrastructure itself, refreshing while the box lives.

"My code doesn't call GCP"

That is the wrong mental model — the assumption that the attached identity only matters when application code touches Google APIs. The metadata server doesn't care which process curls it. A webshell, a compromised npm dependency, a curl line in a CI step — all of it mints. And it spreads: any principal that can actAs or attach the default SA to other workloads inherits the same grant. A roles/run.developer holder attaching the default SA to a public Cloud Run service has minted themselves Editor.

Azure's counterpart is subtler because Azure creates no default managed identity. The equivalent mistake is self-built: a single user-assigned identity attached to everything — twenty workloads sharing one principal, each workload's compromise carrying the union scope. Same blast radius, constructed by hand.

The remediation is unglamorous and short:

gcloud projects remove-iam-policy-binding my-project   --member='serviceAccount:PROJECT_NUMBER-compute@developer.gserviceaccount.com'   --role='roles/editor'

Same for PROJECT_ID@appspot.gserviceaccount.com. Then inventory what's attached: gcloud compute instances list --format='value(name,serviceAccounts[].email)' shows which VMs still ride the default; gcloud run services describe SERVICE --format='value(spec.template.spec.serviceAccountName)' does it for Cloud Run. Every workload moved to a dedicated SA shrinks the number of boxes that can mint project-Editor tokens.

Fix the grant, not just the SA

Three controls:

  1. constraints/iam.automaticIamGrantsForDefaultServiceAccounts at the org node stops new default SAs from receiving Editor automatically. Existing grants must still be removed by hand — the constraint prevents future mistakes, it doesn't retro-fix. Projects created under an org with the constraint set skip the auto-grant entirely; projects created before it keep whatever bindings they already had — the constraint is a gate, not a cleaner.
  2. Per-workload service accounts with predefined roles. --service-account=dedicated@... on gcloud compute instances create, Cloud Run, and Cloud Functions deployments. A service that writes objects gets roles/storage.objectUser on its bucket — not Editor on the project.
  3. Revoke Editor from the defaults that exist. Nothing about the default SA requires it; the grant is a convenience holdover from a less hostile era.

Security Command Center flags default-SA usage on compute resources for exactly this reason — in most GCP estates it's the cheapest high-severity finding you can close. The audit tell: grep your workload inventory for identities ending in -compute@developer.gserviceaccount.com or @appspot.gserviceaccount.com — those two suffixes are the whole finding class.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.