Join our Newsletter — 33% off our NHI Course
Home› Guides› How to Federate GitHub Actions to Google Cloud:…
Guide Cloud Security

How to Federate GitHub Actions to Google Cloud: Workload Identity Pools Without Keys

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 27 November 2026 13 min read
On this page

A service account key JSON stored as a GitHub secret is a long-lived Google Cloud credential that, by default, never expires, and any workflow step that can read it can use it from anywhere. Workload Identity Federation replaces that key: GitHub issues a short-lived OIDC token for each job, Google's Security Token Service checks it against a workload identity pool provider you control, and the job receives a short-lived Google credential. This guide walks through the Google Cloud side in the order you build it: the pool, the provider, attribute mapping, the attribute condition, the IAM binding (direct access or service account impersonation) and the workflow, then how to log, test and retire the old keys. It is for platform, DevOps and cloud security engineers who already know Google Cloud IAM.

Key takeaways

  • The attribute condition is not optional. GitHub uses one issuer, https://token.actions.githubusercontent.com, for every organisation, so a provider without a condition admits tokens from any repository on GitHub.
  • Use numeric IDs, not names. Condition on repository_owner_id and repository_id; names can be re-registered after an organisation or repository is deleted.
  • Map before you match. Google can only evaluate claims you have mapped to attributes, and mapping errors are the most common cause of failed exchanges.
  • Prefer direct resource access. Google recommends granting roles straight to the federated principal; use service account impersonation only where an API needs it or you need OAuth access tokens or ID tokens.
  • Scope the binding, not just the pool. Grant roles to a principalSet for one repository (or a single subject), never to the whole pool.

How the exchange works

Each job that declares id-token: write can ask GitHub for an OIDC token. The google-github-actions/auth action requests one with the audience set to the full provider resource name, sends it to the Security Token Service (STS) ExchangeToken method, and receives a federated access token. Google checks the token's issuer and signature, applies the provider's attribute mapping, evaluates the attribute condition, and only then issues credentials. With impersonation, a second call to the IAM Service Account Credentials API (GenerateAccessToken) swaps the federated token for a service account access token.

ComponentWhere it livesWhat you setSecurity role
Workload identity poolGoogle Cloud project (dedicated project recommended)Pool ID, display name, location globalContainer for external identities; one pool per identity provider
OIDC providerInside the poolIssuer URI, attribute mapping, attribute condition, allowed audiencesDecides which GitHub tokens are admitted and how they are named
IAM bindingOn the target resource or service accountprincipal:// or principalSet:// member and a roleDecides what an admitted identity can do
WorkflowGitHub repositorypermissions: id-token: write, workload_identity_provider, optional service_accountRequests the token and exports Application Default Credentials
Audit logsProjects holding pools and service accountsData Access logs for IAM and STSRecords every exchange and impersonation

Before you start

  • Project: Google's best practice is a single, dedicated project for workload identity pools and providers, separate from the projects holding the resources. This keeps the power to edit providers away from application teams.
  • Role: the person creating the pool needs Workload Identity Pool Admin (roles/iam.workloadIdentityPoolAdmin). Owner also works but should not be used in production.
  • Organisation policy: Google recommends setting constraints/iam.workloadIdentityPoolProviders to deny all at the organisation root and allowing only trusted issuers, such as https://token.actions.githubusercontent.com, in the federation project. This stops anyone creating a rogue provider elsewhere. See the Google Cloud Organization Policy Guide.
  • Identifiers: look up the numeric organisation and repository IDs from the GitHub REST API (the id field of the organisation and repository objects) and record them. You will also need the Google Cloud project number, not the project ID: federation resource names only accept the number.
  • Claim review: decide which GitHub claims express "this workflow may deploy". The sub claim encodes the repository plus the branch, tag, environment or pull_request context; ref, environment, workflow_ref, job_workflow_ref and runner_environment (github-hosted or self-hosted) are available separately.

