Stop running Cloud Run and GKE workloads as the default compute service account: create one service account per service, grant resource-level roles, attach it at deploy time, and audit what is left.

Every Cloud Run service and GKE workload runs as a service account, and if you never chose one, it is the Compute Engine default service account. In many older projects that account holds the Editor role on the whole project, which means a template rendering bug in your marketing API can delete your production database.
The lasting fix is one service account per service, with roles bound on the specific resources that service uses, and it gets harder the longer you wait. This guide walks through the setup for Cloud Run, the bindings for common resources, and how to find what is still over-granted.
Google's service account best practices recommend single-purpose service accounts and warn against relying on the default ones. New organizations created after May 2024 enforce the iam.automaticIamGrantsForDefaultServiceAccounts constraint, which stops the Editor grant, but projects created earlier keep it until someone removes it.
Name accounts after the service so audit logs read naturally.
On GKE, the equivalent is a Kubernetes service account bound to the Google service account through Workload Identity Federation for GKE, so pods get the Google identity without a key file.
Whoever deploys needs roles/iam.serviceAccountUser on that specific account, the actAs permission. Grant it on the account, not the project, or any deployer can run code as any service account in the project.
Most Google Cloud resources accept IAM bindings directly. Use those instead of project-level grants:
Cloud SQL is the exception: cloudsql.client only allows connecting through the connector or Auth Proxy, and what the service can do inside Postgres depends on the database user. With Cloud SQL IAM authentication, the service account itself becomes a database user you can grant per-table privileges.
IAM Recommender compares granted permissions with the permissions each principal used over the last 90 days and suggests smaller roles. Start with the default compute account:
Once no workload uses the default account, remove its Editor binding, then consider disabling it. Do this in a staging project first, since forgotten workloads fail loudly when their roles disappear.
Best fit: every project with more than one service. Create the account when you create the service, and the bindings stay small.
Encore brings infrastructure from code, which gives it the information this guide asks you to track by hand: which service uses which bucket, topic, database and secret. The GCP infrastructure docs describe a dedicated service account per Cloud Run deployment, or per service on GKE, with permissions derived from the resources the code uses, and updated as the code changes.
package orders
import (
"context"
"encore.dev/pubsub"
"encore.dev/storage/objects"
)
type OrderCreated struct {
OrderID string `json:"order_id"`
}
// Publishing here is what gives this service publish access to the topic.
var OrderEvents = pubsub.NewTopic[*OrderCreated]("order-created", pubsub.TopicConfig{
DeliveryGuarantee: pubsub.AtLeastOnce,
})
// Using this bucket from the service is what grants storage access to it.
var Invoices = objects.NewBucket("invoices", objects.BucketConfig{})
var secrets struct {
StripeKey string // the service can read this secret and no others
}
func publishCreated(ctx context.Context, id string) error {
_, err := OrderEvents.Publish(ctx, &OrderCreated{OrderID: id})
return err
}
Static analysis of topics, buckets and secrets is what drives the bindings. When code needs a reference it can pass around, Encore asks you to declare the permission up front with a typed reference such as pubsub.TopicRef[pubsub.Publisher[*OrderCreated]], so the granted access stays visible in the code. Encore provisions a service account for the service, and you never pick roles or write bindings.
A coding agent that adds a bucket write to a service changes the permissions in the same diff, visibly, and cannot grant itself access to a resource the code does not use.
Best fit: teams on GCP who want least-privilege identities per service without maintaining the binding list by hand as services change.
If you deploy to GCP yourself, create one service account per service now, attach it at deploy time, bind roles on resources, grant actAs per account, and use IAM Recommender to trim the default account until you can remove its Editor role. If you deploy with Encore, the per-service accounts and bindings follow from the code, and your review is of the code that uses each resource.
Every service that shares a service account can do everything that account can do. With one account per service, a bug or compromised dependency in one service can only reach that service's own database, topics and secrets, and audit logs show which service performed each action.
Cloud Run and GKE use the Compute Engine default service account unless you choose another. In projects created before Google started enforcing the automatic-grants organization policy in 2024, that account often holds the project-wide Editor role, which gives every workload broad write access to the project.
Bind the role on the resource rather than the project, for example gcloud pubsub topics add-iam-policy-binding orders --member=serviceAccount:orders-api@PROJECT.iam.gserviceaccount.com --role=roles/pubsub.publisher. Resource-level bindings keep the account from reaching other topics or buckets in the same project.
Yes. Encore's GCP documentation describes a dedicated service account for each deployment, with permissions derived from the resources your code uses, such as the buckets, topics, databases and secrets it accesses. The bindings change as your code changes.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.