fix: oidc auth - invalid bearer token, errorCause invalid bearer token (swall... by Roshan931 · Pull Request #4204 · loft-sh/vcluster · GitHub
Skip to content

fix: oidc auth - invalid bearer token, errorCause invalid bearer token (swall... - #4204

Open
Roshan931 wants to merge 1 commit into
loft-sh:mainfrom
Roshan931:prilog/fix-error-vcluster-proxy-discards-tokenreview-10-10-2026-bb4b26
Open

Roshan931 wants to merge 1 commit into
loft-sh:mainfrom
Roshan931:prilog/fix-error-vcluster-proxy-discards-tokenreview-10-10-2026-bb4b26

Conversation

@Roshan931

@Roshan931 Roshan931 commented Oct 10, 2026 •

Copy link
Copy Markdown

Fixes #3930

Root cause

vCluster proxy discards TokenReview status error

Changes

  • Log the TokenReview rejection reason (tokReview.Status.Error) in pkg/authentication/delegatingauthenticator before falling through, instead of silently dropping it, and add a unit test covering the rejection path.

Note

Low Risk
Adds verbose logging on an existing rejection path; no change to authentication outcomes or error propagation.

Overview
When the vCluster proxy delegates bearer-token validation via TokenReview and the virtual cluster API server rejects the token, the delegating authenticator now emits a V(1) klog line including tokReview.Status.Error instead of failing silently with no reason.

Auth behavior is unchanged: rejected tokens still return unauthenticated with no error to the caller—only observability improves for debugging OIDC/invalid-token issues (e.g. #3930).

Reviewed by Cursor Bugbot for commit 129b251. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Robert Markovski <5818108+Roshan931@users.noreply.github.com>
@Roshan931
Roshan931 requested a review from a team as a code owner October 10, 2026 08:14

@blacksoxx blacksoxx 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.

Thanks for looking into this one, it has been a confusing error to debug. I traced the path on main and I think the reporter's expected line can be restored without a verbosity flag.

filters/authentication.go:75 (vendored k8s.io/apiserver) logs the error returned by the union authenticator, and the union authenticator aggregates the errors of each authenticator in the chain. Upstream's webhook token authenticator returns the review error when the token is not authenticated:

// vendor/k8s.io/apiserver/plugin/pkg/authenticator/token/webhook/webhook.go:170
if !r.Status.Authenticated {
    var err error
    if len(r.Status.Error) != 0 {
        err = errors.New(r.Status.Error)
    }
    return nil, false, err
}

vcluster's delegating authenticator returns nil, false, nil on the same branch, so the aggregate only ever contains invalid bearer token. Returning errors.New(tokReview.Status.Error) there mirrors upstream and brings back [invalid bearer token, oidc: email not verified] in the existing ERROR line, which is what #3930 asks for. A V(1) log works too but needs -v on the syncer; which of the two the maintainers prefer is their call, I just wanted to put the upstream behaviour next to it.

Two small things on the PR itself: the description mentions a unit test for the rejection path, but the diff only has the one file; and gofmt -l flags the file because the blank line between the import block and var ( was removed.

This branch has not been deployed

No deployments
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.

oidc auth - invalid bearer token, errorCause invalid bearer token (swallowing "oidc: email not verified" root cause)

2 participants