Step-by-step setup

  1. Create the pool. gcloud iam workload-identity-pools create "github" --project="${PROJECT_ID}" --location="global" --display-name="GitHub Actions Pool". Use one pool for GitHub only: Google advises one provider per pool and a separate pool per identity provider, to avoid subject collisions.
  2. Create the OIDC provider with mapping and condition in one step. Use gcloud iam workload-identity-pools providers create-oidc with --issuer-uri="https://token.actions.githubusercontent.com", an --attribute-mapping and an --attribute-condition. Never create the provider first and add the condition later: in the gap, any GitHub repository can enter the pool.
  3. Map the claims you will use. At minimum google.subject=assertion.sub. Add attribute.repository_id=assertion.repository_id, attribute.repository_owner_id=assertion.repository_owner_id and any claim you plan to use in a condition or binding, such as attribute.ref=assertion.ref or attribute.environment=assertion.environment. Mapped attribute values are limited to 127 bytes, which long repository or branch names can exceed.
  4. Write the condition on immutable IDs. A minimal, robust condition is assertion.repository_owner_id == '<ORG_ID>'. Tighten it where you can, for example adding && assertion.repository_id == '<REPO_ID>' or && assertion.ref == 'refs/heads/main'. Values are case-sensitive in Google Cloud even where GitHub is not, so copy them from a real token.
  5. Keep the default audience. Leave allowed audiences at the default, which is the provider's full resource name. The auth action sends exactly that value. Google lists requiring the provider URL as audience as a protection against confused deputy attacks.
  6. Grant access. For direct access, bind a role on the resource to a principalSet for one repository, for example principalSet://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/github/attribute.repository_id/REPO_ID (this requires the repository_id mapping). For impersonation, grant roles/iam.workloadIdentityUser on one dedicated service account to that same principalSet, and give the service account the resource roles.
  7. Configure the workflow. In the job, set permissions: contents: read and id-token: write, run actions/checkout before the auth step, then call google-github-actions/auth with workload_identity_provider set to projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/github/providers/PROVIDER_ID. Add service_account only for impersonation. Pin the action to a full commit SHA rather than a tag; see How to Pin GitHub Actions to Commit SHAs.
  8. Test from a branch that should fail. Run once from an allowed branch or environment and once from one that is not allowed. The failed run proves the condition is doing work. Allow up to five minutes after any pool, provider or IAM change: these resources are eventually consistent.
  9. Retire the key. Once runs succeed, delete the service account key in Google Cloud (deleting only the GitHub secret leaves the key valid), then remove the credentials_json secret. See How to inventory Google Cloud service account keys and replace them with federation.

Rollback: if a deployment breaks, fix the mapping, condition or binding rather than restoring a key. Keep the old key disabled, not deleted, for a short agreed window only if a rollback path is genuinely required, and record the exception with a date.

Direct access or service account impersonation

QuestionDirect resource accessImpersonation through a service account
Google's positionRecommended defaultUse where an API has limitations or a service account is required
What the job receivesFederated token from STSService account OAuth access token (or ID token) via GenerateAccessToken
Credential lifetimeShort; the auth action's documentation notes these tokens last minutes, not hoursaccess_token_lifetime default 3600s, maximum one hour unless constraints/iam.allowServiceAccountCredentialLifetimeExtension allows up to 12 hours
Where roles are grantedOn each resource, to the principalSetOn the service account; the principalSet only needs roles/iam.workloadIdentityUser
Audit trailResource logs show the federated principalResource logs show the service account; the federated subject appears in the GenerateAccessToken log entry
Typical fitArtifact Registry pushes, Secret Manager reads, Cloud Storage uploads where supportedTools that need an access token or ID token, APIs that do not accept federated principals, Domain-Wide Delegation

Decision guidance: start with direct access for each target resource. Fall back to impersonation per API when a call fails because the service does not accept federated principals, or when a downstream step needs token_format: access_token or id_token. In large estates, impersonation with one service account per application and environment is often easier to review because role grants stay in one place; small teams with a few resources usually find direct grants simpler. Do not grant roles/iam.serviceAccountTokenCreator to the federated identity unless Domain-Wide Delegation is truly needed.

Writing conditions and bindings that hold

Admission and authorisation are two layers. The attribute condition decides who may enter the pool at all; the IAM binding decides what each admitted identity may do. Use both.

GoalCondition (pool admission)Binding (resource access)
Only your organisationassertion.repository_owner_id == 'ORG_ID'Per repository principalSet
One repository deploys to productionOrganisation ID plus assertion.repository_id == 'REPO_ID'attribute.repository_id/REPO_ID on production resources only
Production only from protected environmentAdd assertion.environment == 'production'Separate mapped attribute for environment, bound only on production
Only GitHub-hosted runnersAdd assertion.runner_environment == 'github-hosted'Unchanged
Only a central reusable workflow may deployCondition on assertion.job_workflow_ref matching the approved workflow path and refBind production roles to that attribute value
  • Environments beat branches for production: GitHub environments can require reviewers and limit which branches deploy, so a condition on environment inherits those protections. Note that when a job references an environment, the sub claim uses the environment form (repo:ORG/REPO:environment:NAME) rather than the branch form.
  • Immutable subject format: GitHub now documents an immutable sub format (repo:OWNER@OWNER-ID/REPO@REPO-ID:...) for repositories created after 15 July 2026 or that opt in. If any condition or principal:// member matches on sub, check which format your repositories emit before writing it.
  • Pull requests: do not bind deployment roles to the pull_request subject. Code from a pull request should not obtain production credentials. See the GitHub Actions Script Injection Guide.
  • Restrict provider edits: anyone with iam.googleapis.com/workloadIdentityPoolProviders.update can relax a condition. Limit Workload Identity Pool Admin to the platform team. See the How to Scope CI OIDC Trust to Branch and Environment guide for patterns that apply across CI systems.

