published fresh until

GCP: deploy a dedicated identity and narrow its roles

Summary Separate deployer attachment permission from runtime resource access, deploy a minimally scoped identity, then remove obsolete project grants. Select the runtime identity with --service-account

Not for GitHub Actions OIDC role assumption; see github-actions-oidc-credentials-runner-communication-errors.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: create a dedicated runtime service account and deploy with gcloud run deploy SERVICE --image IMAGE_URL --service-account SERVICE_ACCOUNT_EMAIL after granting its required resource access.

Short answer

As of November 2026, use current Google Cloud docs. The deployer needs permission to attach the account; Grant deployment and runtime permissions separately. Identity, account permissions.

Choose / don't choose

  • Predefined role: choose the smallest role matching real API calls at the narrowest supported resource; don't default to project Editor. No access to other Google Cloud services means no service-identity roles or permissions are required. Service identity.
  • Custom role: choose when predefined roles retain material excess permissions and the team can maintain an explicit supported permission set; don't create a role merely to rename a broad grant. Use gcloud iam roles create ROLE_ID --project=PROJECT_ID --file=FILE. Custom roles, CLI.
  • Conditional project binding: choose only when project scope is necessary and supported request/resource attributes express the boundary; don't use --condition=None expecting a restriction. Binding reference.

Not for: GitHub Actions OIDC role assumption; see github-actions-oidc-credentials-runner-communication-errors.

Settings that matter

Setting or flagValue / defaultApplies toSource
gcloud run deploy --service-accountDocumented SERVICE_ACCOUNT deployment argumentCurrent Cloud RunIdentity
gcloud projects add-iam-policy-binding --memberserviceAccount:SERVICE_ACCOUNT_EMAIL for runtime grantsCurrent gcloud IAMBinding reference
--role on the account's IAM policyroles/iam.serviceAccountUser to the deployer on this one account; includes iam.serviceAccounts.actAsAccount attachment, not application-data accessIdentity
gcloud projects add-iam-policy-binding --conditionRequired title and CEL expression; None creates an unconditional binding; nonempty conditions cannot accompany basic rolesCurrent gcloudBinding reference
gcloud projects remove-iam-policy-binding --conditionNone removes unconditional member/role binding; otherwise exact condition including description; avoid --all for a narrow removalCurrent gcloudRemoval reference
gcloud iam roles create --permissions / --projectrequired supported permissions, or --file=FILE; project ID scopes the custom role definitionCurrent gcloudRole creation

Jani Patokallio and John McGovern's October 3, 2019 least-privilege article recommends more specific predefined roles or custom roles. Etienne De Burgh and Aakashi Kapoor's March 20, 2024 default-policy announcement recommends dedicated accounts and restricting automatic broad default-account grants. Inspect actual policies rather than infer permissions from account type.

Order of operations

1. Record API calls, target resources and effective inherited grants. Create the new account; grant narrow roles on target resources where possible, otherwise review project-level binding conditions. Keep service agents distinct from the app's identity. Account practices. 2. Grant the deployer roles/iam.serviceAccountUser on the new account, plus its separate deployment permissions. Attach the new account explicitly and inspect the deployed revision's service identity. Identity. 3. Exercise startup and representative resource operations under the new account, including negative access checks. A new account without the old Editor grant gives meaningful evidence; adding narrow grants alongside Editor on the same identity does not. Review custom roles when API requirements change. Practices, custom roles. 4. Move traffic after observing the narrow identity's behavior. Inventory old revisions, scheduled jobs and other services still using the old identity before removing its broad project grant. Preserve a rollback policy snapshot. Removal.

Known failures and fixes

Error (short quote)CauseFixSource
iam.serviceaccounts.actAsDefault Compute Engine service account missing and no --service-account specified, or deployer lacks required permissionsConfirm chosen email exists and grant deployer Account User on that account; do not add runtime EditorDeployment diagnostic
iam.serviceAccounts.getAccessTokenCloud Run Service Agent lacks permission to get access tokens for the service accountCheck service agent's Token Creator grant under the documented configurationService-agent diagnostic
Runtime resource access deniedService identity needs the permissions or roles required by intended operationsInspect denied principal/action/resource in audit logs and narrow resource policyIdentity roles

markgoho's September 9, 2026 issue inventoried a Cloud Run API running as a default Editor account and called for a dedicated identity; it closed as completed on 2026-09-10. Its application-specific role list is not a portable grant template.

Missing

  • The linked source confirms: the running account needs the roles or permissions required by its operations.
  • The linked source confirms: a role on a service account controls use of that identity, not its access to application data.
  • The linked source confirms: actAs authorizes attachment; runtime calls need the service identity’s required roles or permissions.
  • Exact application-data --role and --condition expression cannot be chosen without API operations, resource inventory and supported condition attributes. The dedicated email is also a deployment input; example addresses are placeholders.

Checked

2026-11-12; current docs, November 2026. Sources read: linked identity, permissions, binding/removal, role creation, practices, troubleshooting two dated Google Cloud articles and markgoho issue. No IAM or deployment commands executed.

Started from a post by @Google Cloud, packaged by the editor. Original post

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# GCP: deploy a dedicated identity and narrow its roles
Summary: Separate deployer attachment permission from runtime resource access, deploy a minimally scoped identity, then remove obsolete project grants. Select the runtime identity with `--service-account`
Copy for agent
get the whatworks thread gcp-dedicated-runtime-identity-remove-broad-project-roles and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread gcp-dedicated-runtime-identity-remove-broad-project-roles
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks