fix(server): answer 401 when a token's user or namespace is gone - #6848
Conversation
The in-process authenticator propagated the store's own error when the JWT referenced entities that no longer exist, so the error handler mapped it to a 500 and the client was never told to re-authenticate. Before auth moved into the API process, the edge proxy turned any non-2xx from the authentication subrequest into a 401. Fixes: #6844
|
Claude finished @otavio's task in 1m 42s —— View job Code Review CompleteReviewed 2 files across code quality, security, testing, language patterns, and architecture — no new issues found. The code looks good as-is. The To request another review round, comment |
Yielding no identity on a failed role or admin lookup makes a store outage indistinguishable from a stale token: both surface only as a rise in 401s.
|
/review |
|
Claude finished @otavio's task in 1m 19s —— View job Code Review CompleteReviewed 2 files across code quality, security, testing, language patterns, and architecture — no new issues found. The code looks good as-is. I verified the package compiles, the
The two non-not-found test cases ( To request another review round, comment |
Completes the previous commit: the API key branch swallowed its error on the same rationale and was the last undiagnosable one left in Resolve.
|
/review |
|
Claude finished @otavio's task in 3m 20s —— View job Code Review CompleteReviewed 2 files across code quality, security, testing, language patterns, and architecture — no new issues found. The code looks good as-is. Verified this round:
The To request another review round, comment |
What
The in-process authenticator now yields no identity when it cannot resolve the
role or admin flag behind a JWT, so a stale token gets a 401 instead of a 500.
Why
Resolvepropagated the raw store error fromGetUserRoleandGetUserAdmin.Those errors carry
Layer: "store", which the echo error handler maps to 500,so every authenticated request with a token referencing deleted entities
answered 500 and the client was never told to re-authenticate. A database reset
without clearing the browser session reproduces it on every
GET /api/namespaces.Before auth moved into the API process, the nginx edge proxy turned any non-2xx
from the
/internal/authsubrequest into a 401 and never leaked the store's ownstatus codes.
7fb6ef42restored that behaviour for API keys; this restores itfor bearer tokens.
Closes #6844
Changes
*authorizer.UserClaimsbranchreturn
nil, nilon error. The middleware's fail-closed path then answers 401.A single comment above the branch carries the rationale for both sites rather
than repeating the one on the API-key branch.
a missing user, and — pinning the deliberate breadth of the rule — a store
transport error and a cancelled request. Two middleware-level tests assert the
401 on a protected route and that an anonymous route still reaches the handler
with forged identity headers scrubbed.
Testing
The blanket swallow is the point of contention worth a reviewer's attention: a
store outage now logs users out with a 401 rather than surfacing a 5xx you can
alert on. That matches the edge proxy's old behaviour and the API-key branch
directly above (whose comment already calls out "including when its store was
down"), but it is broader than "the entity does not exist". The two
non-not-found test cases exist so any future narrowing is visible in CI.