Skip to content

Configure Keycloak account lockout

You’ll configure Keycloak’s brute-force protection to control how accounts are locked after repeated failed login attempts. By default, UDS Core applies a permanent lockout after 3 failures within a 12-hour window. You can configure temporary lockouts that precede permanent lockout using a bundle override.

  • UDS Core deployed
  • UDS CLI installed

UDS Core exposes one configurable option for brute-force lockout behavior: MAX_TEMPORARY_LOCKOUTS.

ValueBehavior
0 (default)Permanent lockout only — 3 failed attempts within 12 hours locks the account permanently until an admin unlocks it
> 0Temporary then permanent — each group of 3 failures triggers a 15-minute temporary lockout; after MAX_TEMPORARY_LOCKOUTS temporary lockouts, the account is permanently locked
  1. Set MAX_TEMPORARY_LOCKOUTS in your bundle override

    Add the override to your uds-bundle.yaml:

    uds-bundle.yaml
    packages:
    - name: core
    repository: registry.defenseunicorns.com/public/core
    ref: x.x.x-upstream
    overrides:
    keycloak:
    keycloak:
    values:
    - path: realmInitEnv
    value:
    MAX_TEMPORARY_LOCKOUTS: "3"

    With MAX_TEMPORARY_LOCKOUTS: "3", the lockout sequence for a user is:

    EventResult
    3 failed loginsTemporary lockout (15 minutes)
    3 more failed loginsSecond temporary lockout
    3 more failed loginsThird temporary lockout
    3 more failed loginsPermanent lockout

    The number of temporary lockouts allowed before escalation to permanent:

    • MAX_TEMPORARY_LOCKOUTS: "1" → second lockout is permanent
    • MAX_TEMPORARY_LOCKOUTS: "2" → third lockout is permanent
    • MAX_TEMPORARY_LOCKOUTS: "3" → fourth lockout is permanent
  2. (Optional) Fine-tune brute-force settings in the Keycloak admin UI

    For additional control over lockout timing and thresholds, configure them directly in the Keycloak Admin Console. Log in to keycloak.<admin_domain>, switch to the uds realm, and navigate to Realm SettingsSecurity DefensesBrute Force Detection.

    Key settings:

    SettingRecommended valueDescription
    Brute Force ModeLockout permanently after temporary lockoutEnables the temporary-then-permanent mode
    Failure Factor3Failed login attempts within the window before a lockout triggers
    Quick Login Check (ms)1000Treat rapid repeated failures as an attack
    Max Delta Time (s)4320012-hour rolling window for counting failures
    Wait Increment (s)900Duration of a temporary lockout (15 minutes)
    Max Failure Wait (s)86400Maximum temporary lockout duration (24 hours)
    Failure Reset Time (s)43200When to reset failure counters
    Permanent LockoutONEnable escalation to permanent lockout
    Max Temporary LockoutsMatch your MAX_TEMPORARY_LOCKOUTS value

    After configuring, save and test with a non-production account.

  3. Create and deploy your bundle

    Terminal window
    uds create <path-to-bundle-dir>
    uds deploy uds-bundle-<name>-<arch>-<version>.tar.zst

Confirm brute-force lockout is working:

  1. In a test browser session, attempt to log in with a valid username and incorrect password 3 times
  2. Log in to the Keycloak Admin Console → Users → select the test user → Details tab and confirm the Locked status is shown
  3. If using temporary lockouts, wait 15 minutes and confirm the Locked status clears automatically
  4. Attempt to log in again after the temporary lockout period to confirm the account is accessible

Check the lockout configuration:

In the Keycloak Admin Console, navigate to Realm SettingsSecurity DefensesBrute Force Detection and confirm the settings match your intended configuration.

Problem: Account does not lock after repeated failed login attempts

Section titled “Problem: Account does not lock after repeated failed login attempts”

Symptoms: A user can keep attempting login indefinitely without being locked out.

Solution: Confirm brute-force detection is enabled. In the Keycloak Admin Console, go to Realm SettingsSecurity DefensesBrute Force Detection and verify it is Enabled. Also confirm the MAX_TEMPORARY_LOCKOUTS bundle override was applied and that Keycloak was redeployed afterward.

Problem: Permanently locked account needs to be unlocked

Section titled “Problem: Permanently locked account needs to be unlocked”

Symptoms: A user is permanently locked and cannot regain access.

Solution: An administrator must manually unlock the account in the Keycloak Admin Console:

  1. Navigate to Users and find the affected user
  2. Click the user to open their profile
  3. On the Details tab, toggle Enabled to On
  4. Save

Problem: Lockout settings applied via bundle override are not reflected in the admin UI

Section titled “Problem: Lockout settings applied via bundle override are not reflected in the admin UI”

Symptoms: MAX_TEMPORARY_LOCKOUTS was set in the bundle but the Keycloak admin UI still shows default values.

Solution: realmInitEnv settings are applied only during initial realm import. The bundle must be deployed on a fresh Keycloak instance (or the realm must be re-imported) for the override to take effect. For an already-running instance, configure the settings manually in the Keycloak Admin Console as described in Step 2.

These guides and concepts may be useful to explore next: