Skip to content

fix(auth): preserve API-key user across RequireAuth re-dispatch#8913

Open
lrf-nitro wants to merge 4 commits into
apache:mainfrom
AkerBP:fix/openapi-key-auth-401-requireauth
Open

fix(auth): preserve API-key user across RequireAuth re-dispatch#8913
lrf-nitro wants to merge 4 commits into
apache:mainfrom
AkerBP:fix/openapi-key-auth-401-requireauth

Conversation

@lrf-nitro

Copy link
Copy Markdown
Contributor

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:

  • 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.

⚠️ 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.
  • I will add labels to the PR, such as pr-type/bug-fix, pr-type/feature-development, etc.

lrf-nitro and others added 4 commits June 8, 2026 14:07
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.
* feat(gh-copilot): close API gaps for per-user metrics, teams, CLI, code review, and PR fields

Add missing GitHub Copilot Metrics API fields to achieve full API parity:

Enterprise/Org metrics:
- CLI active user counts and CLI breakdown (sessions, requests, tokens)
- Code review user counts (daily/weekly/monthly × active/passive)
- Chat panel mode breakdown (agent/ask/custom/edit/plan/unknown)
- Expanded PR metrics (merged, merge time, suggestions, Copilot impact)

Per-user metrics:
- used_cli, used_copilot_code_review_active/passive boolean flags
- CLI breakdown per user (sessions, requests, tokens)

User-team mapping (new):
- New collector/extractor for user-teams-1-day endpoint
- Enables team-level metrics via JOIN with per-user tables

Seat assignments:
- Team assignment fields (assigning_team id/name/slug)
- User detail fields (name, email)

Includes migration script 20260527 and comprehensive docs in
COPILOT_METRICS_GAPS.md.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* feat(copilot-metrics): remove outdated metrics gaps documentation and implement new user-team mapping and metrics enhancements

Signed-off-by: Jarek <jaroslaw.gajewski@atos.net>

---------

Signed-off-by: Jarek <jaroslaw.gajewski@atos.net>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ion (apache#8907) (apache#8912)

* refactor(plugin-circleci): extract unfinished-jobs input clauses into a helper

Signed-off-by: Volodymyr Zahorniak <v.zahorniak@gmail.com>

* fix(plugin-circleci): populate workflow id for unfinished-job collection (apache#8907)

The collectJobs 'unfinished details' collector built its URL from
'/v2/workflow/{{ .Input.Id }}/job' but its iterator selected 'DISTINCT
workflow_id' into a models.CircleciJob, leaving .Id empty and producing
'/v2/workflow//job' (HTTP 500) whenever a job was running/queued/on_hold.
Alias the projection to 'workflow_id AS id' so .Id carries the workflow id,
mirroring the new-records collector. Adds an e2e regression test.

Signed-off-by: Volodymyr Zahorniak <v.zahorniak@gmail.com>

---------

Signed-off-by: Volodymyr Zahorniak <v.zahorniak@gmail.com>
Co-authored-by: Klesh Wong <klesh@qq.com>
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.

3 participants