Disabling an account at Keycloak revokes nothing inside an app, and SHC has no seam that could tell it to
Status: the mechanism is settled and measured; the fix is a job an operator runs, because the lifecycle event the real fix needs does not exist yet. The seam that must exist first is named in §5, with the owner decision it needs.
1. The defect, measured
Section titled “1. The defect, measured”Read-only, bitspur estate, 2026-08-18, against oc_authtoken in
corp_prod_nc_db-postgres-1 and user_entity in master_default_postgres-postgres-1:
| fact | value |
|---|---|
token rows in oc_authtoken | 112 on 23 uids |
of which permanent app passwords (type=1) | 68 |
of which sessions (type=0) | 44 |
accounts DISABLED in Keycloak realm corp | 19 of 47 |
| disabled accounts still holding live Nextcloud credentials | 9 |
| live permanent app passwords owned by those 9 | 23 |
newest last_activity on one of those 23 | 2026-07-28 |
oldest of those 23, by last_activity | 2025-08-22 |
Nextcloud core/enabled preference on those 9 accounts | unset on all nine; Nextcloud believes they are enabled |
Every one of the 23 token-holding uids is keycloak-<sub> shaped (user_oidc with
provider-1-providerBasedId=1), so this is the SSO-provisioned population, not
a pocket of legacy local accounts.
Nine offboarded people, 23 credentials, one of them exercised three weeks ago.
2. Why the disable does nothing: the mechanism, exactly
Section titled “2. Why the disable does nothing: the mechanism, exactly”A Nextcloud app password does not go near Keycloak. It is a row in
oc_authtoken; the client presents it as the password half of HTTP Basic against
WebDAV / CalDAV / CardDAV / OCS, and Nextcloud checks it locally. Disabling the
account at the IdP blocks the authorisation-code flow (new SSO logins) and
nothing else. That is Nextcloud’s design, not a bug in it.
Nextcloud does have a self-invalidation path, and it is keyed on the wrong
flag. In lib/private/User/Session.php at the pinned nextcloud:34.0.2-apache
(read verbatim off the running container):
:705:if ($lastCheck > ($now - 60 * 5)); the credential is re-checked at most once every five minutes; inside that window nothing is evaluated at all.:718and:727:if (!is_null($this->activeUser) && !$this->activeUser->isEnabled()) { $this->tokenProvider->invalidateToken($token); }
So invalidation fires only when the Nextcloud account is disabled, lazily, on
the token’s next use. A Keycloak-side disable flips no Nextcloud flag: measured
above, all nine holders carry no core/enabled preference at all, so
isEnabled() answers true and that branch never runs. The tokens live forever.
There is no HTTP path to another user’s tokens. provisioning_api’s
appinfo/routes.php at 34.0.2 exposes PUT /cloud/users/{userId}/disable and
/enable and nothing token-shaped (the only token routes are mail
verification). No broker credential, however privileged, can delete someone
else’s app password over the API. The only real delete is
occ user:auth-tokens:delete <uid> <id>; core/Command/User/AuthTokens/
contains exactly Add.php, Delete.php, ListCommand.php, which is CLI,
inside the container.
3. Where SHC is in the loop today: nowhere
Section titled “3. Where SHC is in the loop today: nowhere”There is no disable path to hook. Searched both repos:
shc useriscreate | ls | grant | revoke | reset-password | logout | rm(ce/modules/user/commands/).revokerevokes a ROLE. There is nodisableverb, andce/modules/user/service.gonever writes Keycloak’senabledfield; it only reads it as a display column inshc user ls(ce/modules/user/commands/list.go:59).- So an operator disabling an account does it in the Keycloak admin console or
kcadm, out of band. SHC is not told, and has nothing to be told. shc user logout(ce/modules/user/service.go:577) is the closest verb, and its own help calls it “the revocation verb”. Its blast radius is Keycloak sessions plus SHC’s own issued bearers:s.kc.LogoutUser, one call. It does not reach into any app’s local credential store, and today it does not say so. Its Long text already sends the operator onward with “To stop them logging back in, disable or remove the account”, pointing at a thing SHC does not do.- The one place SHC is in-process at Keycloak is the event-listener SPI,
keycloak/spi/.../events/ShcEventListenerProvider.java. It receives every admin event, which includes a user disable. But it deliberately ignores user events, its only consumer isFederationGuard(identity-provider / user-federation policy), and (decisive) it has no outbound channel to the daemon at all. Everything it does happens inside the Keycloak session.
That is the finding: the platform has no user-disable lifecycle event, and no component that would receive one.
4. What was built instead, and why it is a job and not a cron
Section titled “4. What was built instead, and why it is a job and not a cron”apps/flagship/nextcloud/revoke-user-tokens.job.yaml: context: service,
user: www-data, run per offboarded user:
shc job run revoke-user-tokens -s <stack> --var user=<nextcloud-uid> -wIt packages the only real reach (occ user:auth-tokens:delete) behind three
properties the shipped socket teardown already established as house shape:
- The uid crosses as process env, never as shell source.
REVOKE_UID: "{{ user }}"inenvironment:; thecommand:contains no template at all. An operator-typed uid stays data. (ce/modules/job/util.go:35puts every--varat the top of the render scope;ce/modules/job/context_service.go:57renders env values into-epairs.) - Refuse before delete. Empty uid → exit 1 with no
phpcall. Unknown account →occ user:infofails, exit 1, no delete is reached. Answering “revoked” for a typo tells an operator access is gone and stops them looking for the account that actually holds it, the same 404-not-success contractLogoutSessionsstates ince/modules/user/service.go. - The read-back is the claim. After the delete loop it re-lists; a single survivor fails the job rather than being reported as a revocation. Sessions are deleted alongside app passwords; a revocation that leaves the browser sessions alive is half a verb.
NOTHING SCHEDULES IT, on purpose. A cron that walks Keycloak for
enabled=false and reconciles every app would be a poller wearing a lifecycle
event’s clothes: it would run continuously against every stack to catch an event
that happens a handful of times a year, it would have to guess each app’s uid
mapping, and its failures would land where nobody looks. The honest shape is an
operator verb now and a real event later.
5. ★ The seam that must exist first: owner decision needed
Section titled “5. ★ The seam that must exist first: owner decision needed”Wiring revocation into “the disable path” is impossible today because there is no disable path. Two candidate seams, in preference order:
(a) shc user disable / shc user enable: SHC becomes the actor.
ce/modules/user/service.go already owns create / delete / grant / revoke /
reset-password / logout against Keycloak with tenant resolution and permission
gating; a disable is one more kcadm-shaped write to the same client, and it
gives the platform a point in its own code where “this account is being taken
away” is known. Token revocation then fans out from there. Cost: one verb, one
route, one CLI command, tests. Consequence to accept: it only fires for
disables done through SHC. An operator who disables in the Keycloak console
still bypasses it, the same gap every other realm edit already has.
(b) The SPI grows an outbound notification.
ShcEventListenerProvider already sees the admin event for a console-side
disable. Catching every disable requires giving it a credential, a retry
story, and an at-least-once contract to the daemon, a new outbound dependency
in the authentication hot path’s process, which is exactly what its class doc
says it was designed to avoid. Strictly more expensive, and strictly more
dangerous, than (a).
And the third question, which (a) and (b) both raise and neither answers: what is the fan-out? Nextcloud is one app of ~88. Any app holding app-local credentials (Nextcloud app passwords, GitLab PATs, Gitea tokens, Matrix access tokens…) has the identical defect. Two shapes:
- a per-app declared revocation job the platform calls by convention (this job is the first instance, and the convention would be its name), or
- a socket verb apps opt into, which is heavier but typed.
Until that is ruled, one honest job beats a framework nobody asked for.
6. Owed, small, and not done here
Section titled “6. Owed, small, and not done here”shc user logout should say what it does not reach. Its help calls it “the
revocation verb”; an operator offboarding someone reads that and stops. One
paragraph naming app-local credentials (and pointing at
shc job run revoke-user-tokens) costs nothing and closes the honesty gap
today, before any of §5 is built. Left out of this change deliberately: it is a
ce edit and belongs in its own MR.
The nine accounts measured in §1 are still live. This lane took no estate writes. Running the job against them is an operator act on a production estate and is not this MR’s to perform.