fix(auth): preserve API-key user across RequireAuth re-dispatch#8913
Open
lrf-nitro wants to merge 1 commit into
Open
fix(auth): preserve API-key user across RequireAuth re-dispatch#8913lrf-nitro wants to merge 1 commit into
lrf-nitro wants to merge 1 commit into
Conversation
Open-API (/rest) requests authenticated with a valid API key were rejected with 401 "unauthorized" whenever AUTH_ENABLED is on (the default). The API-key middleware authenticates the request and sets common.USER via c.Set, then re-dispatches the rewritten path through router.HandleContext. gin's HandleContext calls Context.reset(), which sets c.Keys = nil and destroys the user, so the terminal RequireAuth gate sees no user and 401s. Carry the authenticated user on the request's context.Context, which survives HandleContext (only gin Keys are reset). GetUser now falls back to the request context when gin Keys are empty. This fixes every /rest endpoint (webhooks, push, etc.) at once without disabling auth. Add regression coverage: - shared: user set via SetUserOnRequest survives a HandleContext re-dispatch while gin Keys do not. - api: the full RestAuthentication -> OIDCAuthentication -> RequireAuth chain with AUTH_ENABLED=true returns 200 for a valid key, 401 for missing token, 403 for an invalid key, and 401 for a userless protected route.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Open-API (/rest) requests authenticated with a valid API key were rejected with 401 "unauthorized" whenever AUTH_ENABLED is on (the default - unless explicitly disabled via env var). The API-key middleware authenticates the request and sets common.USER via c.Set, then re-dispatches the rewritten path through router.HandleContext. gin's HandleContext calls Context.reset(), which sets c.Keys = nil and destroys the user, so the terminal RequireAuth gate sees no user and 401s.
Carry the authenticated user on the request's context.Context, which survives HandleContext (only gin Keys are reset). GetUser now falls back to the request context when gin Keys are empty. This fixes every /rest endpoint (webhooks, push, etc.) at once without disabling auth.
Add regression coverage:
pr-type/bug-fix,pr-type/feature-development, etc.