Fix webhook authorization when AUTH_ENABLED=true#9008
Open
kamphaus wants to merge 2 commits into
Open
Conversation
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.
pr-type/bug-fix,pr-type/feature-development, etc.Summary
When AUTH_ENABLED=true, requests to REST-style webhook endpoints (e.g. /rest/plugins/webhook/connections/:id/deployments) were incorrectly rejected with 401 Unauthorized even when a valid, authorized API key was supplied. The root cause is in RestAuthentication: it validates the API key and stores the resulting user on the gin context, then reroutes the request from /rest/... to /plugins/... via gin's HandleContext. That call internally resets c.Keys, wiping the user that was just set, so the downstream RequireAuth middleware sees no authenticated user and rejects the request.
The fix stores the authenticated user in the underlying http.Request's context as well, since c.Request survives gin's context reset during the reroute. shared.GetUser now falls back to this request-context value when the gin context key is missing. A regression test spins up a real router with RestAuthentication + a RequireAuth-style gate + a webhook handler, and confirms a valid bearer-token request now reaches the handler (200) instead of being rejected (401).
Does this close any open issues?
Closes #9007
Other Information