Skip to content

fix(admin): keep users signed in when their access policy changes - #1780

Merged
Quick104 merged 7 commits into
Silo-Server:mainfrom
Rhainland:fix/issue-1404-policy-change-no-signout
Oct 2, 2026
Merged

Quick104 merged 7 commits into
Silo-Server:mainfrom
Rhainland:fix/issue-1404-policy-change-no-signout

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1404
Validation tasks: changes #1197 C1

Moving a user to another access group signs them out on every device, and so
does changing their permissions or playback-quality override. Deleting a group
signs out every member it moves to the default group. Editing a group's own
policy signs no one out, so the stricter rule falls on the narrower change. This
change keeps users signed in for these policy changes and tells connected
clients to refresh what they show.

Tokens never carried the policy. Each request resolves the current access group,
permissions and quality limits from the database, and these changes already bump
access_policy_revision, which invalidates profile PIN tokens and v2 list
cursors. The sign-out was not needed for enforcement. What was missing is a way
for a connected client to learn that its cached libraries and pages are out of
date: the events socket already closed when access changed, but without a reason,
so Web reconnected and kept its cache.

Approach

  • Account updates on v1 and v2 now sign the user out only for a password, an
    enabled change, or a role change. Role changes keep signing out until a
    follow-up makes them refresh the access token instead (step 4 of Apply access-group changes without signing users out #1404).
  • Group deletion still moves members to the default group and bumps their
    revision, in the same transaction, but no longer revokes their sessions. The
    store and handler drop the revocation hook they no longer need, and the unused
    AdminHandler.revokeUserSessions is removed.
  • The events socket's 15-second recheck now tells an access change apart from a
    dead session. When the role, effective role, scope fingerprint or profile
    verification changed under a valid session, the connection loop sends
    {"type":"access_changed"} and closes with code 4001, reason
    access_changed. The connection loop writes both frames, because it is the
    only data writer on the socket. A revoked or expired session and a disabled
    account close the socket as before. The playback-control and Watch Together
    sockets share the validator and keep closing without a frame.
  • Web handles the frame or the close code: it marks libraries, home, catalog and
    search results, item details, collections, calendar, requests and downloads
    stale, re-reads the signed-in account so permission-gated controls update, and
    reconnects without the usual backoff. A PIN profile whose token the change
    invalidated gets profile_verification_required on the next ticket mint or
    request and goes back to profile selection, as it already does.
  • The group delete confirmation no longer says members are signed out.
  • docs/realtime-api.md documents the frame, the close code and what clients
    should do; docs/admin-users-api.md lists which updates still sign users out.

Playback that already started keeps the limits in its stream token until the
next start, as it already does after a group edit. Jellyfin-compatible sessions
are no longer dropped for these changes; their library and quality filters are
resolved per request.

Android (Silo-Server/silo-android#440) and Apple (Silo-Server/silo-apple#571)
handle access_changed and profile_verification_required and pair with this
change. Both work against older servers, so merge order does not matter.

Validation

  • Go: focused tests for access, api/handlers, events and auth pass,
    including the DB-backed group store tests against a migrated Postgres. New
    tests cover v1 and v2 updates (no revocation for group, permission or quality
    changes; revocation for password, disable and role), group deletion keeping a
    member's session, validator classification, and a socket that receives the
    frame and close code 4001 on an access change but not on a revoked session.
  • internal/apiv2 and api/handlers each have one failure that also fails on
    main in the same environment (TestAdminResourceCapabilitiesAndScope,
    TestAdminSubtitleListPageDB).
  • make lint-changed: 0 issues. gofmt clean. make verify-local-paths passes.
  • Web: provider, invalidation, auth and access-group page tests pass; prettier
    clean; eslint adds no warnings. The full make test-web run fails only in
    AdminUserDetail.test.tsx, which fails the same way on main on a
    case-insensitive file system; tsc -b reports only the matching
    AdminUserDetail.tsx import error.
  • Not run: a manual check on a running server with a connected browser.

Risks

  • A user loses access granted by the old policy on their next request rather
    than at sign-out. Server enforcement already worked this way for group edits
    and per-user library changes.
  • A client that ignores the new frame and close code keeps its cached pages
    until it refetches, as Web did before this change. Android and Apple need the
    follow-ups above for the refresh.
  • Role changes still sign the user out; that stays until the follow-up lands.
  • The socket's scope fingerprint also covers profile preferences (metadata
    language, hidden libraries) and the server's unrated-content setting. Changing
    them already closed the socket; it now also makes Web refetch its
    access-dependent queries once. A preference read that fails and falls back
    to the defaults is not reported as a change: the recheck skips the comparison
    for that round, and the ticket mint refuses, as for any other failed read.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code
  • Tool(s): Claude Code, GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: a separate Claude Code agent (claude-opus-5-5) reviewed
    the branch diff for socket writer concurrency, goroutine leaks, validator
    classification for the other sockets that share it, callers that relied on
    the removed sign-out, Web reconnect loops, and whether the new tests fail on
    the old behavior. It found no defects. It noted that the scope fingerprint
    also covers profile preferences and the unrated-content setting, so those
    changes now send access_changed; the realtime docs say so. A second review
    of the finished branch found that a failed preference read, which falls back
    to defaults, changed the fingerprint and was reported as an access change, so
    a slow database would make every affected client refetch everything. Fixed:
    the resolved scope records the fallback, the recheck skips the comparison
    that round, and the ticket mint refuses; a test covers both.

Note

Keep users signed in across access-policy changes; signal events sockets with close code 4001

  • Admin account updates now revoke sessions only for password, enabled-state, or role changes; permissions, playback-quality, and access-group changes no longer sign users out (updateRequiresSessionRevocation in admin.go).
  • Deleting an access group moves members to the default group and bumps their access_policy_revision in one transaction without revoking their sessions (group_store.go, admin_access_group_service.go).
  • The v2 events socket periodically revalidates authority and sends an access_changed JSON frame plus websocket close code 4001 when role, scope fingerprint, or policy revision changes under a still-valid session (events_socket_v2.go).
  • The frontend handles the access_changed message or close code by invalidating access-dependent queries and calling the new refreshAccount on the auth context, which re-reads /api/v2/account/me without clearing the session or query cache (RealtimeEventsProvider.tsx, useAuth.tsx).
  • Failed viewer-preference reads now set Scope.PreferencesDegraded (excluded from the access fingerprint) so the socket does not treat degraded defaults as an access change (viewer_preferences.go).
  • Behavioral changes: memberMovingGroupStore.DeleteMovingMembers now returns only an error (moved user IDs and the in-transaction callback are removed), OnUserSessionsRevoked is no longer wired to the access-group handler, EventsSocketV2.Mint refuses tickets when preferences are degraded, and clients that ignore the 4001 signal simply reconnect and pick up the new policy on their next request.

Macroscope summarized b979d79.

Changing a user's access group, permissions or playback-quality override
no longer revokes their sign-ins. The change still bumps
access_policy_revision, and every request resolves the current policy.
Password, enabled and role changes still sign the user out, on the v1 and
v2 update paths alike.

Also removes the unused AdminHandler.revokeUserSessions.

Refs Silo-Server#1404
Deleting an access group still moves its members into the default group
and bumps their access_policy_revision in the same transaction, but no
longer signs them out. DeleteMovingMembers drops its in-transaction
callback and the handler drops its session hook, since nothing else
used them.

Refs Silo-Server#1404
When the events socket's periodic recheck finds that the account role,
effective role, scope fingerprint or profile verification changed under a
still-valid login session, the connection loop now sends
{"type":"access_changed"} and closes with code 4001, reason
access_changed, instead of dropping the connection. A revoked or expired
session and a disabled account still close the socket as before.

The validator reports these cases with errSocketAccessChanged, which
wraps evt.ErrSocketTicket, so the playback-control, watch-together, admin
logs and Apple push callers keep their behavior.

Refs Silo-Server#1404
When the events socket sends access_changed or closes with code 4001,
the web app marks libraries, home, catalog and search results, item
details, collections, calendar, requests and downloads stale, re-reads
the signed-in account so permission-gated controls follow the new
policy, and reconnects without the usual one-second backoff.

Refs Silo-Server#1404
The delete confirmation now says members move to the default group and
get its access right away without being signed out, matching the server.

Refs Silo-Server#1404
realtime-api.md documents the access_changed frame, close code 4001 and
what clients do with them. admin-users-api.md lists which account
updates still sign the user out and says group deletion keeps members
signed in.

Refs Silo-Server#1404
When a profile's viewer preferences cannot be read, the resolver falls back
to their defaults. The scope fingerprint then differs from the ticket's, and
the events socket told the client its access changed, making every affected
client refetch everything while the database was already slow.

The resolved scope now records the fallback. The periodic check skips the
fingerprint comparison for that round, and the ticket mint refuses to fingerprint
fallback preferences, as for any other failed read.
@kody-ai

kody-ai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the `@kody start-review` command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Providing Context (Files & MCPs)

Add these hints in your PR description (or a comment) to unlock deeper checks:

  • Ticket / Acceptance Criteria: `Refs: ABC-123` (Linear/Jira/Asana/ClickUp/Trello) or a direct ticket link.
  • Bugfix Validation: a Sentry/Datadog/Bugsnag event link (or paste the stack trace/error message).
  • Endpoint Risk: mention the route (e.g., `POST /api/payments`) or controller/action name.
  • Attach a repo file as context: use an explicit marker like `@file:docs/guide.mdx#L10-L50` (replace with your real path).
  • API Contract Docs: include `@file:openapi.yaml` or `@file:swagger.json` when changing routes/schemas.
  • Definition of Done / Standards: include `@file:DOD.md` or `@file:CONTRIBUTING.md` if your repo has them.
  • Design System Source of Truth: include `@file:ui/index.ts` (replace with your DS entrypoint path).
  • Feature Flags: include the flag key/name and `@file:flags.ts` / `@file:config.json` (and optionally the PostHog flag name).
  • Edge/CDN Rules: link the Cloudflare rule/zone or describe the intended redirect/header behavior.
  • Attach an MCP tool output: use `@mcp<provider|tool>` (replace with an installed MCP provider + tool, e.g., `@mcp<sentry|events.search>`).
Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Access your configuration settings here.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 49 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: c2a596a3-0f0d-4902-881d-1692adf1c11c

📥 Commits

Reviewing files that changed from the base of the PR and between 8846872 and b979d79.

📒 Files selected for processing (29)
  • docs/admin-users-api.md
  • docs/realtime-api.md
  • internal/access/group_store.go
  • internal/access/group_store_test.go
  • internal/access/resolver.go
  • internal/access/types.go
  • internal/access/viewer_preferences.go
  • internal/api/handlers/access_groups.go
  • internal/api/handlers/admin.go
  • internal/api/handlers/admin_access_group_delete_test.go
  • internal/api/handlers/admin_access_group_service.go
  • internal/api/handlers/admin_scoped_api_key_test.go
  • internal/api/handlers/admin_session_revocation_test.go
  • internal/api/handlers/admin_test.go
  • internal/api/handlers/events_socket_v2.go
  • internal/api/handlers/events_socket_v2_test.go
  • internal/api/handlers/events_ws.go
  • internal/api/router.go
  • internal/events/types.go
  • internal/policy/viewer_resolver.go
  • web/src/api/types.ts
  • web/src/components/RealtimeEventsProvider.test.tsx
  • web/src/components/RealtimeEventsProvider.tsx
  • web/src/components/realtimeCatalogInvalidation.test.ts
  • web/src/components/realtimeCatalogInvalidation.ts
  • web/src/hooks/AuthProvider.test.tsx
  • web/src/hooks/useAuth.tsx
  • web/src/pages/AdminAccessGroups.test.tsx
  • web/src/pages/AdminAccessGroups.tsx
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment on lines +300 to +303
// Preferences that fell back to their defaults say nothing about
// whether access changed, so this round skips the comparison.
if identity.AccessFingerprint != "" && !scope.PreferencesDegraded && identity.AccessFingerprint != eventsScopeFingerprint(scope) {
return ctx, nil, errSocketAccessChanged

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug high

Access-change detection fails during degraded preference reads because validation skips the entire access fingerprint comparison, including successfully resolved policy revisions, library restrictions, and playback limits. If an unprotected profile's policy changes during a preference-read failure, validation succeeds without an access_changed signal, leaving the client with stale access-dependent data until a later successful preference read.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accurate, but the effect is a delay, not a missed change. A degraded round skips the comparison, but the ticket fingerprint stays fixed, so the next successful round (15 s later) still sees the difference and sends access_changed. Degraded only comes from a failed settings-store read, and the server resolves access per request regardless, so nothing is granted during the gap; only the client's notice is late. Not blocking. A follow-up could keep a second fingerprint over the preference-independent fields (libraries before the hidden-library subtraction, maturity, quality, bitrate, revision) and compare that on degraded rounds.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed—the finding describes a delayed client notification, not a permanently missed change or an enforcement gap. The ticket fingerprint stays fixed, so the first successful recheck detects the difference and sends access_changed. That may be the next 15-second recheck, or later if preference reads keep failing.

Given that access is enforced per request, the high-severity classification overstates the impact. I would treat this as a non-blocking resilience improvement.

A separate preference-independent fingerprint is a sensible follow-up: compare libraries before hidden-library filtering, maturity, quality, bitrate, and policy revision even during degraded reads, while leaving preference-sensitive comparisons deferred. No changes made.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a defect, so no change. Skipping the comparison delays the signal by at most one recheck; it doesn't lose it. access_policy_revision and the library and quality limits live on the user and group rows, so the next recheck with a successful preference read still sees a different fingerprint and sends access_changed. Enforcement doesn't wait for the socket either, because every request resolves the current policy. Mint also refuses a ticket while preferences are degraded, so a socket can't open in that state. If the preference read keeps failing, the client loses the refresh hint, but it already has other trouble and its requests still enforce the new policy.

Comparing only the non-preference parts would mean storing a second fingerprint in every ticket, which costs more than one 15-second delay during a database fault.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed—the high-severity finding is not justified, and no code change is needed. The fixed ticket fingerprint preserves detection for the next successful preference read, while per-request policy resolution preserves enforcement. Refusing ticket minting during degraded reads also prevents a new socket from starting with a fallback fingerprint.

One qualification: “at most one recheck” assumes the next preference read succeeds. Consecutive failures can delay the notification longer, but they do not bypass access enforcement. A second fingerprint is unnecessary complexity for this non-blocking notification delay.

@Quick104

Quick104 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: b979d79a. I found no defects and pushed no changes.

What I checked

  • The sign-out rule on v1 and v2 updates: only a password, enabled, or role change still revokes. Group, permission, and quality changes now rely on the access_policy_revision bump. That revision is in the socket fingerprint, so the next recheck catches the change.
  • The socket path: the connection loop stays the only data writer. The recheck goroutine closes accessChanged and cancels only if the loop doesn't finish within the grace period, and the deferred cancel stops it. Mint and the recheck use the same validator, so their fingerprints agree and a socket can't loop on access_changed.
  • Jellyfin-compatible sessions resolve library and quality scope per request (NewScopeAccessFilter → access.Resolver, uncached), so they pick up the new policy without the dropped revocation.
  • The Kody finding about degraded preference reads delays the signal by one recheck and doesn't lose it. I replied in the thread.

Verification

  • Go: access, events, auth, policy, jellycompat, api, and apiv2 pass. TestEventsSocketV2* passes 30 times under -race. In api/handlers, only TestAdminSubtitleListPageDB and TestCatalogTransferPersistsJobsAndSignedLink fail, and they fail the same way on main against the same test database.
  • Web: the four touched test files (64 tests) pass, and tsc -b and prettier are clean.
  • The branch merged onto current main builds, and the same focused tests pass.
  • Sandbox built from this head, using a Go client with an open events socket:
    • Group move, permission change, and v2 group delete each sent access_changed and close 4001. The same access token kept working, and user/libraries followed the new group.
    • A password change closed the socket with no frame and returned 401, as before.
  • Sandbox, Web signed in as a regular user: after an admin moved the user to a one-library group, the other library left the sidebar and the home rows 8–12 seconds later, with no reload and no sign-out.

Validated features

  • User management / access groups / invites — Web admin #1197 C1 (Web admin: create accounts and groups, configure policies and an account override): the criterion still holds. The behavior changes deliberately: group, permission, and quality changes no longer sign the user out, and the group delete confirmation copy changed. A maintainer should hand C1 to the validator for a re-test on the build that includes this.

Follow-ups

  • silo-android#440 and silo-apple#571 handle the new signal and work against older servers, so merge order doesn't matter.
  • Steps 3 and 4 of Apply access-group changes without signing users out #1404 (a fallback for clients without the socket, and role changes that refresh the token) stay open, so Related issue: #1404 is correct as written.

Mergeability: 9/10, ready. The rationale holds: tokens never carried policy, and every request resolves it. The change is bounded, tested at unit and live level, and required checks are green.

Evidence: https://evidence.siloserver.org/r/silo-server/pr-1780/

AI-assisted review: Claude Code (claude-opus-5-5) with GitHub CLI.

@Quick104
Quick104 merged commit 4cb2da6 into Silo-Server:main Oct 2, 2026
21 checks passed
Quick104 added a commit to Rhainland/silo-server that referenced this pull request Oct 2, 2026
Silo-Server#1780 was squash-merged, and this branch edits lines its commits added,
so a plain merge conflicts. The tree is this branch's own commits
(b979d79..388816e) replayed onto main without conflicts.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.

2 participants