What brute force detection does in Keycloak
Brute force detection counts failed sign-ins for each user. After too many failures, Keycloak locks that user for a while, or disables the account. It turns a fast guessing attack into a slow one.
It is off by default. You turn it on per realm, in the admin console under Realm settings, Security defenses, Brute force detection. The settings are stored on the realm, so they travel with a realm export and import.
This page explains each setting, how they combine, and how to read the calculator above. The calculator is a model, not Keycloak itself. The limits of that model are spelled out below, and they matter.
Why it matters in production
Any public sign-in page gets guessing traffic. Most of it tries common passwords against known or likely usernames. Without a limit, an attacker can try as fast as your servers answer.
Lockouts change the math. If each user can only fail a handful of times before a wait, the attacker gets a few guesses per hour instead of thousands. That makes a strong password policy far more effective.
Lockouts also have a cost. Every lock is a user who cannot sign in, and every support ticket about it costs time. The right settings slow attackers a lot while rarely touching real users.
The settings and their defaults
Each setting has a field in the realm JSON. These are the ones the calculator uses, with Keycloak’s defaults.
| Setting | Realm JSON field | Default |
|---|---|---|
| Max login failures | failureFactor | 30 |
| Wait increment | waitIncrementSeconds | 60 seconds |
| Max wait | maxFailureWaitSeconds | 900 seconds (15 minutes) |
| Failure reset time | maxDeltaTimeSeconds | 43,200 seconds (12 hours) |
| Quick login check | quickLoginCheckMilliSeconds | 1,000 milliseconds |
| Minimum quick login wait | minimumQuickLoginWaitSeconds | 60 seconds |
| Permanent lockout | permanentLockout | off |
{
"realm": "acme",
"bruteForceProtected": true,
"permanentLockout": false,
"failureFactor": 5,
"waitIncrementSeconds": 60,
"maxFailureWaitSeconds": 900,
"maxDeltaTimeSeconds": 43200
}Max login failures
How many failures a user may have before a lock applies. Lower means fewer guesses per lock, and more locks for users who mistype.
Wait increment and max wait
The wait increment is the base lock time. As failures keep coming, the wait grows in steps of the increment, up to the max wait.
Failure reset time
If no failure happens for this long, the count goes back to zero. A long reset time means a slow attacker still builds up failures.
Quick login check
Failures that come faster than this window look like a script. If no other wait applies, Keycloak applies the minimum quick login wait instead.
Temporary and permanent lockout
With temporary lockout, a locked user can try again when the wait is over. With permanent lockout, the user is disabled and stays disabled until an admin enables the account.
Permanent lockout has a serious downside. Brute force detection counts failures per user, not per attacker. Anyone who knows a username can lock that person out by failing on purpose. For most realms, temporary lockout is the safer choice.
Recent Keycloak versions offer more choices here, such as a number of temporary lockouts before a permanent one, and a choice of how the wait grows. Check the options your version shows in the admin console.
What the calculator does and does not do
The calculator follows Keycloak’s classic temporary lockout formula. Newer versions can change when locks apply and how long they last. Always confirm your settings on a test realm before you rely on them.
The model works like this. After each failure, the wait is the wait increment times the number of failures divided by max login failures, rounded down, and capped at the max wait. A failure inside the quick login window gets the minimum quick login wait when no other wait applies. Failures reset after the failure reset time. Attempts during a lock are refused and not counted.
- It simulates an attacker who tries every few seconds, for as many tries as you choose.
- It shows each try: failed, failed and locked, or refused.
- It reports how many passwords the attacker actually got to try, and about how many per hour.
- It writes the settings as realm JSON you can copy.
It does not model newer lockout strategies, the number of temporary lockouts before a permanent one, or several attackers at once. It does not know whether your sign-in flow has other checks in front.
How to use the calculator
- Copy your realm’s values from Realm settings, Security defenses, or start from the filled-in example.
- Set how often the attacker tries and how many times.
- Read the badges: passwords tried, rate per hour and the longest lock.
- Scroll the list of tries to see when locks start and how they grow.
- Change one value at a time and compare the passwords tried.
- Copy the realm JSON once you are happy, then test it on a test realm.
Reading the results
The number that matters most is passwords tried. It is the number of real guesses the attacker made against one account in the time you simulated. Refused tries cost the attacker time but test nothing.
Compare that number with your password policy. If users must pick long passwords and common ones are banned, a few dozen guesses a day is very little. If the policy is weak, even a small number of guesses can find a common password.
Then look at the longest lock. A long lock slows attackers, but it is also what a real user faces after a bad morning. If the max wait is reached quickly, the attacker settles into one guess per max wait, and that rate is what you are really choosing.
Use cases
First production deploy
Turn brute force detection on before launch. Use the calculator to pick values that allow a few honest mistakes but cap guessing at a low rate.
Security audit
Reviewers often ask how many guesses an attacker gets per account per day. Enter the realm’s values and a steady attack, and read the rate. Note the model’s limits in the audit notes.
Upgrade from an older version
Lockout options have grown over recent releases. After an upgrade, open the brute force settings in the console and check which mode the realm uses, then test it.
LDAP and Active Directory users
Directories often have their own lockout policy. Two lockouts stacked on top of each other can lock users out of both. Decide which one leads, and set the other more loosely.
Common problems and fixes
A user is locked and cannot sign in
Open the user in the admin console and clear the lock, or wait for it to expire. Through the admin API, delete the user’s entry under attack-detection.
curl -X DELETE \
"https://auth.example.com/admin/realms/acme/attack-detection/brute-force/users/<user-id>" \
-H "Authorization: Bearer $TOKEN"Many users locked at once
A wave of locks often means one password tried against many usernames. Check login events for LOGIN_ERROR and the addresses they come from, and block at the network edge.
Users do not know they are locked
The sign-in page may show a generic error, so users think they mistyped. Login events record the reason, such as user_temporarily_disabled, which helps support answer quickly.
Locks never seem to clear
With a long failure reset time, a user who fails now and then keeps a high count. Each new failure then locks at once. Shorten the reset time, or clear the user’s failures.
Security notes
- Per-user lockouts do not stop one password tried against many users. Add rate limits at the proxy as well.
- Permanent lockout lets anyone who knows a username lock that user out.
- Save login events, so you can see attacks and explain locks to users.
- Protect admins with a second factor, not only with lockouts.
Best practices
- Turn brute force detection on in every production realm.
- Prefer temporary lockout with a modest max wait.
- Keep max login failures low enough to cap guessing, high enough for honest typos.
- Keep the settings in your realm file and version control.
- Test the settings on a test realm after every upgrade.