Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for oidc aws session tags #3015

Merged
merged 2 commits into from
Sep 25, 2024
Merged

Add support for oidc aws session tags #3015

merged 2 commits into from
Sep 25, 2024

Conversation

sj26
Copy link
Member

@sj26 sj26 commented Sep 24, 2024

Description

Teach the agent how to request OIDC tokens including aws session tags:

buildkite-agent oidc request-token --audience sts.amazonaws.com --aws-session-tag pipeline_id

Claims are then added to the returned token as aws session tags using their prescribed format:

https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_adding-assume-role-idp

which can then be used to grant permission to aws resources using attribute based access control (ABAC):

https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_attribute-based-access-control.html

This is a finer grained control than the subject condition based option currently available:

https://buildkite.com/docs/pipelines/security/oidc/aws#step-2-create-a-new-or-update-an-existing-iam-role-to-use-with-your-pipelines

The Buildkite Agent API already supports this parameter.

Changes

Mostly copy/pasta of how --claim works. I also added an api test for claims alongside aws_session_tags.

Testing

  • Tests have run locally (with go test ./...). Buildkite employees may check this if the pipeline has run automatically.
  • Code is formatted (with go fmt ./...)
go run . oidc request-token --endpoint http://agent.buildkite.localhost --agent-access-token test --job abc123 --debug --debug-http --aws-session-tag organization_id
2024-09-24 13:43:44 DEBUG  Loaded config command=oidc request-token agent_version=3.78.0+x..dirty
2024-09-24 13:43:44 DEBUG  POST /jobs/abc123/oidc/tokens HTTP/1.1
Host: agent.buildkite.localhost
User-Agent: buildkite-agent/3.78.0.x (darwin; arm64)
Content-Length: 41
Content-Type: application/json
Accept-Encoding: gzip

{"aws_session_tags":["organization_id"]}

That will do the job.

@sj26 sj26 self-assigned this Sep 24, 2024
@sj26 sj26 requested a review from a team September 24, 2024 03:49
@sj26 sj26 force-pushed the oidc-aws-session-tags branch from 243b1a8 to 1051762 Compare September 24, 2024 03:52
Copy link
Contributor

@DrJosh9000 DrJosh9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just one nit.

api/oidc.go Outdated Show resolved Hide resolved
clicommand/oidc_request_token.go Outdated Show resolved Hide resolved
@sj26 sj26 enabled auto-merge September 25, 2024 06:35
@sj26 sj26 merged commit 1f69f1b into main Sep 25, 2024
1 check passed
@sj26 sj26 deleted the oidc-aws-session-tags branch September 25, 2024 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants