Skip to main content
INS // Insights

Buildkite OIDC for AWS

Updated October 2026 · 7 min read

Buildkite OIDC AWS is how a pipeline assumes an IAM role from a token the job already has, and then stops reading a stored access key. The agent asks Buildkite for an OIDC token. AWS STS exchanges that token for a short-lived role session. When every job that needs AWS has exchanged successfully, the access key comes out of the pipeline. Rotation of that key was the previous control. Rotation keeps a long-lived secret on the agent. Exchange removes the secret from the job.

Rutagon builds the cutover on the pipeline the client already runs. One job first, then every other job that used the same key, then deactivation and deletion. A green build that still interpolates the access key has not finished the cutover. The token and the role session are the credentials that remain, and both expire.

Buildkite OIDC AWS trust on the role

The IAM OIDC provider issuer is https://agent.buildkite.com. The audience the job must request is sts.amazonaws.com. Buildkite documents a different default audience: the organization URL. AWS rejects that default against a role whose trust policy expects the STS audience. The job passes --audience sts.amazonaws.com. A token that looks well-formed in the job log still fails at STS when the audience is the default.

IAM treats this issuer as shared across Buildkite customers. The identity-provider controls require the trust policy to evaluate agent.buildkite.com:sub. A policy that checks an organization slug and never evaluates sub fails when the role is created or when the trust policy is updated. The subject on the token is a composite of organization, pipeline, ref, commit, and step. We pin the organization slug and the pipeline slug in that string. We also require agent.buildkite.com:organization_id. The organization id stays put when someone renames the slug.

{
  "Effect": "Allow",
  "Principal": {
    "Federated": "arn:aws:iam::111122223333:oidc-provider/agent.buildkite.com"
  },
  "Action": "sts:AssumeRoleWithWebIdentity",
  "Condition": {
    "StringEquals": {
      "agent.buildkite.com:aud": "sts.amazonaws.com",
      "agent.buildkite.com:organization_id": "ORG_UUID"
    },
    "StringLike": {
      "agent.buildkite.com:sub": "organization:ORG_SLUG:pipeline:PIPELINE_SLUG:*"
    }
  }
}

The wildcard sits at the end, after the pipeline slug, so a different pipeline in the same organization does not match. A condition value of * on sub would satisfy the shared-issuer check and would also allow any caller who can present a token from that issuer to attempt the role. We do not ship that condition. Optional claims such as cluster_id are absent unless the job requests them. A trust policy that requires cluster_id fails closed for a job that did not pass --claim cluster_id and did not set BUILDKITE_OIDC_TOKEN_CLAIMS. We condition only on claims the job requests. Buildkite documents the claim set and the matching AWS condition keys in OIDC with AWS.

The role's permission policy is a separate document from the trust policy. Trust decides which pipeline may assume the role. The permission policy decides what that session may call. A deploy job that can read one artifact bucket and pass one task role is the permission set we attach. AdministratorAccess on the CI role remains a finding after the exchange is perfect, because the exchange removed the long-lived key and left the blast radius of the session untouched.

The exchange inside the job

The agent command prints the token. The AWS CLI trades it for a session. The session name has to fit the STS limit of 64 characters, so the build number is the session name, rather than the full pipeline slug plus the commit.

TOKEN="$(buildkite-agent oidc request-token --audience sts.amazonaws.com)"
aws sts assume-role-with-web-identity \
  --role-arn "$BUILDKITE_AWS_ROLE_ARN" \
  --role-session-name "bk-${BUILDKITE_BUILD_NUMBER}" \
  --web-identity-token "$TOKEN" \
  --query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]' \
  --output text

The job exports those three values for the steps that follow. It does not write them into the Buildkite secret store. Buildkite documents a default token lifetime of five minutes, and --lifetime overrides it. The assume call has to complete before the token's expiry. A step that requests the token, then runs a long checkout, then assumes the role, fails at STS. The fix is to request the token immediately before the assume. Restoring the access key hides the expiry and puts the secret back.

