Skip to content

fix(auth): don't log out on a post-auth 401/403 query error (e.g. UNKNOWN_USER)#19

Merged
BorisTyshkevich merged 1 commit into
mainfrom
fix/no-logout-on-post-auth-403
Jun 22, 2026
Merged

fix(auth): don't log out on a post-auth 401/403 query error (e.g. UNKNOWN_USER)#19
BorisTyshkevich merged 1 commit into
mainfrom
fix/no-logout-on-post-auth-403

Conversation

@BorisTyshkevich

Copy link
Copy Markdown
Collaborator

Bug

On github.demo, SHOW CREATE USER 'btyshkevich@altinity.com' (an existing user) works, but SHOW CREATE USER 'btyshkevich@gmail.com' (a missing user) logged the user out with:

ClickHouse denied your account (HTTP 403). … Server: Code: 192. DB::Exception: There is no user btyshkevich@gmail.com in user directories. (UNKNOWN_USER)

Cause

ClickHouse maps several query-level errors to HTTP 403ACCESS_DENIED, and UNKNOWN_USER from SHOW CREATE USER <missing>. authedFetch treated any 401/403 as a credentials failure → refresh → onSignedOut, so a normal query error force-logged-out. (This is the over-broad flip side of the authorization-denied handling added in #11.)

Fix

Track ctx.authConfirmed, set on the first 2xx. A 401/403 is only treated as an auth/identity failure before the session has authenticated — preserving the first-contact "signed in via IdP but CH won't accept your identity" path. After a request has succeeded, the same credentials are still good, so a later 401/403 is a query error: authedFetch returns the response and the caller surfaces it (results pane, or a toast for SHOW CREATE) — no logout. Token expiry is unaffected (handled by getToken/refresh before the request; a failed refresh still routes to the expiry sign-out).

Tests / verification

ch-client.js stays at 100%; added cases for "a 2xx marks the ctx authenticated" and "a post-auth 403 is returned, not signed-out". Verified live on github.demo: the missing user now shows Code: 192 … UNKNOWN_USER in the results pane and stays signed in; the existing user still returns its CREATE USER … statement.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QennTvGKAtJZrv9EpQagef

…NOWN_USER)

ClickHouse maps several query-level errors to HTTP 403 — ACCESS_DENIED, and
UNKNOWN_USER from `SHOW CREATE USER <missing>`. authedFetch treated any 401/403
as a credentials failure and force-logged-out, so an authenticated user running
`SHOW CREATE USER 'nobody@x'` got booted to the login screen with the
authorization-denied banner.

Fix: track `ctx.authConfirmed` (set on the first 2xx). A 401/403 is only an
auth/identity failure *before* the session has authenticated — that keeps the
first-contact authorization-denied path (signed in via IdP but CH won't accept
the identity). Once a request has succeeded, the same credentials are still
valid, so a later 401/403 is a query error: return the response and let the
caller show it in the results pane (or as a toast for SHOW CREATE), no logout.

Verified on github.demo: `SHOW CREATE USER 'btyshkevich@gmail.com'` now shows
"Code: 192 … UNKNOWN_USER" in the results pane and stays signed in; the existing
user still returns its CREATE USER statement.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QennTvGKAtJZrv9EpQagef
@BorisTyshkevich BorisTyshkevich merged commit ffe900f into main Jun 22, 2026
2 checks passed
BorisTyshkevich pushed a commit that referenced this pull request Jun 22, 2026
@BorisTyshkevich BorisTyshkevich deleted the fix/no-logout-on-post-auth-403 branch June 22, 2026 16:43
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.

1 participant