This Bitbucket pipe enables your CI/CD pipeline to assume an AWS role using OIDC (OpenID Connect) and build and publish Docker images to a public Docker Hub repository.
- Bitbucket repository with OIDC enabled for your pipelines.
- AWS account with IAM role configured for OIDC.
-
Enable OIDC in your pipeline: Ensure your Bitbucket pipeline step has
oidc: true
enabled. -
Set up repository variables:
AWS_OIDC_ROLE_ARN
: The ARN of the AWS IAM role to assume.AWS_DEFAULT_REGION
: The default AWS region to use.
- Create an IAM role in AWS with the necessary permissions for your tasks.
- Configure the role for OIDC by adding the Bitbucket OIDC provider to the trust policy.
Create a file named bitbucket-pipelines.yml
in the root of your repository with the following content:
pipelines:
default:
- step:
name: Do something after authenticating to AWS via OIDC
oidc: true
script:
- pipe: docker://dwightwhitlock1/aws-oidc-bitbucket-pipe:sha-1d105b4
variables:
AWS_OIDC_ROLE_ARN: arn:aws:iam::0000000000:role/bitbucket-oidc-role
AWS_DEFAULT_REGION: us-east-1