[GH-ISSUE #6620] JWT group sync silently never persists when the dashboard cancels the request #11609

Closed
opened 2026-08-05 01:30:10 -04:00 by saavagebueno · 1 comment
Owner

Originally created by @den-dw on GitHub (Jun 30, 2026).
Original GitHub issue: https://github.com/netbirdio/netbird/issues/6620

Describe the problem

With JWT group sync enabled, a user's JWT-derived groups (users.auto_groups) are never persisted. The dashboard shows no groups for the user, and the management log repeats, on essentially every dashboard request:

management/server/http/middleware/auth_middleware.go:157: HTTP server failed to sync user JWT groups: context canceled

while users.auto_groups stays [].

Root cause

checkJWTFromRequest (management/server/http/middleware/auth_middleware.go) calls syncUserJWTGroups(ctx, userAuth) with ctx = r.Context() — the HTTP request context. SyncUserJWTGroups persists the groups in a DB transaction bound to that context (ExecuteInTransaction). The dashboard SPA routinely aborts in-flight fetch() calls on re-render/navigation, which cancels the request context mid-write; the transaction is rolled back and the groups never persist. The error is logged but swallowed (no return), so it repeats silently.

This is distinct from #2696 (the older lock/deadlock that hung the dashboard, fixed in v0.31.0) — here the dashboard is responsive, the write is simply rolled back.

Steps to reproduce

  1. Self-host management with an external IdP that emits a flat groups claim (e.g. Keycloak).
  2. Enable JWT group sync (Settings → Groups), claim name groups.
  3. Log into the dashboard as a user whose token carries "groups": ["..."].
  4. Observe users.auto_groups stays [] and the log repeats failed to sync user JWT groups: context canceled.

Expected behaviour

The user's JWT groups are persisted to auto_groups regardless of whether the originating dashboard request is cancelled.

Are you using NetBird Cloud?

No — self-hosted.

NetBird version

management v0.73.2 (also reproduces on current main), PostgreSQL store.

Notes

Claim extraction itself works (ToGroups returns the groups); the failure is purely the cancelled write. A fix (detaching the sync write from request cancellation) is in the PR linked below.

Originally created by @den-dw on GitHub (Jun 30, 2026). Original GitHub issue: https://github.com/netbirdio/netbird/issues/6620 ### Describe the problem With JWT group sync enabled, a user's JWT-derived groups (`users.auto_groups`) are never persisted. The dashboard shows no groups for the user, and the management log repeats, on essentially every dashboard request: ``` management/server/http/middleware/auth_middleware.go:157: HTTP server failed to sync user JWT groups: context canceled ``` while `users.auto_groups` stays `[]`. ### Root cause `checkJWTFromRequest` (`management/server/http/middleware/auth_middleware.go`) calls `syncUserJWTGroups(ctx, userAuth)` with `ctx = r.Context()` — the HTTP **request** context. `SyncUserJWTGroups` persists the groups in a DB transaction bound to that context (`ExecuteInTransaction`). The dashboard SPA routinely aborts in-flight `fetch()` calls on re-render/navigation, which cancels the request context mid-write; the transaction is rolled back and the groups never persist. The error is logged but swallowed (no `return`), so it repeats silently. This is distinct from #2696 (the older lock/deadlock that hung the dashboard, fixed in v0.31.0) — here the dashboard is responsive, the write is simply rolled back. ### Steps to reproduce 1. Self-host `management` with an external IdP that emits a flat `groups` claim (e.g. Keycloak). 2. Enable JWT group sync (Settings → Groups), claim name `groups`. 3. Log into the dashboard as a user whose token carries `"groups": ["..."]`. 4. Observe `users.auto_groups` stays `[]` and the log repeats `failed to sync user JWT groups: context canceled`. ### Expected behaviour The user's JWT groups are persisted to `auto_groups` regardless of whether the originating dashboard request is cancelled. ### Are you using NetBird Cloud? No — self-hosted. ### NetBird version management v0.73.2 (also reproduces on current `main`), PostgreSQL store. ### Notes Claim extraction itself works (`ToGroups` returns the groups); the failure is purely the cancelled write. A fix (detaching the sync write from request cancellation) is in the PR linked below.
Author
Owner

@linear-code[bot] commented on GitHub (Jun 30, 2026):

NET-1335

<!-- gh-comment-id:4844840026 --> @linear-code[bot] commented on GitHub (Jun 30, 2026): <!-- linear-linkback --> <p><a href="https://linear.app/netbird/issue/NET-1335">NET-1335</a></p>
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#11609