Keycloak health probes, metrics and memory alerts #573

Stängd
öppnade 2026-10-08 14:52:40 +00:00 av supernaut · 5 kommentarer
Ägare

Monitor Keycloak and alert before it fails.

  • Blackbox probe on /realms/bitborg/.well-known/openid-configuration replaces /status. Update sign-in chain probes.
  • Scrape the management port :9000/metrics. Add a unit-active metric for keycloak.
  • Alerts: memory above 90 % of MemoryMax for 10 minutes, any OOM kill of the unit, not ready for 2 minutes, brute-force lockouts above a threshold.
  • Update SignupProvisioningFailing to the new log prefix.
  • Rewrite the Kanidm runbook sections for Keycloak: bootstrap, break-glass admin, client secret rotation, upgrade per minor, delete a user, restore.

Done when: each alert fires in a test and the runbook covers the listed procedures.

Depends on: #570
Epic: bitborg/bitborg-docs#127

Monitor Keycloak and alert before it fails. - [x] Blackbox probe on `/realms/bitborg/.well-known/openid-configuration` replaces `/status`. Update sign-in chain probes. - [x] Scrape the management port `:9000/metrics`. Add a unit-active metric for `keycloak`. - [x] Alerts: memory above 90 % of `MemoryMax` for 10 minutes, any OOM kill of the unit, not ready for 2 minutes, brute-force lockouts above a threshold. - [x] Update `SignupProvisioningFailing` to the new log prefix. - [x] Rewrite the Kanidm runbook sections for Keycloak: bootstrap, break-glass admin, client secret rotation, upgrade per minor, delete a user, restore. Done when: each alert fires in a test and the runbook covers the listed procedures. Depends on: #570 Epic: bitborg/bitborg-docs#127
Upphovsperson
Ägare

#640 merged. Two thresholds differ from the issue text, by decision 2026-10-10:

  • Memory alert at 80 % of MemoryMax, not 90 %. MemoryHigh throttles at 87.5 %, so 90 % would never be reached.
  • Not-ready after 3 min, not 2 min. It must outlast the 120 s HealthStartPeriod.

Proven by vmalert-tool unit tests: KeycloakNotReady, KeycloakMemoryHigh and CoreUnitDown for keycloak. The Loki rules for OOM, lockout and the sign-up prefix are checked against sample log lines.

Left:

  • Prove the KeycloakLoginLockouts matcher against real Loki lines: enough bad passwords on a test user to lock it.
#640 merged. Two thresholds differ from the issue text, by decision 2026-10-10: - Memory alert at 80 % of `MemoryMax`, not 90 %. `MemoryHigh` throttles at 87.5 %, so 90 % would never be reached. - Not-ready after 3 min, not 2 min. It must outlast the 120 s `HealthStartPeriod`. Proven by vmalert-tool unit tests: `KeycloakNotReady`, `KeycloakMemoryHigh` and `CoreUnitDown` for `keycloak`. The Loki rules for OOM, lockout and the sign-up prefix are checked against sample log lines. Left: - [ ] Prove the `KeycloakLoginLockouts` matcher against real Loki lines: enough bad passwords on a test user to lock it.
Upphovsperson
Ägare

