The CMS keeps its own server-side session, but every request checks with Keycloak that the person may still be in. How long a person stays signed in, and how fast a change in Keycloak reaches the CMS, comes from four Keycloak settings.
Who does this: KIMS's Keycloak admin. These may be realm-wide settings that affect every KIMS application, so they decide. Our engineer explains what the CMS expects and checks the result.
#The settings the CMS expects
These are the reference realm's values (local/keycloak/kims-realm.json), the ones the CMS was built and tested with:
| Setting | Value | Where (Keycloak 26.x) |
|---|---|---|
| Access Token Lifespan | 5 minutes (300 seconds) | Realm settings, Tokens tab, Access tokens section |
| SSO Session Idle | 30 minutes | Realm settings, Sessions tab, SSO Session Settings |
| SSO Session Max | 10 hours | Realm settings, Sessions tab, SSO Session Settings |
| Revoke Refresh Token | On | Realm settings, Tokens tab, Refresh tokens section |
| Refresh Token Max Reuse | 0 (shown when Revoke Refresh Token is on) | Same |
#What each one does for the CMS
#Access Token Lifespan: 300 seconds
The CMS keeps the access token's expiry on its session row. On each request:
- While the access token is valid, it introspects the refresh token at Keycloak. Introspection shows a disabled user, an ended session or a removed
cms-accessat once, and does not use the refresh token up. - Once it has expired (5 seconds early, to be safe), it refreshes: a new access token, which must still carry
cms-access, and a new refresh token, saved on the session.
So the access token's lifespan sets how often the CMS refreshes, not how fast a revocation lands (introspection already catches that on the next click). 300 seconds is a good balance. A much longer value (an hour) still works. A much shorter one (under a minute) just means more refreshes.
The CMS reads the lifespan from the token response's expires_in, so it needs no configuration to match.
#SSO Session Idle: 30 minutes
A person who does nothing in the CMS (and no other KIMS application in the same Keycloak session) for 30 minutes has their Keycloak session end. The CMS's next refresh or introspection then fails, the CMS deletes its session, and the person is sent to sign in.
Any activity keeps it alive: each CMS refresh (at least every 5 minutes while they work) counts as activity.
#SSO Session Max: 10 hours
The hard limit: after 10 hours from sign-in, the Keycloak session ends whatever the person is doing, and so does the CMS session. The CMS's own cookie lasts 12 hours, so Keycloak's limit is the one that matters.
#Revoke Refresh Token: on, max reuse 0 (rotation)
Each refresh token works once: a refresh returns a new one and the old one is dead. A stolen refresh token that has already been used is useless, and a replayed one ends the session.
The CMS is built for this: it refreshes under a lock on the session row in PostgreSQL, so two requests from the same person at the same moment (two tabs, a page and its data) never both use one refresh token. Without that lock, rotation would sign people out at random.
If KIMS keeps rotation off realm-wide, the CMS still works unchanged; it only loses the protection against a replayed refresh token.
#If KIMS's realm uses other values
Most KIMS realms will already have settings chosen for their other applications. What each difference means:
| KIMS's value | Effect on the CMS | Acceptable? |
|---|---|---|
| Access token 15 or 60 minutes | Fewer refreshes; revocation still lands on the next click through introspection | Yes |
| Access token under 60 seconds | Many more refreshes, more load on Keycloak | Works; not recommended |
| SSO Session Idle longer (8 hours) | People stay signed in while away from their desk | KIMS's security call |
| SSO Session Idle shorter (10 minutes) | Signed out after 10 idle minutes, losing unsaved edits | Works; editors will notice |
| SSO Session Max 24 hours | The CMS cookie (12 hours) then ends the CMS session first | Yes |
| Revoke Refresh Token off | No replay protection | Works |
| Offline access or Remember Me | Not used by the CMS (it never asks for offline_access) |
No effect |
#Set them for the CMS client only
If KIMS will not change the realm, the client can have its own, shorter values. Clients, kims-cms, Advanced tab, section Advanced settings:
| Field | Value | Note |
|---|---|---|
| Access Token Lifespan | 5 minutes | Overrides the realm's for this client |
| Client Session Idle | 30 minutes | Can only be shorter than the realm's SSO Session Idle; a longer value has no effect |
| Client Session Max | 10 hours | Can only be shorter than the realm's SSO Session Max |
Click that section's own Save. Refresh token rotation is a realm setting in the admin console; there is no per-client switch for it.
#Check the values
#In the admin console
Realm settings, Tokens and Sessions tabs: read the values above. Then Clients, kims-cms, Advanced, Advanced settings: empty fields mean "use the realm's".
#In a real token
Clients, kims-cms, Client scopes tab, Evaluate, pick a user, Generated access token. exp minus iat is the access token lifespan in seconds: you should see 300.
#In the CMS
- Sign in. Leave the tab alone for longer than SSO Session Idle (30 minutes).
- Click anything.
You should land on the CMS sign-in page, and Keycloak should ask for a password again.
#Clocks must be right
The CMS checks token times (exp, iat) with no clock tolerance, and refuses a back-channel logout token older than 10 minutes. If a CMS pod's clock and Keycloak's clock differ by more than a second or two, sign-ins can fail with "KIMS sign-in refused the sign-in" and a log line mentioning "iat" claim timestamp check failed or "exp" claim timestamp check failed.
EKS nodes keep time through the Amazon Time Sync Service by default. KIMS's Keycloak servers must use NTP. If the clocks drift, fix the time sync; there is no CMS setting to loosen it.
#Sources
kims-v2/local/keycloak/kims-realm.json(accessTokenLifespan,ssoSessionIdleTimeout,ssoSessionMaxLifespan,revokeRefreshToken,refreshTokenMaxReuse)kims-v2/apps/cms/src/lib/auth/gate.ts(introspect or refresh on every request, the 5 second skew, the row lock)kims-v2/apps/cms/src/lib/auth/sessions.ts,pg-sessions.ts(withLock)kims-v2/apps/cms/src/lib/auth/keycloak.ts(expires_in,invalid_grant, introspection, logout tokenmaxTokenAge)kims-v2/apps/cms/src/lib/auth/cookie.ts(12 hour session cookie)- https://www.keycloak.org/docs/latest/server_admin/index.html (Session and token timeouts; Configuring sessions; Advanced settings)
- https://datatracker.ietf.org/doc/html/rfc6749#section-10.4 (refresh token rotation)
- https://datatracker.ietf.org/doc/html/rfc7662 (token introspection)
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html