Skip to content

Lesson 5 of 14 · 16m

Workload Identity Federation: Exchange a Token, Don't Store a Key

WIF trades an OIDC assertion for a federated token and a short-lived service account token — the config file holds no secret at all.

The actual exchange

Here is what google-github-actions/auth@v2 does when a GitHub Actions job runs with permissions: id-token: write:

  1. GitHub mints an OIDC JWT for the job, issued by https://token.actions.githubusercontent.com, carrying claims like repository, ref, workflow, actor, and sub.
  2. The action posts that JWT to sts.googleapis.com/v1/token — Google's Security Token Service — addressed to your workload identity pool provider, with grant type urn:ietf:params:oauth:grant-type:token-exchange.
  3. STS validates the issuer, the audience, and the attribute conditions configured on the provider. If the claims match, STS returns a federated access token.
  4. The action then calls iamcredentials.googleapis.com generateAccessToken against serviceAccountImpersonationUrl and mints a short-lived access token for your service account. The job is now the SA — for about an hour, not forever.

The external_account JSON config describing all this — issuer, audience, the impersonation URL, the attribute mapping like google.subject=assertion.sub — contains no secret. Commit it to a public repo without a second thought. The credential in the exchange is ambient: GitHub's OIDC token, minted per job, never at rest. There is nothing to leak because there is nothing stored.

The conditions are the boundary

The attribute mapping and conditions are where security lives, and where teams slip. A provider that checks only the issuer lets any repo in the allowed organization mint tokens for the SA. Pin harder:

attribute.repository == 'SudoSecurityOrg/Tower-of-Elements'
&& assertion.repository_owner == 'SudoSecurityOrg'
&& attribute.ref == 'refs/heads/main'

That reads "jobs from this repo, on this branch, owned by this org." On the SA side, grant roles/iam.serviceAccountTokenCreator to the pool's principal set — principalSet://iam.googleapis.com/projects/123/locations/global/workloadIdentityPools/gh-pool/attribute.repository/org/repo scopes impersonation to a single repository's jobs. One pool per external system, one provider per IdP; AWS federates via a signed GetCallerIdentity request instead of OIDC — and create-aws takes --attribute-condition the same as create-oidc, evaluated against AWS-mapped attributes (attribute.aws_role, attribute.aws_account, attribute.aws_region, attribute.aws_ec2_tag) rather than OIDC claims. AWS workloads get dedicated pools anyway: each provider carries its own attribute mapping, conditions, and trust boundary, and a shared pool only widens the blast radius while muddying the audit trail.

You can also skip impersonation and grant GCP roles directly to federated principals — simpler, but the audit trail then shows the federated identity rather than a service account, and role grants sprawl. Impersonation is the conventional choice because it keeps the authorization surface on one SA.

Two details the docs bury. The STS exchange takes subject_token_type=urn:ietf:params:oauth:token-type:jwt for OIDC sources, and the federated token it returns is itself short-lived — the impersonation hop converts it into an SA token good for about an hour. Nothing in the chain outlives the job that minted it. Azure's federated credentials cap at 20 per app registration — one per repo/ref/environment you need, which forces exactly the discipline you want.

When STS rejects, the debugging path is mechanical: decode the OIDC JWT the IdP minted, compare its claims against the provider's attribute mapping and conditions. The failure is always a claim mismatch — never a credential failure, because there is no credential. And log the impersonation hop: generateAccessToken calls in audit logs show which federated principal became the SA, and when.

Azure has the same mechanism and it's equally underused: federated credentials on an app registration replace client secrets for CI. azure/login@v2 takes client-id, tenant-id, subscription-id, and the OIDC flow mints the token — the credential's subject looks like repo:org/repo:ref:refs/heads/main or environment:prod. A stored client secret does the same job with a file that never expires; the federated credential does it with nothing stored at all.

Land it

The tradeoff against a JSON key is honest: WIF setup takes an hour, and debugging a claim mismatch — wrong attribute.repository name, missing ref condition — is unglamorous. The payoff is that no credential exists to leak: nothing in the repo, nothing in CI secrets, nothing to rotate. If your CI secrets still hold a GCP_SA_KEY, that is the thing to delete this sprint.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.