Skip to main content
INS // Insights

Bitbucket Pipelines OIDC AWS Key Removal

Updated October 2026 · 7 min read

Bitbucket Pipelines OIDC AWS is a workspace OpenID Connect provider in the AWS account, a role whose trust names the repository, and a step with oidc: true so the pipeline can assume that role without an access key stored in Bitbucket. The pain is the secured variable. AWS_ACCESS_KEY_ID sits at the repository, the deployment environment, or the workspace. It was added so a pipeline could push to S3 or apply Terraform. It is still there. Anyone who can edit variables, and anyone who can print the environment of a step, is closer to that key than the trust policy of a role would allow. The key has no relationship to a branch, a step, or a deployment environment. The OIDC token does.

Atlassian's deploy-on-AWS guidance is the setup we follow: register the provider, create the role, set oidc: true, and pass BITBUCKET_STEP_OIDC_TOKEN. Rutagon's work is the part after the happy path. One provider for the workspace. A separate role for production. A trust condition on the repository UUID. And the deletion of the stored keys once a real step has assumed the role.

How Bitbucket Pipelines OIDC AWS is pinned

The provider URL and the audience come from the workspace OpenID Connect page. The issuer looks like https://api.bitbucket.org/2.0/workspaces/{workspace}/pipelines-config/identity/oidc. The audience looks like ari:cloud:bitbucket::workspace/{workspace-uuid}. We copy both. AWS allows one OIDC provider per URL in an account, so the workspace gets one provider, and every repository role trusts that provider. A second provider for the same URL fails. A provider created from a stale screenshot fails in a quieter way: the thumbprint or the audience does not match the token the step presents.

The token's sub claim starts with the repository UUID. When the step is tied to a deployment environment, the environment UUID is included before the step UUID. Those are the fields the trust can see. Branch name is on the token and is not a reliable IAM condition key for this provider, so we do not pretend a branch string in the trust is what AWS will enforce. We constrain sub.

{
  "Effect": "Allow",
  "Principal": {
    "Federated": "arn:aws:iam::ACCOUNT_ID:oidc-provider/api.bitbucket.org/2.0/workspaces/WORKSPACE/pipelines-config/identity/oidc"
  },
  "Action": "sts:AssumeRoleWithWebIdentity",
  "Condition": {
    "StringEquals": {
      "api.bitbucket.org/2.0/workspaces/WORKSPACE/pipelines-config/identity/oidc:aud": "ari:cloud:bitbucket::workspace/WORKSPACE_UUID"
    },
    "StringLike": {
      "api.bitbucket.org/2.0/workspaces/WORKSPACE/pipelines-config/identity/oidc:sub": "{REPO_UUID}:*"
    }
  }
}

A workspace-wide role, with no repository condition, lets every pipeline in the workspace assume production. That is the same blast radius as a workspace-level access key. Production is a second role. Its sub condition includes the deployment environment UUID, so only a step assigned to that environment can assume it. Pull-request steps and default-branch steps assume the non-production role, or they assume nothing. The pipeline file sets oidc: true on each step that calls AWS. We do not depend on a default. A step without the flag has no BITBUCKET_STEP_OIDC_TOKEN, and the AWS CLI falls through to whatever key is still in the environment.

The step writes the token where the AWS CLI expects a web identity file, and it sets AWS_ROLE_ARN to the role for that environment. The session name includes the pipeline UUID so CloudTrail can be joined back to a build. Duration stays short. A step that needs a longer session is a design problem, not a reason to store a key.

Removing the keys Bitbucket still holds

OIDC can be wired and green while AWS_ACCESS_KEY_ID remains a secured variable. The CLI prefers a static key when both are present. The cutover inventory lists variables named AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN at workspace, repository, and deployment scope. It also lists any variable whose value matches an access key id we already know from the credential report. Names drift. People call them PROD_AWS_KEY. The known key id catches those.

We run one successful assume from the production deployment step and one from a non-production step, and we find both in CloudTrail as AssumeRoleWithWebIdentity. Then we delete the variables. The next build has to go green on the role alone. A failed build after deletion reopens the row. We do not restore the key into the variable store as the fix. The fix is the trust, the audience, or the step flag.

workspace: client
repo_uuid: "{repo}"
prod_environment_uuid: "{env}"
oidc_on_deploy_step: true
assume_role_seen: true
secured_aws_keys_remaining: 0

Replacing AWS access keys with OIDC is the same end state for other CI systems. The Bitbucket-specific parts are the workspace provider URL, the braced repository UUID in sub, and the deployment environment UUID that appears only on deployment steps. Pulumi OIDC is a different issuer and a different subject. A team that uses both still gets two providers and two ledgers. Collapsing them into one "OIDC is on" checkbox hides a key left in one of the products.

What the reviewer sees after the keys are gone

The role is reviewed like any other CI principal. The row shows the repository, the environment, the role ARN, the sub condition, and the last assume time. A production role assumed from a repository UUID that does not match the condition is a trust bug, and CloudTrail is where it would appear. A role with no assume inside the build window is an unused path or a pipeline that went back to a key. The variable inventory answers which.

Permissions on the role stay scoped to what that pipeline does. A pipeline that copies one object does not get a role that can create IAM users. The policy ARN is on the evidence row. When the pipeline's job changes, the policy change is a separate edit with its own request, not a quiet attachment of AdministratorAccess so the next apply will pass.

Workspace variables are the ones that surprise people. A key defined at workspace scope is injected into repositories that never opted in. The inventory treats workspace scope as higher priority than repository scope, because the blast radius is the workspace. Deleting it is part of the same cutover, after every repository that used it has a role of its own. Repositories that still fail their assume stay on the key until their role works, and they are listed. A partial cutover is an explicit list. It is not a claim that the workspace is clean.

Security automation runs the provider check, the trust conditions, the variable inventory, and the CloudTrail recheck. The GRC item closes when secured_aws_keys_remaining is zero for the repositories in scope and the assume has been seen.

Rutagon delivers the workspace provider, the per-repository and per-environment roles, the oidc: true steps, and the removal of the stored keys. Bitbucket remains the place pipelines run. AWS remains the place the role lives. Our store is the proof that a build assumed the role and that the key variables are gone.

Frequently Asked Questions

Why is the repository UUID in the trust policy?

The token's sub claim starts with that UUID, and IAM can match sub. A role without the condition can be assumed by any repository in the workspace that can set oidc: true. Production roles add the deployment environment UUID so only steps assigned to that environment match.

What if both a key variable and oidc: true are set?

The AWS CLI uses the static key when it is in the environment. The pipeline looks green and the key is still the credential. We delete the key variables only after CloudTrail shows AssumeRoleWithWebIdentity for that role, then we rerun the build and require it to pass on the role alone.

Where do we read the provider URL from?

The workspace OpenID Connect settings page. The audience on that page is the aud value we put in StringEquals. Copying either value from a different workspace, or from an old thumbnail of the page, produces a provider the step's token will not satisfy.

Do pull-request builds assume the production role?

Production trust requires the deployment environment UUID. Pull-request steps are not that environment, so they do not match. They use a separate role with a narrower policy, or they do not receive AWS credentials at all. The pipeline file names the role per step.

Ask for a credential diagnostic that inventories AWS keys in Bitbucket Pipelines and moves those steps to OIDC. Contact Rutagon at https://rutagon.com/contact, 907-841-8407, or contact@rutagon.com.