Skip to content

fix(security): enforce the managed store's disabled flag and admin role (#2345) - #2393

Merged
juanresendiz813 merged 4 commits into
developmentfrom
fix/2345-revoke-disabled
Nov 18, 2026
Merged

juanresendiz813 merged 4 commits into
developmentfrom
fix/2345-revoke-disabled

Conversation

@buggtb

@buggtb buggtb commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Disabling a user (SCIM active:false/DELETE, admin console) or removing their admin role now takes effect on the next login and request, for accounts that exist in both stores. This is the bounded fix; the single-user-store redesign in the issue is not attempted (see Decisions).

Root cause

The admin console and SCIM write the H2 USERS/USER_ROLES tables; the only AuthenticationProvider reads users.properties, and authorities come from that Authentication. So disable/demote returned 200 and changed nothing. Separately JdbcUserDAO.updateUser passes enabled = TRUE to the legacy UPDATE, so an admin role/email edit silently reactivated a deactivated account (which would have defeated this fix).

Fix

  • UserService.accountStatus(username) returns (managed row?, enabled, roles); unknown user or lookup error is unmanaged (the authenticator's answer stands).
  • AccountStatusPolicy: disabled row denies; a row without any admin role strips the admin authorities. Only credential logins (UsernamePasswordAuthenticationToken: form and Basic) are considered, so share/embed/OAuth principals are untouched. Lookups cached ~2 s.
  • AccountStatusPolicy is the SessionService authorisation predicate, so a disabled account is refused at form login.
  • AccountStatusFilter (before FILTER_SECURITY_INTERCEPTOR, main chain and /xmla/**): disabled gets 401 ACCOUNT_DISABLED, the HTTP session is ended and the cached Saiku session dropped (SessionService.logout); demoted continues without admin and the cached session roles are refreshed.
  • JdbcUserDAO.updateUser carries the current enabled flag instead of TRUE.
  • Docs: new section in docs/operator-hardening.md.

Decisions / not done (maintainer)

  • Delete is not revoked. DELETE /rest/saiku/admin/users/{id} removes the row, which is indistinguishable from "never managed", so the user can still log in via users.properties. Fixing it needs a tombstone or the issue's H2-backed UserDetailsService (single store), which is an architecture decision; documented instead. The destructive home-folder delete on that route is also untouched.
  • Accounts present only in users.properties (or an external provider) stay governed by the authenticator.
  • Passwords remain the authenticator's (the Admin panel reports success rotating the admin password but silently does nothing — old credential stays live #1514 501 refusal stands).
  • The filter is a sibling of the form-login check; I did not wire a Spring SessionRegistry.

Overlap: #2338, #2339 and #2341 are separate PRs on the same login/session code, each based on development; this one adds SessionService.onDisabled/onDemoted and changes the authorisationPredicate bean wiring.

Test plan

  • acceptance/2345/spec.json (command spec, node check.mjs, pins the wiring on both chains, the predicate and the DAO) as the first commit; red on base locally, green on head. Behaviour is proven by the unit tests below; the launcher was not run end to end (it could not be built offline here).
  • mvn -pl saiku-core/saiku-web -am test -Dtest='UserServiceAccountStatusTest,JdbcUserDAOEnabledTest,AccountStatus*Test,UserServiceTest,SessionService*Test,SessionResourceTest,ScimServiceTest' green (policy, filter, store lookup, real-H2 DAO test that a role edit does not re-enable)
  • spotless:check on saiku-service and saiku-web
  • Spring wiring (circular userService/sessionService, setter-injected policy, filter on both chains) is only exercised by CI's launcher build; please watch the acceptance job.

Closes #2345

🤖 Generated with Claude Code

buggtb and others added 2 commits November 12, 2026 17:20
…#2345)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…le (#2345)

Disabling a user via SCIM or the admin console, or removing ROLE_ADMIN from
their H2 row, changed nothing: login and authorities come from users.properties.

For accounts present in both stores, AccountStatusPolicy now refuses form login
for a disabled row and AccountStatusFilter (main chain and /xmla/**) answers 401
and ends the session on the next request, or strips the removed admin authority
and refreshes the cached session roles. JdbcUserDAO.updateUser no longer forces
enabled = TRUE, so a role edit cannot reactivate a deactivated account. Accounts
with no row, and share/embed/OAuth principals, are untouched.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@buggtb buggtb added the security Created by Hive for agent-filed issue provenance label Nov 12, 2026
@github-actions github-actions Bot added risk/high Change risk tier: high (see docs/risk-tiers.md) area/service area/web docs labels Nov 12, 2026
@github-actions

Copy link
Copy Markdown

Semantic model diff

Semantic model diff

No model changes and no broken references.

Semantic model diff

No model changes and no broken references.

saiku#1434 · reproduce locally with saiku model diff

@juanresendiz813 juanresendiz813 left a comment

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.

The subtract-only policy and the filter placement are right, but the check fails open for a common row shape and on any lookup error, so it doesn't yet deliver the property #2345 asks for.

Blocking

  1. blocking · Correctness / Security · saiku-core/saiku-service/src/main/java/org/saiku/service/user/UserService.java:148 and :151-155
    The role set is built with Set.of(roles), which throws on a duplicate. The catch turns that into AccountStatus.UNMANAGED, which AccountStatusPolicy.java:85-87 reads as "leave the authenticator's answer alone". Duplicates are the normal case: JdbcUserDAO.insert always prepends ROLE_USER (JdbcUserDAO.java:67-71), and both the admin console's new-user form (UsersAdmin.svelte:33, default ['ROLE_USER']) and SCIM create (ScimService.java:137-138) already send it, so the row ends up ROLE_USER,ROLE_USER.
    Repro: create a user through JdbcUserDAO.insert with {"ROLE_USER"} against in-memory H2 with the shipped SQL, set enabled=0, and policy.evaluate() still allows it (the form-login predicate is true). Same for a console-created admin with ROLE_ADMIN removed: still allowed with ROLE_ADMIN. The seeded admin/smith rows behave correctly, which is why the current tests pass. That's the issue's own scenario (a leaver deactivated through SCIM).
    Would accept: build the set tolerantly (de-duplicate, skip null/blank) and never let a role-parsing problem discard the enabled flag of a row that was found; plus a regression test that creates the user via JdbcUserDAO.insert/UserService.addUser with {"ROLE_USER"}, disables it, and asserts the policy denies. JdbcUserDAOEnabledTest.java:68-69 already creates exactly that row. Ideally also the launcher IT the issue names (UserWorkflowIT.scimDeactivate_revokesLogin).

  2. blocking · Correctness (error handling) / Security · UserService.java:151-155, AccountStatusPolicy.java:47
    Any exception reading the store means "unmanaged", i.e. allow, the exception is dropped from the log, and the answer is cached for 2 s (AccountStatusPolicy.java:131-132). An unwired policy also allows everything. The rubric asks for fail-closed, and the two existing readers of the same table (UserService.isEnabled, UserServiceOwnerIdentityResolver.resolve) do fail closed. This is what turned item 1 into a silent bypass instead of a loud failure.
    Would accept: at minimum, log the exception and never treat "row found but unreadable" as "no row". The "store unreachable" half is a policy decision (question 2 below).

Non-blocking

  • non-blocking · Compatibility · no way to re-enable a row from the admin console any more (no control in AdminResource or the UI); only SCIM active:true can. Document it or add the control.
  • non-blocking · Correctness · role replacement is delete-then-insert without a transaction (JdbcUserDAO.java:83-96). A lookup landing in between sees no ROLE_ADMIN, and AccountStatusFilter.java:61 writes the reduced authentication into the session, so the session stays demoted until re-login. Make the rewrite atomic, or replace the context per request only.
  • non-blocking · Security · no audit event when the filter refuses or demotes (AccountStatusFilter.java:52-63); a deactivated user with the right password over Basic is logged as loginSuccess and then refused silently.
  • non-blocking · Tests · the real SessionService hooks aren't exercised (the filter test counts stub calls); JdbcUserDAOEnabledTest.java:127 uses assumeTrue so it can skip instead of fail; AccountStatusPolicyTest.java:94-109 relies on a 25 ms wall-clock window (inject a clock).
  • non-blocking · Performance · each lookup opens a JDBC connection and reads every user (UserService.java:145); a keyed query would do.
  • non-blocking · Security · case-variant rows: the first case-insensitive match wins (UserService.java:145-149). Deny if any match is disabled.
  • non-blocking · saiku-beans.xml:65: authorisationPredicate is now unreferenced. AccountStatusPolicy.java:126: prefer System.nanoTime() for the TTL.
  • praise · the policy can only subtract authority, and the updateUser re-enable bug is fixed with a real-H2 test.

Questions for you

  1. question · Should this close #2345? Several acceptance criteria are explicitly not attempted (delete/rename of a row still doesn't revoke, password change still 501, no migration). Deleting or renaming a deactivated row re-opens that login, which deserves a docs line. Refs #2345 plus a follow-up issue would be more accurate.
  2. question · Store-error policy when the user store is unreachable: fail closed (store outage becomes login outage), last-known-good per user, or fail open with explicit sign-off, an ERROR log and a docs line?
  3. question · Scope: only the admin role is reconciled (AccountStatusPolicy.java:91-106) and only UsernamePasswordAuthenticationToken is checked (:81), so removing ROLE_SQL_EXEC or a data role changes nothing, and OAuth bearer / SSO logins are exempt. Intended? If so, docs/operator-hardening.md:140-157 should say so.
  4. question · Upgrade: once item 1 is fixed, a users.properties admin whose H2 row lacks ROLE_ADMIN loses admin on upgrade. Needs a release note and the recovery step in the docs.

🤖 Generated with Claude Code

@juanresendiz813 juanresendiz813 left a comment

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.

Approving. The points from my review are now tracked separately in #2431 (status check fails open on duplicate rows / lookup errors) and #2432 (re-enable, atomic role rewrite, audit, docs). Before it can merge it needs a rebase on development; keep both sections in docs/operator-hardening.md.

🤖 Generated with Claude Code

Conflict in docs/operator-hardening.md: development appended the
pass-through credentials section (#2341) at the same spot. Kept both
sections, development's first, separated by horizontal rules.

Signed-off-by: Juan Resendiz <50384386+juanresendiz813@users.noreply.github.com>
Resolve docs/operator-hardening.md: keep both sections, development's
reverse-proxy lockout section first.

Signed-off-by: Juan Resendiz <50384386+juanresendiz813@users.noreply.github.com>
@juanresendiz813
juanresendiz813 added this pull request to the merge queue Nov 18, 2026
Merged via the queue into development with commit 9d9c30e Nov 18, 2026
28 checks passed
@github-actions

Copy link
Copy Markdown

PR acceptance metric

Acceptance rate: 85.8% — 423 merged / 493 decided PRs (7 still open, excluded from the denominator).

Metric Value
Acceptance rate 85.8%
Accepted / rejected / open 423 / 70 / 7
Median time to first review (merged) 125.1 h
Median time to merge (merged) 13.9 h
Median time open (decided) 17.6 h
Mean review rounds on merged PRs 1.2
Authors with at least one merged PR 8
Author Merged Rejected Acceptance
buggtb 210 19 91.7%
app/dependabot 99 41 70.7%
juanresendiz813 94 1 98.9%
app/spicule-hive 8 1 88.9%
spicule-hive-bot 8 1 88.9%
oiacub1 2 0 100.0%
k-jm 1 3 25.0%
Prithvi1994 1 0 100.0%
laborima 0 3 0.0%
rezamuliawijaya 0 1 0.0%

Generated by scripts/pr-metrics.mjs — see docs/metrics.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/service area/web docs risk/high Change risk tier: high (see docs/risk-tiers.md) security Created by Hive for agent-filed issue provenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[security] Disabling or demoting a user in the admin UI / SCIM does not revoke login or ROLE_ADMIN

2 participants