Google Cloud Tutorial · Identity and Access · Lesson 9 of 27
Workload Identity Federation
Letting workloads outside Google Cloud (CI systems, AWS, Azure, on-premises) use Google Cloud without keys.
The problem
A GitHub Actions workflow, a job on AWS or an on-premises app needs to call Google Cloud. The old answer was a service account key stored as a secret. Workload Identity Federation replaces it: the external workload proves who it is with a token from its own identity provider (GitHub's OIDC tokens, AWS credentials, Azure AD tokens, any OIDC or SAML provider), and Google exchanges it for short-lived Google credentials.
The pieces
- A workload identity pool, with a provider per external identity source.
- Attribute mappings copy claims from the external token (repository, branch, AWS role) into Google attributes.
- An attribute condition restricts which external identities are accepted at all.
- IAM grants to the federated principals, or permission to impersonate a service account.
gcloud iam workload-identity-pools providers create-oidc github \
--location=global --workload-identity-pool=ci \
--issuer-uri="https://token.actions.githubusercontent.com" \
--attribute-mapping="google.subject=assertion.sub,attribute.repository=assertion.repository,attribute.ref=assertion.ref" \
--attribute-condition="assertion.repository == 'acme/orders' && assertion.ref == 'refs/heads/main'"
The attribute condition matters: without one, tokens from any GitHub repository could use your provider.
def accepted(claims):
return claims["repository"] == "acme/orders" and claims["ref"] == "refs/heads/main"
tokens = [
{"repository": "acme/orders", "ref": "refs/heads/main"},
{"repository": "acme/orders", "ref": "refs/heads/feature-x"},
{"repository": "attacker/fork", "ref": "refs/heads/main"},
]
for t in tokens:
verdict = "exchanged for Google credentials" if accepted(t) else "rejected by attribute condition"
print(f"{t['repository']:16} {t['ref']:25} {verdict}")
Output
acme/orders refs/heads/main exchanged for Google credentials acme/orders refs/heads/feature-x rejected by attribute condition attacker/fork refs/heads/main rejected by attribute condition
Test yourself
What does Workload Identity Federation remove the need for?
IAM rolesService account key filesProjectsAudit logs
Show answer
Answer: Service account key files
External workloads exchange their own tokens for short-lived Google credentials.