The Buildkite plugin aws-assume-role-with-web-identity performs this same request with audience sts.amazonaws.com and exports the role credentials for the rest of the step. We use the plugin when the job is already a plugin block and the assume should be boring. We use the agent command when the script under review needs the assume to be visible line by line. Either path depends on the trust policy. The plugin does not insert the sub condition.

We prove the job no longer reads the key. The build log shows AssumeRoleWithWebIdentity. The AWS call the job exists to make succeeds. The step environment no longer contains the old access key id. A step that still interpolates the secret can pass while ignoring the token, so we delete the secret from that step's inputs before we call the step done. Another CI vendor with the same cutover shape is CircleCI OIDC for AWS. The account-wide version of the same work, beyond a single vendor, is replacing AWS access keys with OIDC.

Order of revocation

Start with one pipeline, preferably the one that both builds and deploys. Then every other pipeline, trigger, and shared template that injected the same access key. A hidden caller fails on deletion day, or someone pastes the key back during the incident and the deletion is undone. Search the cluster environment, the pipeline settings, and the shared steps library for the key id before calling the list complete.

During the overlap the key sits in a sealed admin path and is not mounted into steps. That sealed copy is the rollback for a single failed exchange: mount it on the one step that failed, fix the trust condition, and unmount it again. Once every step has a clean build, deactivate the key, confirm CloudTrail shows no further uses of that key id, and delete it. Rollback after deletion is a new federated role, or a new key with an owner and a removal date, stored outside the repository. A copy in a chat transcript is how the key returns.

Evidence for the GRC platform you already run is a short pack. Include the OIDC provider ARN, the role ARN, the trust policy, the list of pipelines that assumed the role, and the time the access key was deactivated and then deleted. A screenshot of the provider page, with no pipeline list and no deletion time, does not show that the key left the agent. This cutover is security automation on the CI system you already operate. We do not stand up a second build system to get rid of one key.

Failures we leave open

Not authorized to perform sts:AssumeRoleWithWebIdentity is a condition miss: audience, organization id, or subject. We decode the token claims in one redacted debug build, compare them to the trust policy, and change the condition. We do not attach a second access key to ship the deploy and then describe the migration as complete.

A token requested without the STS audience fails the audience check. A trust policy that requires cluster_id while the job never requests that claim fails closed, every build. A session name longer than 64 characters fails before the job calls the API it meant to call. Each of those has a configuration fix. None of them is a reason to restore the long-lived key.

Rutagon's own delivery jobs assume a role from a short-lived token the same way. That is how the pipelines run. It is a practice, and the client's evidence is still the trust policy plus the deletion record from their account. A pipeline that uses Bitbucket rather than Buildkite follows the sibling cutover in Bitbucket Pipelines OIDC.

Frequently Asked Questions

Why does IAM reject a Buildkite trust policy that looks complete?

Buildkite's issuer is shared. IAM requires the trust policy to evaluate agent.buildkite.com:sub before it will save the role. A policy that matches only a slug, or only organization_id, can fail at creation even though the token contains those claims. Keep the subject condition in the policy and put the organization id beside it.

What audience does the Buildkite job have to request?

sts.amazonaws.com. The agent command's default audience is the Buildkite organization URL, and STS will not assume an AWS role with that default. Pass --audience sts.amazonaws.com on buildkite-agent oidc request-token. The official assume-role plugin documents the same audience.

Can one IAM role serve every pipeline in the organization?

Only when the subject condition names that scope on purpose. We bind sub to one organization and one pipeline. A second pipeline gets its own role, or an additional subject value that names that pipeline explicitly. A subject of organization:ORG:* is an exception with an owner, because every pipeline in the organization can then assume the role.

What evidence is left after the access key is deleted?

Keep the OIDC provider, the role and its trust policy, the pipelines that assumed the role, and the CloudTrail record that the key stopped being used before deletion. The OIDC token and the role session are not stored. They expire on their own. The pack goes into the GRC platform the client already runs.

Talk to us about your credential elimination pilot. Contact Rutagon at rutagon.com/contact, 907-841-8407, or contact@rutagon.com.