A Buildkite plugin to assume-role-with-web-identity using a Buildkite OIDC token before running the build command.
You will need to configure an appropriate OIDC identity provider in your AWS account with a Provider URL of https://agent.buildkite.com
and an Audience of sts.amazonaws.com
. This can be automated with Terraform. Then you can create a role to be assumed.
Use the plugin in your steps like this:
steps:
- command: aws sts get-caller-identity
plugins:
- aws-assume-role-with-web-identity:
role-arn: arn:aws:iam::AWS-ACCOUNT-ID:role/SOME-ROLE
This will call buildkite-agent oidc request-token --audience sts.amazonaws.com
and exchange the resulting token for AWS credentials which are then added into the environment so tools like the AWS CLI will use the assumed role.
If you automate your infrastructure with Terraform, the following configuration will setup a valid OIDC IdP in AWS -- adapted from an example for using OIDC with EKS:
locals {
agent_endpoint = "https://agent.buildkite.com"
}
data "tls_certificate" "buildkite-agent" {
url = local.agent_endpoint
}
resource "aws_iam_openid_connect_provider" "buildkite-agent" {
url = local.agent_endpoint
client_id_list = [
"sts.amazonaws.com",
]
thumbprint_list = [
data.tls_certificate.buildkite-agent.certificates[0].sha1_fingerprint,
]
}