Logging, detection and metrics

Token exchanges are only visible if you turn them on. Enable Data Access audit logs (Admin Read) for the IAM API and the Security Token Service API in the federation project and in every project holding service accounts used for impersonation.

  • Exchange events: google.identity.sts.v1.SecurityTokenService.ExchangeToken entries in the data_access log carry the GitHub sub in protoPayload.authenticationInfo.principalSubject, the mapped principal:// identifier in protoPayload.metadata.mapped_principal and the provider in protoPayload.resourceName. Client errors such as rejected credentials are not logged there, so a failing condition shows up in the workflow, not in this log.
  • Impersonation events: GenerateAccessToken entries name the target service account in resource.labels.email_id and the federated subject in principalSubject.
  • Alerts: provider create, update or delete outside change control; an exchange whose subject belongs to a repository or environment not in your approved list; a new service account key created for an identity that has moved to federation. See the GCP Audit Log Principal Fields guide for reading these entries.

Metrics

  • Number of GitHub repositories still using credentials_json (target zero).
  • Active user-managed keys on CI service accounts (target zero).
  • Providers without an attribute condition, and providers outside the federation project (target zero).
  • Bindings granted to the whole pool (workloadIdentityPools/POOL_ID/*) (target zero).
  • Share of deployments using direct access rather than impersonation.

Common failure patterns

  • No attribute condition: because GitHub's issuer is shared, any repository on GitHub can be admitted, leaving only the IAM binding between an attacker's workflow and your project.
  • Name-based conditions: conditions on repository_owner or repository names can be satisfied by someone who registers the same name after you rename or delete it.
  • Pool-wide grants: granting roles/iam.workloadIdentityUser to .../workloadIdentityPools/POOL_ID/* lets every repository the condition admits impersonate the service account.
  • Keys left behind: teams add federation but keep the key JSON secret "just in case". Stored keys are what leak when a workflow is compromised: in the tj-actions/changed-files compromise, a poisoned action printed runner secrets, including cloud access keys, into workflow logs. Federated credentials can still be exposed in such an attack, but they expire within the hour.
  • Credentials file in artefacts: the auth action writes a gha-creds-*.json file into the workspace. Add it to .gitignore and .dockerignore so it is never committed or baked into an image.
  • Wrong identifiers: using the pool name instead of the provider name, or the project ID instead of the project number, in workload_identity_provider. Errors mentioning "Failed to generate Google Cloud federated token" point at admission (condition or mapping); "Failed to generate OAuth 2.0 Access Token" points at impersonation. See the GitHub Actions OIDC Errors Troubleshooting Guide.

Framework mapping

FrameworkReferenceHow federation supports it
NIST SP 800-53 Rev 5IA-5 Authenticator ManagementRemoves long-lived keys in favour of short-lived, automatically issued credentials
NIST SP 800-53 Rev 5IA-9 Service Identification and AuthenticationEach job authenticates as a named workload identity
NIST SP 800-53 Rev 5AC-6 Least PrivilegePer repository and environment bindings
NIST SP 800-53 Rev 5AU-2 Event LoggingSTS and IAM Data Access logs
NIST CSF 2.0PR.AA-01, PR.AA-05Workload credentials managed and access scoped
NIST SP 800-204DSoftware supply chain security in CI/CD pipelinesShort-lived pipeline credentials and protected build identities
MITRE ATT&CKT1552.001 Credentials In Files, T1078.004 Cloud AccountsRemoves stored key files that attackers harvest and reuse

Where this fits

This page is the Google Cloud build. For cross-cloud hardening rules for GitHub's OIDC tokens (claim choice, reusable workflows, review cadence) see the GitHub Actions OIDC Federation Hardening Guide, and for Google Cloud service account design see the Google Cloud IAM and Service Accounts Guide.

Practitioner checklist

  • Create pools and providers only in a dedicated federation project.
  • Set constraints/iam.workloadIdentityPoolProviders to deny by default and allow only GitHub's issuer where needed.
  • Create every provider with an attribute condition on repository_owner_id, plus repository or environment where possible.
  • Map every claim used in a condition or binding; keep google.subject=assertion.sub.
  • Grant roles to a per-repository principalSet, never to the whole pool.
  • Prefer direct resource access; use one dedicated service account per application where impersonation is needed.
  • Set id-token: write only on jobs that need Google access and pin the auth action to a commit SHA.
  • Test a denied branch or environment before declaring the setup done.
  • Delete the old service account keys in Google Cloud, then the GitHub secrets.
  • Enable IAM and STS Data Access logs and alert on provider changes and new keys.

Standards and references

Related NHI Mgmt Group resources: GitHub Actions OIDC Federation Hardening Guide · How to inventory Google Cloud service account keys and replace them with federation · Google Cloud IAM and Service Accounts Guide · Cross-cloud workload identity federation

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.