Keyless CI/CD with OIDC

Short-lived cloud credentials for pipelines

Pipelines used to deploy with long-lived cloud keys stored as CI secrets. With OpenID Connect (OIDC), the CI platform gives each job a signed identity token, and the cloud exchanges it for credentials that last minutes. There is no stored key to leak, but the trust policy must be precise.

Intermediate · 5 steps

StandardOpenID Connect
AWS callAssumeRoleWithWebIdentity
Also onAzure workload identity federation, GCP Workload Identity
Token issuertoken.actions.githubusercontent.com
Key checkTrust policy on the "sub" claim
Credential lifetimeMinutes to an hour

Step by step

  1. The job asks for an identity token Signed by the CI platform

    When the deploy job starts, it requests an OIDC token from the CI platform. The token is signed and says exactly which repository, branch and workflow is running, and which cloud it's meant for.

  2. Exchange it for cloud credentials AssumeRoleWithWebIdentity

    The job sends the token to the cloud's security token service and asks to assume the deploy role. The cloud verifies the token's signature against the CI provider's published keys, then checks the role's trust policy.

  3. The trust policy decides Exactly which repo and branch

    The trust policy only allows tokens whose subject is the main branch of acme/shop. This token matches, so STS returns credentials valid for one hour, and the job deploys. Nothing long-lived was ever stored.

  4. A too-broad trust policy Wildcards trust everyone

    If the condition had been repo:acme/* or, worse, missing, any repository in the organisation (or on the platform) could assume the production role. Here a job in an experimental repo tries, and is rejected because the subject doesn't match.

  5. Production approvals People still decide

    For production, the trust policy can require a deployment environment instead of a branch, and that environment needs a reviewer's approval. The result: short-lived credentials, issued only to the right workflow, only after a human approves.

Security notes

More in DevSecOps.