Repository navigation
fix(security): enforce the managed store's disabled flag and admin role (#2345) - #2393
Conversation
…#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>
Semantic model diffSemantic model diffNo model changes and no broken references. Semantic model diffNo model changes and no broken references. saiku#1434 · reproduce locally with |
juanresendiz813
left a comment
There was a problem hiding this comment.
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
-
blocking· Correctness / Security ·saiku-core/saiku-service/src/main/java/org/saiku/service/user/UserService.java:148and:151-155
The role set is built withSet.of(roles), which throws on a duplicate. The catch turns that intoAccountStatus.UNMANAGED, whichAccountStatusPolicy.java:85-87reads as "leave the authenticator's answer alone". Duplicates are the normal case:JdbcUserDAO.insertalways prependsROLE_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 upROLE_USER,ROLE_USER.
Repro: create a user throughJdbcUserDAO.insertwith{"ROLE_USER"}against in-memory H2 with the shipped SQL, setenabled=0, andpolicy.evaluate()still allows it (the form-login predicate is true). Same for a console-created admin withROLE_ADMINremoved: still allowed withROLE_ADMIN. The seededadmin/smithrows 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 theenabledflag of a row that was found; plus a regression test that creates the user viaJdbcUserDAO.insert/UserService.addUserwith{"ROLE_USER"}, disables it, and asserts the policy denies.JdbcUserDAOEnabledTest.java:68-69already creates exactly that row. Ideally also the launcher IT the issue names (UserWorkflowIT.scimDeactivate_revokesLogin). -
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 inAdminResourceor the UI); only SCIMactive:truecan. 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 noROLE_ADMIN, andAccountStatusFilter.java:61writes 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 asloginSuccessand then refused silently.non-blocking· Tests · the realSessionServicehooks aren't exercised (the filter test counts stub calls);JdbcUserDAOEnabledTest.java:127usesassumeTrueso it can skip instead of fail;AccountStatusPolicyTest.java:94-109relies 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:authorisationPredicateis now unreferenced.AccountStatusPolicy.java:126: preferSystem.nanoTime()for the TTL.praise· the policy can only subtract authority, and theupdateUserre-enable bug is fixed with a real-H2 test.
Questions for you
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 #2345plus a follow-up issue would be more accurate.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?question· Scope: only the admin role is reconciled (AccountStatusPolicy.java:91-106) and onlyUsernamePasswordAuthenticationTokenis checked (:81), so removingROLE_SQL_EXECor a data role changes nothing, and OAuth bearer / SSO logins are exempt. Intended? If so,docs/operator-hardening.md:140-157should say so.question· Upgrade: once item 1 is fixed, ausers.propertiesadmin whose H2 row lacksROLE_ADMINloses admin on upgrade. Needs a release note and the recovery step in the docs.
🤖 Generated with Claude Code
juanresendiz813
left a comment
There was a problem hiding this comment.
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>
PR acceptance metricAcceptance rate: 85.8% — 423 merged / 493 decided PRs (7 still open, excluded from the denominator).
Generated by |
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_ROLEStables; the onlyAuthenticationProviderreadsusers.properties, and authorities come from thatAuthentication. So disable/demote returned 200 and changed nothing. SeparatelyJdbcUserDAO.updateUserpassesenabled = TRUEto 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.AccountStatusPolicyis theSessionServiceauthorisation predicate, so a disabled account is refused at form login.AccountStatusFilter(beforeFILTER_SECURITY_INTERCEPTOR, main chain and/xmla/**): disabled gets 401ACCOUNT_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.updateUsercarries the currentenabledflag instead of TRUE.docs/operator-hardening.md.Decisions / not done (maintainer)
DELETE /rest/saiku/admin/users/{id}removes the row, which is indistinguishable from "never managed", so the user can still log in viausers.properties. Fixing it needs a tombstone or the issue's H2-backedUserDetailsService(single store), which is an architecture decision; documented instead. The destructive home-folder delete on that route is also untouched.users.properties(or an external provider) stay governed by the authenticator.SessionRegistry.Overlap: #2338, #2339 and #2341 are separate PRs on the same login/session code, each based on development; this one adds
SessionService.onDisabled/onDemotedand changes theauthorisationPredicatebean 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:checkon saiku-service and saiku-webCloses #2345
🤖 Generated with Claude Code