Skip to content

Terser authentication logic in front-proxy#4126

Open
ntnn wants to merge 1 commit into
kcp-dev:mainfrom
ntnn:fix-auth-logic
Open

Terser authentication logic in front-proxy#4126
ntnn wants to merge 1 commit into
kcp-dev:mainfrom
ntnn:fix-auth-logic

Conversation

@ntnn
Copy link
Copy Markdown
Member

@ntnn ntnn commented May 13, 2026

Summary

That logic never sat right with me and it seems to cause a logic error.

The original error was fixed with #4125, which moved the front-proxy back to its old behaviour that relies on essentially a race for the test to function:

The root cause of the error was that an authenticated request came through but the authenticator wasn't yet ready, so the original code here:

// If an authenticator for the workspace exists,
// it offers an alternative way to authenticate.
reqAuthenticator, ok := authentication.WorkspaceAuthenticatorFrom(req.Context())
if ok {
if auth != nil {
authenticator = authenticatorunion.New(auth, reqAuthenticator)
} else {
authenticator = reqAuthenticator
}
additionalAuth = true
}

Would return nil, false from here

func WorkspaceAuthenticatorFrom(ctx context.Context) (authenticator.Request, bool) {
authenticator, ok := ctx.Value(authenticatorContextKey).(authenticator.Request)
if !ok {
return nil, false
}
return authenticator, true
}

Because the handler that should add the workspace authenticator in the cotext silently fails here:

authn, ok := authIndex.Lookup(wsType)
if !ok {
handler.ServeHTTP(w, req)
return

Because of the change that validated authenticators before returning them the authenticator was in the index later than the test assumed, turning this into a race.

Anyhow - this doesn't fix that issue. I just noticed this issue because of that.

This fixes another problem that currently isn't tested - if a request with a static token comes in for a workspace that has per-workspace authentication configured the request will get denied.

I skipped writing a test for this because this will be fixed as part of #4100

What Type of PR Is This?

/kind bug

Related Issue(s)

Fixes #

Release Notes

NONE

@kcp-ci-bot kcp-ci-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the DCO. kind/bug Categorizes issue or PR as related to a bug. labels May 13, 2026
@kcp-ci-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign embik for approval. For more information see the Code Review Process.

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

@kcp-ci-bot kcp-ci-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 13, 2026
Comment thread pkg/proxy/filters/filters.go Outdated
}

// When configured to enable auth other than ClientCert, this returns true.
func (c *Authentication) AdditionalAuthEnabled() bool {
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.

Will be suprised if this will not break anything.

@ntnn
Copy link
Copy Markdown
Member Author

ntnn commented May 13, 2026

This whole thing is a mess.

Basically the front-proxy tries to authenticate a request but just lets it through if it doesn't succeed unless the workspace has per-workspace auth configured.
Then it actually fails.

This causes a problem in the tests because there the shards have fixed identities with tokens (from the csv file) that the front-proxy doesn't know about. This only works because the additionalAuth boolean is false for the front-proxy and is only set for per-workspace auth explicitly. And this in turn doesn't show up in the tests because the per-worspace auth tests only use per-workspace auth and the tests using static tokens don't.

This also hides a bug if a static token is used to access a worksapce with per-workspace auth - this will get declined on the front-proxy simply because per-workspace auth does not recognize the static token.

@ntnn ntnn force-pushed the fix-auth-logic branch 2 times, most recently from 1fafcb7 to 24c9370 Compare May 13, 2026 14:02
Signed-off-by: Nelo-T. Wallus <red.brush9525@fastmail.com>
Signed-off-by: Nelo-T. Wallus <n.wallus@sap.com>
@ntnn ntnn force-pushed the fix-auth-logic branch from 24c9370 to 9daad4b Compare May 13, 2026 14:23
@ntnn ntnn added this to tbd May 13, 2026
@ntnn ntnn moved this to In review in tbd May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. kind/bug Categorizes issue or PR as related to a bug. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants