Workload identity federation: replace long-lived cloud keys in external CI/CD
Learn how external CI/CD workloads exchange issuer-attested OIDC, SAML, or certificate credentials for short-lived cloud access, and how to restrict the issuer, audience, subject, claims, and CI execution context.
Workload identity federation: replace long-lived cloud keys in external CI/CD
Workload Identity Federation (WIF) lets a workload running in CI/CD, another cloud, or an on-premises environment present proof from its own runtime—such as an OIDC or SAML token or a certificate—to a trusted cloud and exchange it for short-lived credentials. This avoids storing a long-lived cloud secret in a repository or build variable. WIF changes the authentication path, so limit which workloads you trust and validate the token's audience and identity claims.
How an external runtime issues and exchanges a token
A trusted CI/CD provider or host issues a short-lived ID token or assertion for a particular job.
The cloud's federation provider configuration validates the issuer, signing keys, audience, and required claims.
Attribute mappings and conditions determine whether the external subject is an allowed workload.
The cloud grants that external subject access to resources directly or lets it temporarily impersonate a restricted service account or role.
The workload uses short-lived cloud credentials to call only the required APIs. The credentials expire, but IAM role bindings or trust policies can remain until separately removed; clean up external-principal permissions and delegation when the job ends.
Exact steps and terminology differ by implementation. Google Cloud Workload Identity Federation exchanges external credentials through its Security Token Service; you can grant roles directly to a federated principal or use service account impersonation. AWS registers an external OIDC identity provider and uses a role trust policy to check token claims before issuing temporary STS credentials. These are examples of the same broad purpose, but their configuration and token contracts are not interchangeable.
Design a GitHub Actions deployment identity
The following vendor-neutral design sequence is based on OIDC integration guidance from Google Cloud and AWS. Follow the target cloud's current documentation for its console fields and commands.
**Set the workflow boundary.** Decide which repositories, branches or tags, deployment environments, and reusable workflows can deploy to production resources. Do not give every pull request job the production deployment identity.
**Check the external issuer's token contract.** Confirm issuer (`iss`), audience (`aud`), subject (`sub`), claims about organization, repository, environment, and run context, and token expiry. Use the external issuer's documentation to verify which claims are stable and safe to trust.
**Configure the cloud trust provider and claim conditions.** Register only the intended issuer and audience, then write policy conditions that accept tokens only from approved organizations, repositories, branches, and deployment environments. For a public, multi-tenant issuer, constrain the organization identity claim so that another organization's token cannot be accepted.
**Limit access to one purpose.** Allow the deployment job to reach only the target environment and APIs it needs. In Google Cloud, bind the external principal directly to resources where possible. If an API requires a service account, use an account for that application and allow impersonation only to the specific principal.
**Constrain CI permissions and cloud trust together.** Grant only the repository permissions required for the workflow to request an ID token, and use protected deployment environments or approval rules to control who can run the job. Anyone able to run arbitrary code in CI can also obtain the federated cloud permissions.
**Test both allowed and denied cases safely.** Confirm that a token from the specified deployment context can perform only the intended deployment. Tokens from another repository, an arbitrary branch, a pull request, the wrong audience, or an expired token should be rejected. Also confirm that API calls to resources outside the granted scope are denied.
**Prepare auditing and revocation.** Map an external subject to a unique, stable claim so it can be found again in cloud logs. Strictly control changes to trust policies and claim mappings, and document how to remove unnecessary workflow permissions, principal bindings, and providers.
Trust configuration mistakes to avoid
**Trusting too broadly:** If you check only the issuer and do not restrict audience, organization, repository, or environment, other organizations or projects using the same issuer might exchange credentials.
**Granting access to a reusable attribute:** Mapping a subject using only email or a mutable name can make identity ambiguous if an account is renamed, deleted, and later reused. Consider a unique, stable subject identifier.
**Treating claim-mapping changes as minor:** Changing a mapping can change the meaning and scope of existing IAM bindings. Approve, review, and record mappings like policy code.
**Granting permissions to an entire pool:** Broad roles for all members of a federation pool can let more workloads access resources than expected when a provider or claim is later added. Grant permissions to a specific principal or a narrowly defined attribute set.
**Mistaking federation for an approval control:** WIF authenticates “who is making the request”; it does not create a deployment approval process. Configure cloud trust conditions together with branch and environment approval rules in CI.
Distinguish workforce federation from workload federation
Some clouds distinguish Workforce Identity Federation, which links an external identity provider to human user accounts, from Workload Identity Federation, which is used by workloads and automation. If GitHub Actions or a server process calls a cloud API, that is usually a workload flow. If an employee signs in through an external IdP to use a console or business application, that is user or workforce federation. Even when product names are similar, check the principal type, issued claims, and delegation model.
References
[Google Cloud Workload Identity Federation](https://docs.cloud.google.com/iam/docs/workload-identity-federation) — external principals, token exchange, direct resource access, and service account impersonation.
[Google Cloud WIF security best practices](https://docs.cloud.google.com/iam/docs/best-practices-for-using-workload-identity-federation) — stable subjects, restricted impersonation, and auditability.
[AWS IAM: Create an OpenID Connect provider](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc.html) — registering an IdP and configuring its audience.
[Harden deployments with GitHub Actions](https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments) — OIDC integrations with external clouds.