Repository navigation
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
🟡 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_AUDIENCESparsing 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, ",") { |
There was a problem hiding this comment.
Good catch, added the empty default so it works from the environment alone, plus a test for it. Fixed in b6e3e66.
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>
b6e3e66 to
44de7ff
Compare
|
thx, rebased on main. Looking forward to your comments after the cluster test. |
|
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 |
Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
|
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 |
| return true, tr, nil | ||
| } | ||
| } | ||
| tr.Status = authnv1.TokenReviewStatus{ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Added that case in 21269e8: the fake returns Authenticated true with an unrelated audience and the request is rejected.
|
The API reads this configuration during startup. Updating the ConfigMap alone will not update existing API processes. They need to restart |
|
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 |

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 ifstatus.audiencescomes 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:
TestRBACTokenAudiencescovers the default, custom and mixed audience cases and the non-audience-aware case, and checks the audiences that are sent.TestTokenAudiencescovers parsing./kind feature
Submitter Checklist
Release Notes