Skip to content

Add --subject-claim flag to oidc request-token#3784

Merged
SorchaAbel merged 1 commit intomainfrom
pb-1331-add-subject-claim-flag-to-buildkite-agent-oidc-request-token
Mar 30, 2026
Merged

Add --subject-claim flag to oidc request-token#3784
SorchaAbel merged 1 commit intomainfrom
pb-1331-add-subject-claim-flag-to-buildkite-agent-oidc-request-token

Conversation

@zero51
Copy link
Copy Markdown
Contributor

@zero51 zero51 commented Mar 27, 2026

Description

Adds a --subject-claim flag to buildkite-agent oidc request-token, allowing users to specify an immutable claim (e.g. cluster_id, pipeline_id) as the OIDC token's subject instead of the default compound subject.

This unblocks Azure federated identity credentials, which reject wildcard sub claims like commit:* that appear in the default compound subject.

Context

  • Linear: PB-1331.
  • Depends on: PB-1329 (API-side acceptance of subject_claim parameter).

Changes

New --subject-claim flag added, following the existing pattern of --audience, --claim and --aws-session-tag:

$ buildkite-agent oidc request-token --help
  --subject-claim value       An immutable claim to use as the token's subject (e.g. pipeline_id, cluster_id). If omitted, the default compound subject is used. [$BUILDKITE_OIDC_TOKEN_SUBJECT_CLAIM]
  • api/oidc.go: added SubjectClaim field to OIDCTokenRequest and wired it into the JSON request body as subject_claim with omitempty.
  • clicommand/oidc_request_token.go: added config field, CLI flag (with env var BUILDKITE_OIDC_TOKEN_SUBJECT_CLAIM) and pass-through to API request.
  • api/oidc_test.go: added table-driven test case verifying SubjectClaim serialises correctly.

Testing

  • Tests have run locally (with go test ./...).
  • Code is formatted (with go tool gofumpt -extra -w .).

Disclosures / Credits

Amp (Claude) walked me through the codebase, wrote the implementation and test, and drafted this PR description. I added the EnvVar binding.

Allows specifying an immutable claim (e.g. cluster_id) as the OIDC
token's subject, instead of the default compound subject. This enables
Azure federated identity credentials which reject wildcard sub claims.

Configurable via `--subject-claim` flag or `BUILDKITE_OIDC_TOKEN_SUBJECT_CLAIM`
environment variable. Omitting it preserves existing behavior (omitempty).

Fixes PB-1331.
@zero51 zero51 self-assigned this Mar 27, 2026
@zero51 zero51 requested review from a team as code owners March 27, 2026 02:20
@zero51 zero51 requested a review from a team March 27, 2026 02:21
Copy link
Copy Markdown
Contributor

@SorchaAbel SorchaAbel left a comment

Choose a reason for hiding this comment

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

LGTM

@swebb
Copy link
Copy Markdown
Contributor

swebb commented Mar 30, 2026

tl;dr, I think this is good, but I'll let someone more familiar with the Agent and Go approve it.

I was initially nervous because the OIDC subject field is security sensitive; however, I think it's ok. The real dangerous work was in https://github.com/buildkite/buildkite/pull/28662.

This PR doesn't allow setting arbitrary values for subject. Rather, you can specify one of the field names (e.g., cluster_id, or pipeline_id) and Buildkite will populate the subject with only that field. This is a very simplified version of what Github provides. Initially I thought we would need compound keys to write a policy to match; however, all of the other claims (org slug, pipeline slug, branch, etc.) are still present in the OIDC token for the policy to match on, they are just no-longer in the subject field (if they were there already).

Copy link
Copy Markdown
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! ✅

@SorchaAbel SorchaAbel merged commit 7485b31 into main Mar 30, 2026
1 check passed
@SorchaAbel SorchaAbel deleted the pb-1331-add-subject-claim-flag-to-buildkite-agent-oidc-request-token branch March 30, 2026 06:27
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.

4 participants