KeycloakMemoryHigh fire and no-fire cases are covered by the vmalert-tool unit tests in alert-rules.test.yml (#640). scripts/test-alert-rules.py passes. Raising the fixture's current value to 75% makes the fire case fail, so the test can fail.

Live check, 2026-10-11: bitborg_unit_memory_current_bytes and bitborg_unit_memory_max_bytes have 0 series. The monitoring VM scrapes only the prod host, and prod does not run Keycloak yet. So the alert cannot fire live before cutover.

#654: the unit and container alert annotations printed the scrape address (node-exporter:9100). They now print $labels.host.

Remaining after cutover: confirm the ratio series returns a value and the rule shows as inactive in vmalert.

`KeycloakMemoryHigh` fire and no-fire cases are covered by the vmalert-tool unit tests in `alert-rules.test.yml` (#640). `scripts/test-alert-rules.py` passes. Raising the fixture's current value to 75% makes the fire case fail, so the test can fail. Live check, 2026-10-11: `bitborg_unit_memory_current_bytes` and `bitborg_unit_memory_max_bytes` have 0 series. The monitoring VM scrapes only the prod host, and prod does not run Keycloak yet. So the alert cannot fire live before cutover. #654: the unit and container alert annotations printed the scrape address (`node-exporter:9100`). They now print `$labels.host`. Remaining after cutover: confirm the ratio series returns a value and the rule shows as inactive in vmalert.
Upphovsperson
Ägare

Status 2026-10-11 after the cutover: Keycloak runs on prod, so its series are scraped. KeycloakMemoryHigh fired live on prod at 833 MB of 1 GiB (the heap flag was dropped by a Quadlet quoting bug, fixed in #666). That is a real firing. Probes now use /realms/bitborg/.well-known/openid-configuration and /user/oauth2/Bitborg-id. OOM, not-ready and lockout alerts are covered by the vmalert unit tests (#654). Open: the runbook procedures listed in the body (bootstrap, break-glass, secret rotation, upgrade, delete a user, restore) should be checked against the runbook before closing.

Status 2026-10-11 after the cutover: Keycloak runs on prod, so its series are scraped. `KeycloakMemoryHigh` fired live on prod at 833 MB of 1 GiB (the heap flag was dropped by a Quadlet quoting bug, fixed in #666). That is a real firing. Probes now use `/realms/bitborg/.well-known/openid-configuration` and `/user/oauth2/Bitborg-id`. OOM, not-ready and lockout alerts are covered by the vmalert unit tests (#654). Open: the runbook procedures listed in the body (bootstrap, break-glass, secret rotation, upgrade, delete a user, restore) should be checked against the runbook before closing.
Upphovsperson
Ägare

Check 2026-10-11 evening.

  • Probe id.bitborg.se/realms/bitborg/.well-known/openid-configuration returns 1. The keycloak:9000 scrape is up.
  • KeycloakNotReady and KeycloakMemoryHigh are loaded in vmalert and inactive. Memory is at 64 % of MemoryMax after the MALLOC_ARENA_MAX=2 apply (#671/#672).
  • Loki ruler: group bitborg-keycloak holds 2 rules (KeycloakOOMKilled, KeycloakLoginLockouts), evaluating with 0 failures (loki_prometheus_rule_* on the Loki host).
  • Runbook covers bootstrap, break-glass, secret rotation, upgrade, delete a user, restore, memory caps and alerts.

Open: prove KeycloakLoginLockouts on a real lockout. A real LOGIN_ERROR line has the shape the matcher expects, but no user_temporarily_disabled line has been logged yet.

Check 2026-10-11 evening. - Probe `id.bitborg.se/realms/bitborg/.well-known/openid-configuration` returns 1. The `keycloak:9000` scrape is up. - `KeycloakNotReady` and `KeycloakMemoryHigh` are loaded in vmalert and inactive. Memory is at 64 % of MemoryMax after the `MALLOC_ARENA_MAX=2` apply (#671/#672). - Loki ruler: group `bitborg-keycloak` holds 2 rules (`KeycloakOOMKilled`, `KeycloakLoginLockouts`), evaluating with 0 failures (`loki_prometheus_rule_*` on the Loki host). - Runbook covers bootstrap, break-glass, secret rotation, upgrade, delete a user, restore, memory caps and alerts. Open: prove `KeycloakLoginLockouts` on a real lockout. A real `LOGIN_ERROR` line has the shape the matcher expects, but no `user_temporarily_disabled` line has been logged yet.
Upphovsperson
Ägare

Lockout matcher verified live on 2026-10-18. A throwaway user (lockout-test, since deleted) failed 10 logins on the account console, and the next attempts were refused. Keycloak logged type="LOGIN_ERROR" ... error="user_temporarily_disabled" ... username="lockout-test" twice. The KeycloakLoginLockouts LogQL selector, count_over_time({container="keycloak"} |~ \type="?LOGIN_ERROR"?.*error="?user_(temporarily|permanently)_disabled` [30m])`, returned 2. The alert threshold (more than 20 in 10 min) was not reached, as intended. The UI shows "Invalid username or password" to a locked user by design, so the lock does not leak.

Earlier checks: SignupProvisioningFailing matches today's [signup] Keycloak prefix, and the runbook covers every procedure in the list. Every done-when item is met.

Lockout matcher verified live on 2026-10-18. A throwaway user (`lockout-test`, since deleted) failed 10 logins on the account console, and the next attempts were refused. Keycloak logged `type="LOGIN_ERROR" ... error="user_temporarily_disabled" ... username="lockout-test"` twice. The `KeycloakLoginLockouts` LogQL selector, `count_over_time({container="keycloak"} |~ \`type="?LOGIN_ERROR"?.*error="?user_(temporarily|permanently)_disabled\` [30m])`, returned 2. The alert threshold (more than 20 in 10 min) was not reached, as intended. The UI shows "Invalid username or password" to a locked user by design, so the lock does not leak. Earlier checks: `SignupProvisioningFailing` matches today's `[signup] Keycloak` prefix, and the runbook covers every procedure in the list. Every done-when item is met.
Logga in för att delta i denna konversation.
Ingen milstolpe
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Förfallodatumet är ogiltigt eller utanför gränserna. Använd formatet "åååå-mm-dd".

Inget förfallodatum satt.

Beroenden

Inga beroenden satta

Referens
bitborg/bitborg-infra#573
Ingen beskrivning angiven.