Skip to content

Make TokenReview audiences configurable - #1530

Open
cvas22 wants to merge 4 commits into
tektoncd:mainfrom
cvas22:feat/1331-token-audiences
Open

cvas22 wants to merge 4 commits into
tektoncd:mainfrom
cvas22:feat/1331-token-audiences

Conversation

@cvas22

@cvas22 cvas22 commented Nov 11, 2026 •

Copy link
Copy Markdown

Changes

Fixes #1331

The API server sends its TokenReview without Audiences, so the Kubernetes API server only accepts tokens issued for its own default audience. Projected service account tokens with a custom audience always fail.

This adds AUTH_TOKEN_AUDIENCES, a comma-separated list that's sent with every TokenReview. When it's set, a token is only accepted if status.audiences comes back with one of the requested values, as the TokenReview API asks clients to check, so a token from an authenticator that isn't audience aware gets rejected rather than silently passing. Those rejections go into the negative cache like any other unauthenticated result. Leaving it empty keeps today's behavior.

The list replaces the default audience, it isn't added to it. The watcher uses a token for the cluster's default audience, so a list without the default audience (for example https://kubernetes.default.svc) makes the API server reject the watcher and nothing is stored. Always list the default audience next to the custom ones. The README says so and explains how to find it.

Tests: TestRBACTokenAudiences covers the default, custom and mixed audience cases and the non-audience-aware case, and checks the audiences that are sent. TestTokenAudiences covers parsing.

/kind feature

Submitter Checklist

  • Has Docs included if any changes are user facing
  • Has Tests included if any functionality added or changed
  • Tested your changes locally
  • Follows the commit message standard
  • Meets the Tekton contributor standards
  • Has a kind label
  • Release notes block below has been updated with any user-facing changes
  • Release notes contain the string "action required" if the change requires additional action from users switching to the new release

Release Notes

The API server can now validate tokens issued for a custom audience. Set AUTH_TOKEN_AUDIENCES to a comma-separated list of audiences to send with each TokenReview. Action required: the list replaces the default audience, so it has to include the default audience too or the watcher can no longer authenticate.

@tekton-robot tekton-robot added kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Nov 11, 2026
@tekton-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign enarha after the PR has been reviewed.
You can assign the PR to them by writing /assign @enarha in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 11, 2026
@enarha
enarha requested a balanced review from Copilot November 17, 2026 09:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

An unresolved critical configuration bug silently ignores environment-only AUTH_TOKEN_AUDIENCES, rejecting custom-audience tokens while continuing to accept default-audience tokens despite the configured restriction.

1 open issue
What changed in this PR

Adds configurable TokenReview audiences to the Results API server, supporting custom-audience service-account tokens while preserving existing behavior when unset.

Changes:

  • Adds AUTH_TOKEN_AUDIENCES parsing and wires it into RBAC authentication.
  • Requires a matching returned audience when configured and negatively caches audience-related rejections.
  • Adds audience-handling tests, parsing tests, and configuration documentation.
File Description
pkg/​api/​server/​v1alpha2/​auth/​rbac.go Sends configured audiences and validates TokenReview responses.
pkg/​api/​server/​v1alpha2/​auth/​rbac_test.go Tests default, custom, mixed, and audience-unaware authentication cases.
pkg/​api/​server/​config/​config.go Adds the audience setting and comma-separated parsing.
pkg/​api/​server/​config/​config_test.go Tests audience parsing and empty-value handling.
config/​base/​env/​config Adds an empty default audience setting.
cmd/​api/​README.md Documents the new configuration option.
cmd/​api/​main.go Passes configured audiences to the RBAC checker and logs them.

Review effort: Balanced

// removed. It returns nil when no audience is configured.
func (c *Config) TokenAudiences() []string {
var audiences []string
for _, a := range strings.Split(c.AUTH_TOKEN_AUDIENCES, ",") {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, added the empty default so it works from the environment alone, plus a test for it. Fixed in b6e3e66.

@enarha

enarha commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

@cvas22 thanks for the PR. The CI failure was fixed by #1544, please rebase your PR and it will pass.
I have few small comments on the PR, I would like to properly test it tomorrow on a live cluster before I comment. Thanks again.

The API server sent TokenReview requests without audiences, so the
Kubernetes API server only accepted tokens issued for its own default
audience. Projected service account tokens with a custom audience were
always rejected.

AUTH_TOKEN_AUDIENCES takes a comma-separated list of audiences that is
sent with each TokenReview. A token is accepted only when the response
confirms one of them, which also rejects tokens from authenticators that
are not audience aware. Leaving it empty keeps the current behavior.

Fixes tektoncd#1331
Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@cvas22
cvas22 force-pushed the feat/1331-token-audiences branch from b6e3e66 to 44de7ff Compare November 17, 2026 23:36
@cvas22

cvas22 commented Nov 17, 2026

Copy link
Copy Markdown
Author

thx, rebased on main. Looking forward to your comments after the cluster test.

@enarha

enarha commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

I tested the PR and it works as expected. There is one issue we need to make very clear in both PR description, but even more so in the docs. Strictly a custom list of audiences not including the default audience breaks the watcher. Our own controller won't be able to store anything through the api because it uses the default audience of the cluster. We have two options going forward, automatically discover the default audience and make the custom audiences list additive to the default one. Not sure if that's really possible and how complex it is. The other option is we make that very clear in the documentation including ways for the user to find the default audience, so when they craft the value of AUTH_TOKEN_AUDIENCES they always include the default audience as well. I'm excluding the option to change the watcher code. @gbenhaim @khrm WDYT?

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@cvas22

cvas22 commented Nov 18, 2026

Copy link
Copy Markdown
Author

Thx for testing. I went with the documentation option: the README now says the list replaces the default audience and has to include it, with ways to look it up, and the description and release note say the same. I did not try to discover the default audience automatically, so that would be a follow up if you prefer it.

@tekton-robot tekton-robot added release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Nov 18, 2026
@adityavshinde

Copy link
Copy Markdown
Contributor

Thx for testing. I went with the documentation option: the README now says the list replaces the default audience and has to include it, with ways to look it up, and the description and release note say the same. I did not try to discover the default audience automatically, so that would be a follow up if you prefer it.

Thanks for documenting that the cluster’s default audience must be included. One small clarification: saying it can be found in the aud claim of “any service account token” may be misleading, because a projected token can contain only its custom audience, such as tekton-results. Could this recommend checking the watcher’s default auto-mounted service-account token or the kube-apiserver --api-audiences setting instead?

return true, tr, nil
}
}
tr.Status = authnv1.TokenReviewStatus{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we add a case where TokenReview returns Authenticated: true with a non-empty but disjoint status.audiences list? The current fake changes a mismatched request to Authenticated: false, so it does not directly verify the overlap protection.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added that case in 21269e8: the fake returns Authenticated true with an unrelated audience and the request is rejected.

@adityavshinde

Copy link
Copy Markdown
Contributor

The API reads this configuration during startup. Updating the ConfigMap alone will not update existing API processes. They need to restart
A small README note such as this would help:
Restart the Tekton Results API deployment after changing AUTH_TOKEN_AUDIENCES
This is just a nit and not a blocker

@cvas22

cvas22 commented Nov 30, 2026

Copy link
Copy Markdown
Author

Thx, both good points. README now points at the watcher's auto-mounted token or --api-audiences instead, and has the restart note. I also added a test case for a token authenticated for a disjoint audience (rejected). 21269e8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support configurable token audiences in TokenReview authentication

5 participants