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:
- GitHub mints an OIDC JWT for the job, issued by
https://token.actions.githubusercontent.com, carrying claims likerepository,ref,workflow,actor, andsub. - 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 typeurn:ietf:params:oauth:grant-type:token-exchange. - STS validates the issuer, the audience, and the attribute conditions configured on the provider. If the claims match, STS returns a federated access token.
- The action then calls
iamcredentials.googleapis.comgenerateAccessTokenagainstserviceAccountImpersonationUrland 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?
Keep reading
Related articles from the SudoSecurity blog.
AWS Emulator Puts AWS on Your Laptop. Keep Your IAM Tests Off It.
AWS released AWS Emulator on November 11, a free local server that answers AWS API calls on 127.0.0.1 with per-run keys and fresh certificates.
Big Tech Plans to Work with the Public Sector for Cybersecurity
Both Microsoft, Inc. and Alphabet, Inc. will put a combined $30 billion dollars into cybersecurity over the next five years and work with the public sector on several initiatives to help improve cybersecurity.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.
What is SSRF? Server-Side Request Forgery and the Attack That Breached Capital One
SSRF tricks your server into making requests to internal systems — cloud metadata services, internal APIs, AWS credentials endpoints. It turned a WAF misconfiguration into 100 million stolen Capital One records