Why Cloud Run, Cloud Functions, Compute Engine and Cloud Build deploys fail with iam.serviceAccounts.actAs, which identity needs the Service Account User role on which service account, and how to grant it without handing out project-wide impersonation.

GCP refuses to attach a service account to a workload unless the identity doing the deploy may act as that service account, and the error reads Permission 'iam.serviceAccounts.actAs' denied on service account billing@acme-prod.iam.gserviceaccount.com (or it may not exist).
It shows up on Cloud Run, Cloud Functions, Compute Engine and Dataflow deploys, often right after someone switches to a dedicated runtime service account. The fix is one IAM binding, granted to the right identity on the right account.
A service account carries permissions, and attaching it to a Cloud Run service gives that service's code those permissions. Without the check, anyone allowed to deploy could attach a highly privileged account and run code as it. The service account permissions docs describe this as the Service Account User role, roles/iam.serviceAccountUser, which contains iam.serviceAccounts.actAs. Deploying a Cloud Run service therefore needs two things on the deployer: a Cloud Run role such as roles/run.developer, and Service Account User on the runtime account, as the Cloud Run IAM docs list.
The error names the service account being attached. The deploying identity is whoever ran the command: gcloud config get account for a local deploy, the build's service account in the Cloud Build history, or the service account the CI job impersonates. Then check the existing bindings on the runtime account:
An empty policy with only an etag means nobody has been granted anything on that account, so only principals with project-level Service Account User can attach it.
Grant Service Account User on the runtime account, not on the project. A project-level grant lets the deployer act as every service account in the project, including ones with admin roles:
The same binding in Terraform is a google_service_account_iam_member resource on the runtime account with the deployer as member. IAM changes can take a minute or two to apply, so a retry right after granting may still fail.
Cloud Build changed its default service account in 2024, and in newer projects builds run as the Compute Engine default service account or a service account set on the trigger, instead of the legacy PROJECT_NUMBER@cloudbuild.gserviceaccount.com. Pipelines copied from older projects grant the legacy account and then fail with actAs, so grant Service Account User to the account the trigger uses, which the build details page shows.
With Workload Identity Federation, the workflow impersonates a CI service account, and that account is the deployer. It needs roles/run.developer on the project or service and Service Account User on each runtime account it deploys with. A common slip is granting Service Account User to the CI account on itself, which allows impersonation but not attaching the runtime account.
Encore brings infrastructure from code: services and resources such as a Pub/Sub topic are declared in TypeScript, and deploys to your GCP project run with the access you grant the Encore platform once, as connecting your cloud describes. Encore provisions an IAM role for the service, a service account on GCP, so per-service actAs grants are not part of adding a service.

Run in your terminal to get started locally.
// signups/signups.ts
import { api } from "encore.dev/api";
import log from "encore.dev/log";
import { Subscription, Topic } from "encore.dev/pubsub";
export interface SignedUp {
userId: string;
email: string;
}
// GCP Pub/Sub topic on GCP, SNS on AWS, a local broker under `encore run`.
export const signedUp = new Topic<SignedUp>("user-signed-up", {
deliveryGuarantee: "at-least-once",
});
export const signup = api(
{ expose: true, method: "POST", path: "/signups" },
async (req: SignedUp): Promise<{ messageId: string }> => {
const messageId = await signedUp.publish(req);
return { messageId };
},
);
// Runs in the same service here; each subscription gets its own GCP subscription.
const _ = new Subscription(signedUp, "send-welcome-email", {
handler: async (evt) => {
// Delivery is at least once: record evt.userId before sending in production.
log.info("sending welcome email", { userId: evt.userId });
},
});
With an encore.service.ts file in signups/, encore run runs the topic on a local broker and delivers each signup to the subscription. On deploy, Encore creates the Pub/Sub topic and subscription in your project and runs the service on Cloud Run or GKE, as the GCP infrastructure docs describe.
A coding agent adding a second service, say a billing service that also subscribes to signups, declares it in code and runs both locally. Encore provisions an IAM role for the service, a service account on GCP, so the Pub/Sub access and the deploy identity's right to attach it are not left as bindings the agent would otherwise have to add in a separate IAM change.
Best fit: Teams deploying several services to their own GCP project who want each service to get its own service account without managing actAs bindings per service.
The identity running the deploy tried to attach a service account to a resource, such as a Cloud Run service or a VM, without permission to act as that service account. GCP requires the iam.serviceAccounts.actAs permission so that nobody can give a workload more access than they hold themselves.
roles/iam.serviceAccountUser (Service Account User). Grant it to the deploying identity, a user, a CI service account or the Cloud Build service account, on the runtime service account itself rather than on the whole project.
GCP returns the same message whether the service account is missing or you lack permission on it, so it does not reveal which accounts exist. Check the email for typos and the project ID inside it, then check the binding.
In newer projects Cloud Build runs builds as the Compute Engine default service account or a user-specified one instead of the legacy Cloud Build service account, and that identity needs Service Account User on the Cloud Run runtime service account. With Encore, deploys run with the access you grant the Encore platform once when connecting your GCP project, and Encore provisions an IAM role for the service, a service account on GCP.
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.