Skip to content

Fix webhook authorization when AUTH_ENABLED=true#9008

Open
kamphaus wants to merge 2 commits into
apache:mainfrom
kamphaus:fix/webhook-auth
Open

Fix webhook authorization when AUTH_ENABLED=true#9008
kamphaus wants to merge 2 commits into
apache:mainfrom
kamphaus:fix/webhook-auth

Conversation

@kamphaus

Copy link
Copy Markdown

⚠️ Pre Checklist

Please complete ALL items in this checklist, and remove before submitting

  • I have read through the Contributing Documentation.
  • I have added relevant tests.
  • I have added relevant documentation. → NA
  • I will add labels to the PR, such as 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

  • Disclose AI usage: AI-assisted
  • I have verified that the regression test fails without the fix and passes with the fix.

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.

[Bug][Webhook] Requests via /rest/... alias return 401 when AUTH_ENABLED=true, even with a valid API key

1 participant