When someone leaves KIMS or should lose CMS access, it must end in the CMS too, not only in Keycloak. The CMS is built so that every route to revoking a person works, and quickly.
Who does what: KIMS's Keycloak admin disables accounts and removes roles; a CMS Admin suspends people on the People screen; our engineer tests that both work, including the network path from Keycloak to the CMS.
#How the CMS keeps checking
Every CMS request (every click, every screen) checks with Keycloak before doing anything (apps/cms/src/lib/auth/gate.ts):
- While the person's 5 minute access token is still valid, the CMS introspects their refresh token at Keycloak. Introspection answers "not active" for a disabled user or an ended session, and returns the current roles.
- After it expires, the CMS refreshes. Keycloak refuses for a disabled user or ended session; a new access token without
cms-accessis refused by the CMS. - Then it reads the person's row on the People screen: deleted or suspended means out.
Any refusal deletes the CMS session and sends the person to sign in. If Keycloak cannot be reached at all, nothing is deleted and the person sees "Could not confirm your access, so nothing was done", rather than being signed out by an outage.
On top of that, Keycloak tells the CMS directly when a session ends, through back-channel logout.
#Every way to revoke, and when it takes effect
| Action | Done by | Where | Takes effect |
|---|---|---|---|
| Sign the person out in Keycloak | KIMS's Keycloak admin | Users, the person, Sessions tab, Sign out (on a session), or Sessions (left menu) | At once: Keycloak calls the CMS's back-channel logout URL and the CMS deletes their sessions. If that call cannot get through, on their next click (introspection says the session is gone) |
| Disable the account | KIMS's Keycloak admin | Users, the person, Details, Enabled off, Save | On their next click (introspection says not active) |
Remove cms-access (or remove them from the group that grants it) |
KIMS's Keycloak admin | Role mapping tab, tick cms-access, Unassign; or Groups tab, Leave |
On their next click (introspection returns their current roles) |
| Delete the account | KIMS's Keycloak admin | Users, the person, Action, Delete | On their next click |
| Suspend on the People screen | A CMS Admin | CMS, People | On their next click |
| Change their CMS roles | A CMS Admin | CMS, People | On their next click |
The repository's own notes promise "seconds; at most 5 minutes". In the code as it stands, each check runs on every request, so the change applies at the person's next click. The 5 minute figure is the outer bound if introspection were ever unavailable.
Disabling or deleting someone only in the CMS (suspending them) does not touch their KIMS account or their other applications. Leavers are KIMS's process: disable them in Keycloak.
Sessions (left menu), Action, Sign out all active sessions signs out every user of every application in the realm, not just the CMS. Use the per-user Sessions tab for one person.
#How back-channel logout works
When a Keycloak session ends (admin sign-out, the person signs out of another KIMS application that shares the session, session expiry handled by Keycloak), Keycloak sends, server to server:
POST https://<CMS_HOST>/api/auth/backchannel-logout
Content-Type: application/x-www-form-urlencoded
logout_token=<a signed JWT>The CMS (apps/cms/src/app/api/auth/backchannel-logout/route.ts):
- Verifies the token: RS256 signature with the realm's keys,
iss=KEYCLOAK_ISSUER,aud= the client ID,iatandjtipresent, not older than 10 minutes, the back-channel logouteventsclaim present, nononce. - Deletes every CMS session with that Keycloak session id (
sid), or, if the token names only the person (sub), every CMS session of that person. - Answers
200(an empty body). A bad or missing token gets400with{"error":"invalid_request"}and a log line[cms] back-channel logout refused: <reason>.
There is no cookie and no CSRF token on this route: the signed token is the only credential. Settings it depends on are on Client: Logout settings.
#Test the back-channel path
The back-channel call comes from Keycloak's servers, not from your laptop. A firewall or a VPN-only CMS can block it while the CMS works fine for people. Test from a Keycloak host.
Who does this: KIMS's Keycloak admin runs it on a Keycloak server (it is Linux in almost every installation); our engineer reads the result.
curl -s -i -X POST https://<CMS_HOST>/api/auth/backchannel-logout -d 'logout_token=test' | head -1You should see HTTP/1.1 400 Bad Request (or HTTP/2 400). That is the CMS refusing a fake token, which proves the path is open and the route answers. A timeout, Could not resolve host, or an HTML page from a proxy means Keycloak cannot reach the CMS.
If KIMS's Keycloak runs on Windows servers, the same in PowerShell:
curl.exe -s -i -X POST "https://<CMS_HOST>/api/auth/backchannel-logout" -d "logout_token=test" | Select-Object -First 1The same check from your own machine shows the route answers from where you are (not from Keycloak):
curl -s -o /dev/null -w "%{http_code}\n" -X POST https://<CMS_HOST>/api/auth/backchannel-logout -d 'logout_token=test'curl -s -o /dev/null -w "%{http_code}\n" -X POST https://<CMS_HOST>/api/auth/backchannel-logout -d 'logout_token=test'curl.exe -s -o NUL -w "%{http_code}\n" -X POST "https://<CMS_HOST>/api/auth/backchannel-logout" -d "logout_token=test"You should see 400. In the CMS log there is a matching [cms] back-channel logout refused line (Troubleshooting).
#If Keycloak cannot reach the CMS
Revocation still works: sign-outs, disabled accounts and removed roles are all caught on the person's next click by introspection. What is lost is the CMS deleting the session at the moment of the sign-out, so an open tab that is not clicked keeps its (useless) session row until it is. KIMS can add a route from Keycloak to the CMS's load balancer, or accept this.
#A full revocation test
Do this on UAT (or production before go-live) with a test account, two browsers or a private window. It is also in Acceptance.
Set up: KIMS's Keycloak admin makes a test account with a verified email and cms-access; a CMS Admin adds it on the People screen with any role.
| Step | Do | You should see |
|---|---|---|
| 1 | Sign in to the CMS as the test user in browser A | The dashboard |
| 2 | Keycloak admin: Users, the test user, Sessions tab, Sign out | (nothing in browser A yet) |
| 3 | In browser A, click any link in the CMS | The CMS sign-in page |
| 4 | Sign in again as the test user | The dashboard |
| 5 | Keycloak admin: Details, Enabled off, Save | |
| 6 | In browser A, click any link | The CMS sign-in page; signing in shows Keycloak's "Account is disabled" |
| 7 | Keycloak admin: Enabled on again. Test user signs in | The dashboard |
| 8 | Keycloak admin: Role mapping, unassign cms-access |
|
| 9 | In browser A, click any link | The CMS sign-in page; signing in again shows "Your KIMS account does not have access to the CMS" |
| 10 | Keycloak admin: give cms-access back. Test user signs in. A CMS Admin suspends them on the People screen |
|
| 11 | In browser A, click any link | The CMS sign-in page; signing in shows the "no access" message |
Afterwards, KIMS's admin disables or deletes the test account.
To confirm the back-channel call (not just introspection) did step 3, look in the CMS log for the absence of a back-channel logout refused line around step 2, and in the sessions table: after step 2 the test user has no rows even before step 3.
#Rotating secrets also signs people out
| Change | Effect |
|---|---|
SESSION_SECRET changed |
Every CMS cookie becomes invalid, and the stored refresh tokens cannot be decrypted: everybody is signed out |
Keycloak client secret regenerated without updating kims-keycloak |
Every check with Keycloak fails: everybody sees "Could not confirm your access" until the Secret is updated and the pods restarted |
See Secrets.
#Sources
kims-v2/apps/cms/src/lib/auth/gate.ts,guard.ts,keycloak.ts,backchannel.tskims-v2/apps/cms/src/app/api/auth/backchannel-logout/route.ts,logout/route.tskims-v2/apps/cms/tests/keycloak-live.test.ts(disabling and role removal refuse the next request)kims-v2/apps/cms/src/lib/auth/errors.ts(AccessCheckUnavailableError)kims-v2/docs/CONFIG.md, Keycloakkims-v2/docs/ON-SITE-DEPLOYMENT.md(main), steps 6 and 11, "Things to tell KIMS"- https://openid.net/specs/openid-connect-backchannel-1_0.html
- https://datatracker.ietf.org/doc/html/rfc7662
- https://www.keycloak.org/docs/latest/server_admin/index.html (Managing user sessions; Revoking active sessions; Disabling a user)