SSO Session Idle vs SSO Session Max in Keycloak: Two Very Different Clocks
A complete, no-code walkthrough of the two timers that decide when a single sign-on session actually ends — and why confusing them leads to logins that expire either too soon or far too late.
Think about a library that lets you sit and read all day, as long as you keep turning pages. The moment you fall asleep at the table for too long, a librarian gently wakes you and asks you to leave — that’s an idle timer. But even if you never once stop reading, the library still closes at 9 PM sharp, no exceptions — that’s a maximum timer. Keycloak’s Single Sign-On sessions work under exactly this same pair of rules: SSO Session Idle ends a session after a period of inactivity, while SSO Session Max ends it after a fixed total duration, active or not. This post untangles these two settings in detail — what each one actually controls, how they interact, and how to configure them without accidentally locking users out too early or leaving sessions open far longer than intended.
1What Are These Two Settings?
Before diagrams and architecture, let’s build a precise mental model of what each timer actually measures.
The problem: “how long should a login last?” has two different answers
When a user logs into Keycloak once and then moves between several applications without logging in again, they’re relying on a single, shared SSO session behind the scenes. But “how long should that session last?” isn’t one question — it’s two. Should it last as long as the user keeps using it? And separately, should there be an absolute cutoff no matter how actively it’s being used? Keycloak answers both questions with two independent realm-level settings.
A parking meter with a maximum stay is a good comparison. Feed it coins and your car can sit there as long as you keep feeding it — that’s like Idle timeout, reset by activity. But many parking meters also have a hard cap, like “4 hours maximum,” after which you must move your car regardless of how many coins you’ve fed the meter. That hard cap is Session Max — it doesn’t care how active you’ve been.
SSO Session Idle, precisely defined
SSO Session Idle is the maximum period of inactivity Keycloak allows before automatically ending the SSO session. Every time the user interacts with Keycloak — logging into another application through SSO, or refreshing a token — this idle timer resets. As long as the user (or an application acting for them) keeps generating activity within the idle window, the session can, in principle, continue indefinitely.
SSO Session Max, precisely defined
SSO Session Max is the absolute maximum lifetime of the SSO session, measured from the moment it was created. Unlike Idle, this timer never resets — no amount of activity extends it. Once this duration elapses, the session ends, full stop, even if the user has been continuously active the entire time.
Idle measures a gap in activity. Max measures total elapsed time since creation. A session can end because of either one — whichever limit is reached first wins.
SSO Session Idle
Resets on activity. Answers: “how long can this session sit unused before it’s cleaned up?”
SSO Session Max
Never resets. Answers: “no matter how active the user is, when must they be forced to log in again?”
A longer Idle value does not mean users stay logged in longer overall — Session Max still applies as a hard ceiling regardless of how frequently the user is active.
Why “session” here means more than one login screen
It’s worth being precise about what “session” refers to in this context. When a user authenticates once through Keycloak and then moves between several separate applications without being prompted to log in again, all of that access is happening under one shared SSO session on the server side. Idle and Max don’t apply per application — they apply to that single, shared session, which is exactly why activity in any one connected application can keep the whole thing alive.
Where these settings live in practice
Both values are configured as a duration — commonly expressed in minutes, hours, or days depending on the admin console’s unit selector — under the realm’s Sessions configuration. They apply as the default for every client in that realm unless a specific client has been given its own override, a topic covered in more depth later in this post.
2Architecture & Components
These two timers don’t operate in isolation — they sit inside Keycloak’s broader session model, alongside client-level sessions and token lifespans.
The realm as the configuration home
SSO Session Idle and SSO Session Max are configured at the realm level, under the Sessions tab of realm settings. Every user session created within that realm inherits these values by default, though individual clients can override them for their own client sessions when a specific application needs different behavior.
User Session
The server-side record representing one authenticated SSO session, shared across every client the user accesses through that single login.
Client Session
A per-application sub-record tracking that specific client’s participation in the broader user session, including its own optional idle and max overrides.
Realm Session Settings
The realm-wide defaults for SSO Session Idle, SSO Session Max, and their “Remember Me” counterparts.
Session Storage
Keycloak’s internal storage (often backed by an embedded or external cache) that tracks session state, last-activity timestamps, and expiry across the cluster.
How the pieces fit together
Picture the User Session as a master ticket for a theme park, and each Client Session as a wristband for a specific ride queue inside the park. The master ticket has its own overall closing time (SSO Session Max) and its own “leave if you haven’t scanned it in a while” rule (SSO Session Idle). Individual ride queues can, in some parks, impose their own stricter rules on top — but they can never let you stay in the park longer than the master ticket allows.
flowchart TD
RS[Realm Settings] -->|defaults| US[User Session
SSO Session Idle + Max]
US --> CS1[Client Session A
optional override]
US --> CS2[Client Session B
optional override]
US -->|expires when| END{Idle exceeded
OR Max reached}
Remember Me as a parallel timer set
Keycloak provides a second, usually longer, pair of Idle and Max values specifically for sessions created via the “Remember Me” option, letting administrators offer a genuinely persistent login experience for users who opt into it, without changing the default, shorter-lived behavior for everyone else.
Session storage and clustering
In a clustered Keycloak deployment, session state — including the creation timestamp and last-activity timestamp that Idle and Max depend on — must be visible consistently across every node handling requests for that user. Keycloak relies on its distributed session cache to keep this state synchronized, which is why the accuracy of these two timers depends not just on their configured values but on the underlying session storage being healthy and correctly replicated across the cluster.
If session replication in a cluster is misconfigured, a request landing on a different node might not see the most recent activity timestamp, which can cause a session to appear idle-expired earlier than the configured value would suggest.
3Internal Working
What actually happens inside Keycloak’s session engine as these two timers tick?
Session creation
At successful login, Keycloak creates a User Session and stamps it with a creation timestamp and an initial last-activity timestamp, both equal at this point.
Activity updates the last-activity timestamp
Each time a token is refreshed, or the user authenticates to another client through SSO, Keycloak updates the last-activity timestamp on the User Session.
Idle check on every relevant request
Keycloak compares the current time against the last-activity timestamp; if the gap exceeds SSO Session Idle, the session is treated as expired.
Max check independent of activity
In parallel, Keycloak compares the current time against the original creation timestamp; if the elapsed time exceeds SSO Session Max, the session is treated as expired — regardless of how recent the last activity was.
Whichever limit triggers first ends the session
Keycloak doesn’t wait for both conditions — the first threshold crossed invalidates the User Session and cascades to every associated Client Session.
Imagine two independent countdown clocks running side by side on a wall — one that resets every time someone walks past a motion sensor, and one that simply counts down from a fixed starting point no matter what. The moment either clock hits zero, the door locks. Keycloak runs exactly these two clocks for every SSO session.
Why activity from any client counts
Because the Idle timer lives on the shared User Session rather than on any single Client Session, activity in one application resets the idle clock for every other application sharing that SSO session. A user actively working in one tool keeps their entire single sign-on session alive across every other tool they’re logged into, even ones they haven’t touched recently.
Refreshing an access token is itself a form of activity that resets the Idle timer — which is why applications that silently refresh tokens in the background can keep a session alive far longer than a user’s actual, conscious engagement with the page.
Why the two checks run independently rather than sequentially
It’s tempting to imagine Keycloak checking Idle first and only checking Max if Idle passes, but in practice both conditions are simply two independent facts about the same session, evaluated together whenever a check is needed. There’s no ordering dependency between them — a session can fail the Max check even while comfortably within its Idle window, and vice versa. Thinking of them as two separate, simultaneously-true-or-false conditions rather than a sequence avoids a common source of confusion when reasoning about edge cases.
What triggers an idle or max check
Keycloak doesn’t necessarily run a constant background sweep checking every session every second. Instead, these checks are commonly evaluated at meaningful touchpoints — when a token refresh is attempted, when a new authentication request arrives for a client sharing the session, or during periodic cleanup passes that remove genuinely expired sessions from storage to free up resources.
4Data Flow & Lifecycle
Let’s trace a realistic scenario across a full working day to see exactly how these two timers interact.
sequenceDiagram
participant User
participant KC as Keycloak
User->>KC: Log in at 9:00 AM
KC->>KC: Create session
created=9:00, lastActive=9:00
User->>KC: Active use throughout the morning
KC->>KC: lastActive keeps updating
Note over KC: Idle timer never triggers
because user stays active
Note over KC: Max timer keeps counting
from 9:00 regardless
User->>KC: Continues working past Max duration
KC-->>User: Session forcibly ended at Max limit
even though still active
Lifecycle stages of a session under both timers
Created
Login establishes the session with both a creation time and an initial last-activity time.
Refreshed
Ongoing activity extends the Idle window each time, while the Max window continues unaffected.
Idle-Expired
No activity occurs for longer than the Idle duration; the session ends here if Max hasn’t already been reached.
Max-Expired
The absolute duration since creation is reached; the session ends here regardless of recent activity.
A long Idle timeout combined with an even longer Max timeout can create sessions that persist for days on end for continuously active users — a combination worth deliberately reviewing rather than leaving at defaults.
How client sessions inherit and diverge
Each Client Session tracks its own activity for that specific application but is ultimately bound by the overall User Session’s expiry. If a client configures a stricter idle or max override, that client’s session can end earlier than the broader SSO session — but it can never outlive it; once the User Session itself expires, every Client Session tied to it expires as well.
A worked example across the two timers
Suppose a realm is configured with a 30-minute Idle timeout and a 10-hour Max timeout. A user logs in at 9:00 AM and works steadily, refreshing tokens every few minutes, never leaving a 30-minute gap. Under Idle alone, this session could theoretically run forever. But because Max is fixed at 10 hours from creation, the session will end at 7:00 PM regardless of how recently the user was active — even mid-task, if that’s when the clock runs out. This is precisely the scenario Max exists to guarantee: an upper bound that activity alone cannot extend.
5Related Settings and How They Interact
Idle and Max don’t operate alone — several neighboring settings shape the full picture of session behavior.
SSO Session Idle Remember Me
A separate, typically longer idle value applied only to sessions created with “Remember Me” checked at login, giving those users more tolerance for inactivity before being logged out.
SSO Session Max Remember Me
A separate, typically longer max value for the same “Remember Me” sessions, extending the absolute ceiling for users who explicitly opted into a persistent login.
Client Session Idle / Client Session Max
Per-client overrides that can impose stricter limits than the realm defaults for a specific application, without affecting the broader SSO session shared with other clients.
Access Token Lifespan
A separate, usually much shorter setting controlling how long an individual access token is valid — unrelated to the session’s own idle or max limits, but bounded by them.
How these settings stack
| Setting | Resets on Activity? | Scope |
|---|---|---|
| SSO Session Idle | Yes | Entire User Session |
| SSO Session Max | No | Entire User Session |
| Client Session Idle | Yes | Single Client Session |
| Client Session Max | No | Single Client Session |
| Access Token Lifespan | No (fixed per token) | A single issued token |
A note on token lifespan versus session lifespan
It’s easy to conflate “how long is my access token valid” with “how long is my session valid,” but these operate at different layers. An access token’s own lifespan is typically much shorter than either session timer, and expired access tokens are routinely replaced through a refresh — as long as the underlying session is still within both its Idle and Max windows. Once the session itself expires under either rule, no further refresh is possible, and the user must authenticate again from scratch.
6Comparing These Settings to Simpler Alternatives
It’s worth seeing this two-timer model next to the simpler approaches teams sometimes assume are equivalent.
Single Fixed Session Length
Logging users out after one flat duration, active or not. Simple, but forces re-authentication on genuinely engaged users just as often as idle ones.
Idle Timeout Only, No Max
Letting a session live indefinitely as long as it stays active. Convenient for users, but removes any hard ceiling on how long a single login can remain valid.
Relying Solely on Access Token Lifespan
Assuming short-lived access tokens alone control session length. In reality, refresh tokens tied to the session can keep renewing access far beyond a single token’s lifespan, until Idle or Max intervenes.
The two-timer model exists precisely because neither extreme serves every situation well. Idle alone rewards continuous activity with unlimited session length, which can be a genuine risk for sensitive applications. Max alone punishes active users by cutting them off mid-task on a fixed schedule. Combining both lets an administrator express “stay logged in while you’re working, but never longer than this absolute ceiling” — a much closer match to how most organizations actually want session risk managed.
Why not just make Access Token Lifespan very short instead?
Some teams wonder whether a very short access token lifespan alone could substitute for session-level controls entirely. It can’t, because the refresh token tied to the session is what actually determines whether a new access token can keep being issued — and that refresh capability is governed by the session’s own Idle and Max limits, not by how short the access tokens themselves are. Shortening access tokens reduces the exposure window of any single stolen token, but it doesn’t touch the question of how long the overall login can be extended through refreshing.
7Advantages, Disadvantages & Trade-offs
Configuring these two timers is a balancing act between user convenience and session risk exposure.
Advantages
- Idle timeout reduces risk from unattended, logged-in sessions on shared or unlocked devices
- Max timeout guarantees a hard ceiling regardless of how active a session appears to be
- Separate Remember Me values let organizations offer convenience without weakening default security
- Per-client overrides allow sensitive applications to enforce stricter limits than the rest of the realm
Disadvantages / Trade-offs
- A short Idle value can interrupt genuinely engaged users during natural pauses in activity
- A long Max value undermines the security benefit of having a ceiling at all
- Two independent settings are easier to misconfigure than a single, simpler timeout
- Background token refresh can mask true user inactivity, keeping sessions alive longer than intended
Setting these two values is like tuning a home security light with both a motion-triggered timer and a hard curfew. Too short a motion timer and it shuts off while you’re still standing there; too long a curfew and the light stays on all night regardless. Getting both settings right takes a little observation of how the space is actually used.
The cost of getting it wrong in either direction
Setting Idle too short generates a steady stream of “I got logged out for no reason” complaints, often from users who were reading a long document or on a call without touching their keyboard. Setting Max too long, on the other hand, rarely generates complaints at all — which is exactly what makes it dangerous; nobody notices a session that’s been open for three days until something goes wrong with it. Tuning both values well is as much about listening for the absence of a problem as it is about responding to visible complaints.
8Security Considerations
Session duration is a direct security control — the longer a session lives, the longer a stolen or hijacked session can be misused.
Excessively Long Idle Timeout
A shared or unlocked workstation with a very long idle allowance stays authenticated far longer than the user is actually present.
Excessively Long Max Timeout
Even with a strict idle setting, an overly generous Max value means a compromised session token remains usable for an extended window.
Uniform Settings Across Sensitivity Levels
Applying the same idle and max values to a low-risk internal wiki and a high-risk financial admin console ignores that they warrant very different exposure windows.
Ignoring the Remember Me Values
Administrators sometimes harden the default Idle and Max settings while leaving the Remember Me equivalents at loose defaults, creating an easy way for the stricter policy to be bypassed.
SSO Session Max should always be set with a real ceiling in mind — treating it as “just a formality” and leaving it very long defeats the entire purpose of having an absolute limit alongside the idle timer.
Matching timeout values to sensitivity
Higher-sensitivity applications — those handling financial transactions, personal health information, or administrative control — generally warrant shorter Idle and Max values than lower-sensitivity, read-mostly applications. Keycloak’s per-client override capability exists precisely so this differentiation doesn’t require compromising the realm-wide defaults used by everything else.
Session hijacking and the value of a short Max
If an attacker manages to steal a valid refresh token — through malware, a compromised network, or a leaked log file — the window during which that stolen credential remains useful is bounded by the session’s Max setting, not by how quickly the theft is detected. A shorter Max value directly limits the damage a successful theft can do, independent of any other detection or response capability the organization has in place. This is one of the clearest, most concrete reasons Max deserves deliberate configuration rather than being left at a permissive default.
9Monitoring, Logging & Metrics
Session expiry behavior is easy to configure and forget — but worth watching once real users depend on it.
What to watch
Idle-Expiry Rate
A high rate of idle expirations can indicate the idle window is too short for how users actually work, generating support complaints about unexpected logouts.
Max-Expiry Rate
Frequent max expirations during active work sessions may signal the max duration is too aggressive for the realm’s typical usage patterns.
Average Session Duration
Comparing actual observed session lengths against the configured Idle and Max values reveals whether the settings match real usage or were set arbitrarily.
Concurrent Active Sessions
Tracking how many sessions are alive at once helps size session storage capacity and spot unusual spikes that might indicate abuse.
What to log
Recording the reason a session ended — idle expiry, max expiry, explicit logout, or administrative revocation — turns a vague “why was I logged out?” support ticket into a quick, factual answer, and helps administrators tell whether their configured timeouts are actually serving the users they were designed for.
Distinguishing complaints from genuine misconfiguration
Not every “I got logged out unexpectedly” report reflects a poorly tuned setting — some are simply the Max ceiling working as intended after a genuinely long, continuous work session. Correlating the logout reason against session duration at the time of the event separates these two very different situations: a session that expired well before its configured Idle value might point to a clock synchronization or session replication issue, while one that expired right at the configured Max value is functioning exactly as designed.
10Design Patterns & Anti-Patterns
Some ways of setting these timers work well in practice. Others create confusing, hard-to-diagnose logout behavior.
Problem
Setting SSO Session Max equal to, or only slightly longer than, SSO Session Idle.
Why It’s Harmful
This effectively removes the benefit of having an idle timer at all — active users hit the Max ceiling almost immediately after any brief pause, producing frequent, disruptive logouts that feel arbitrary to users.
Correct Approach
Set Max meaningfully longer than Idle, so the idle timer genuinely governs day-to-day inactivity while Max serves its intended role as a distant, absolute ceiling.
Problem
Leaving default Idle and Max values unchanged for a highly sensitive administrative console, identical to a public-facing, low-risk application.
Why It’s Harmful
An administrative session left open on an idle workstation carries far more risk than a similar session in a low-privilege application, yet an unreviewed default treats both identically.
Correct Approach
Use per-client overrides to enforce noticeably shorter Idle and Max values for high-privilege clients, independent of the realm’s general-purpose defaults.
Patterns worth adopting
Tiered Timeout Profiles by Sensitivity
Define a small number of standard timeout profiles — for example, “standard,” “sensitive,” and “public” — and apply them consistently across clients based on risk level, rather than setting values ad hoc per application.
Deliberate Remember Me Ceilings
Set Remember Me values that are meaningfully longer than the defaults, but still bounded — treating “remember me” as extended convenience, not unlimited persistence.
Problem
Configuring an extremely long Max value “just in case” without a documented reason, simply because no one has revisited the setting since the realm was first created.
Why It’s Harmful
An undocumented, unreviewed Max value tends to drift toward being far longer than any actual business requirement calls for, quietly expanding the window during which a compromised session remains usable.
Correct Approach
Tie the Max value to an explicit business or compliance requirement — a shift length, a regulatory guideline, a typical work session — and revisit it whenever that underlying requirement changes.
11Best Practices & Common Mistakes
A checklist-style chapter distilling the operational wisdom from the sections above.
| Best Practice | Common Mistake It Prevents |
|---|---|
| Set Max meaningfully longer than Idle | Active users hitting the ceiling almost immediately |
| Use per-client overrides for high-sensitivity apps | Uniform, one-size-fits-all timeout across very different risk levels |
| Review Remember Me values alongside standard ones | A loosely configured “remember me” quietly bypassing stricter defaults |
| Log the reason every session ends | Support tickets with no way to explain unexpected logouts |
| Base values on observed usage patterns | Arbitrary defaults that don’t match how users actually work |
| Communicate timeout policy to end users | Confusion and frustration when sessions end without warning |
Warn users shortly before an idle timeout takes effect, giving them a chance to extend the session with a single click — this alone eliminates a large share of “why was I logged out” complaints without loosening the underlying security posture.
Coordinating with frontend session-warning behavior
Because Keycloak’s own Idle and Max timers run on the server, a well-designed frontend application typically implements its own client-side warning slightly before either limit is reached, giving users a visible countdown and a chance to extend their session proactively. This coordination between server-enforced limits and a considerate frontend experience is what separates a security control users tolerate from one they actively resent.
12Real-World & Industry Examples
These two timers show up wherever session duration is a genuine security or compliance concern.
Banking and Financial Portals
Financial applications typically configure short Idle values, so an unattended browser tab is logged out quickly, alongside a relatively short Max value that forces regular re-authentication even for continuously active users, in line with common regulatory expectations around session security.
Enterprise Internal Tools
Internal productivity suites often set a longer Idle value to accommodate normal workday pauses — meetings, lunch breaks — paired with a Max value tied to a full working day, so users rarely notice the ceiling under normal conditions.
Healthcare Systems
Clinical applications frequently use short Idle timeouts to reduce the risk of a session left open on a shared workstation in a clinical setting, while Max values are tuned to match typical shift lengths.
Consumer-Facing SaaS Products
Consumer platforms commonly offer a generous Remember Me option with extended Idle and Max values, prioritizing convenience for personal devices while keeping the default, non-remembered session shorter-lived.
Government and Public Sector Portals
Public sector applications handling citizen data commonly follow strict compliance guidance that specifies both a maximum idle period and an absolute session ceiling explicitly, making these two Keycloak settings a direct, auditable mapping to a written policy requirement.
Educational Platforms
Learning management systems used in shared computer labs often favor shorter Idle timeouts to prevent one student’s session from remaining active for the next person who sits down, while Max is set generously enough to cover a full class period without interruption.
13Frequently Asked Questions
No — continuous activity only prevents the Idle timer from triggering. SSO Session Max still applies and will end the session once its fixed duration is reached, regardless of activity.
Both matter, but they address different risks: Idle limits exposure from unattended sessions, while Max limits how long any single login — including a compromised one — can remain valid overall.
Yes — a token refresh updates the session’s last-activity timestamp, which is why applications that refresh tokens silently in the background can keep a session alive well beyond a user’s actual engagement.
Yes — Keycloak supports per-client Idle and Max overrides, letting a sensitive application enforce stricter limits without changing the realm-wide defaults used elsewhere.
Remember Me sessions use a separate pair of Idle and Max values, typically longer than the defaults, applied only when the user explicitly opts into the persistent login option at authentication time.
No — Max is measured from the original session creation time and never resets, even though logging into another application through SSO does count as activity for the Idle timer.
Every Client Session tied to that User Session expires along with it, meaning each connected application will require re-authentication the next time it needs a valid token — even ones the user hasn’t actively touched recently.
Yes — an administrator can revoke a session directly, or a user can explicitly log out; both actions end the session immediately without waiting for either timer to elapse naturally.
14Summary and Key Takeaways
SSO Session Idle and SSO Session Max govern the same session but ask two different questions. Idle asks, “has this session gone quiet for too long?” and resets every time genuine activity occurs. Max asks, “has too much total time passed since login?” and never resets, no matter how engaged the user has been. Together, they let an administrator express a session policy that’s both forgiving of natural pauses in use and firmly bounded by an absolute ceiling — a balance that a single flat timeout could never achieve on its own.
Getting the most out of these two settings means treating them as a matched pair rather than configuring each in isolation: choose an Idle value that matches how people actually work, choose a Max value tied to a real business or compliance requirement rather than an arbitrary default, and keep enough distance between the two that Idle actually gets to do its job before Max cuts in. Applied thoughtfully, this pair of timers becomes one of the most direct, easily explained security controls available in the entire realm configuration.
Key Takeaways
- Idle resets on activity — token refreshes and SSO logins to other apps all count.
- Max never resets — it’s measured strictly from session creation, regardless of activity.
- Whichever limit is reached first ends the session — there’s no waiting for both.
- Remember Me uses its own separate pair of values — review both sets, not just the defaults.
- Client-level overrides exist for a reason — sensitive applications deserve stricter limits than general-purpose ones.
- Max close to Idle defeats the purpose of having Idle at all — keep a meaningful gap between the two.
- Logging the expiry reason turns confusing logout complaints into quick, factual explanations.