feat(keycloak): add the keycloak role, database and caddy vhost behind keycloak_enabled #599

Sammanfogat
supernaut sammanfogade 1 incheckning från feat/keycloak-role in i main 2026-10-08 19:29:36 +00:00
Ägare

Runs Keycloak (ADR 0044) on staging behind keycloak_enabled. Prod is unchanged: the flag is false there, the role ends early and the Caddyfile renders byte-identical.

What

  • Role keycloak: a rootless Quadlet unit on bitborg-keycloak:26.8.0-1.
    • MemoryHigh=896M, MemoryMax=1G, -XX:MaxRAM=1G.
    • Read-only root with tmpfs, DropCapability=ALL.
    • Notify=healthy on /health/ready, through a bash /dev/tcp script (the image has no curl).
    • Port 8080 is published on 127.0.0.1:18080 only, for the OpenTofu forward (#598). Port 9000 stays unpublished.
    • The DB pool is capped at 20, because Postgres allows 100 connections in total.
  • Database: the role creates its own keycloak role and database and revokes PUBLIC, as billing does.
  • Bootstrap: the first start creates a temporary master-realm client from KC_BOOTSTRAP_ADMIN_CLIENT_ID/SECRET. #571 replaces it with a permanent client. An assert stops a first start that has no bootstrap secret.
  • Caddy: a vhost on keycloak_domain (kc.stg.bitborg.se on staging, where auth.stg stays on Kanidm for now). It is an allowlist: only /realms/bitborg/* and /resources/* are proxied, and everything else returns 404, including /admin, the master realm, /metrics and /health. The new rate-limit zones keycloak and keycloak_credentials (POST login-actions/* and the token endpoint) use the existing auth budgets.
  • site.yml: the role runs after kanidm. keycloak joins the health gate where it is enabled.
  • Renovate: regex versioning for <keycloak version>-<n> tags. Minors wait for dashboard approval.
  • Runbook: a Keycloak section (forward, first start, bootstrap replacement, break-glass, upgrades), the staging A record, the vault keys and the rate-limit zones.

Verified

  • On the published image: the health script returns 1 before ready and 0 when ready. A read-only root with tmpfs starts. The bootstrap client gets a client_credentials token over plain HTTP. The heap maximum is about 718 MiB.
  • ansible-lint (production profile), --syntax-check against the staging inventory, the repo check scripts, the Renovate validator and shellcheck all pass.
  • With the flag off, the Caddyfile is byte-identical to main. With it on, the vhost validates in stock Caddy without the rate-limit block.

Not verified (staging)

  • What source address the rootless port forward presents, and whether sslRequired=external accepts the token request through it.
  • Read-only root under rootless podman.
  • The rate-limit zones, which only caddy validate with the module checks.
  • That a second apply is idempotent and does not restart Keycloak.
  • Break-glass bootstrap-admin user.

Refs #570

Runs Keycloak (ADR 0044) on staging behind `keycloak_enabled`. Prod is unchanged: the flag is false there, the role ends early and the Caddyfile renders byte-identical. ## What - **Role `keycloak`:** a rootless Quadlet unit on `bitborg-keycloak:26.8.0-1`. - `MemoryHigh=896M`, `MemoryMax=1G`, `-XX:MaxRAM=1G`. - Read-only root with tmpfs, `DropCapability=ALL`. - `Notify=healthy` on `/health/ready`, through a bash `/dev/tcp` script (the image has no curl). - Port 8080 is published on `127.0.0.1:18080` only, for the OpenTofu forward (#598). Port 9000 stays unpublished. - The DB pool is capped at 20, because Postgres allows 100 connections in total. - **Database:** the role creates its own `keycloak` role and database and revokes PUBLIC, as billing does. - **Bootstrap:** the first start creates a temporary master-realm client from `KC_BOOTSTRAP_ADMIN_CLIENT_ID`/`SECRET`. #571 replaces it with a permanent client. An assert stops a first start that has no bootstrap secret. - **Caddy:** a vhost on `keycloak_domain` (`kc.stg.bitborg.se` on staging, where `auth.stg` stays on Kanidm for now). It is an allowlist: only `/realms/bitborg/*` and `/resources/*` are proxied, and everything else returns 404, including `/admin`, the master realm, `/metrics` and `/health`. The new rate-limit zones `keycloak` and `keycloak_credentials` (`POST login-actions/*` and the token endpoint) use the existing auth budgets. - **site.yml:** the role runs after kanidm. `keycloak` joins the health gate where it is enabled. - **Renovate:** regex versioning for `<keycloak version>-<n>` tags. Minors wait for dashboard approval. - **Runbook:** a Keycloak section (forward, first start, bootstrap replacement, break-glass, upgrades), the staging A record, the vault keys and the rate-limit zones. ## Verified - On the published image: the health script returns 1 before ready and 0 when ready. A read-only root with tmpfs starts. The bootstrap client gets a `client_credentials` token over plain HTTP. The heap maximum is about 718 MiB. - ansible-lint (production profile), `--syntax-check` against the staging inventory, the repo check scripts, the Renovate validator and shellcheck all pass. - With the flag off, the Caddyfile is byte-identical to `main`. With it on, the vhost validates in stock Caddy without the rate-limit block. ## Not verified (staging) - What source address the rootless port forward presents, and whether `sslRequired=external` accepts the token request through it. - Read-only root under rootless podman. - The rate-limit zones, which only `caddy validate` with the module checks. - That a second apply is idempotent and does not restart Keycloak. - Break-glass `bootstrap-admin user`. Refs #570
supernaut lade till 1 incheckning 2026-10-08 19:27:13 +00:00
feat(keycloak): add the keycloak role, database and caddy vhost behind keycloak_enabled
Alla kontroller lyckades
ci / ci (pull_request) Successful in 1m48s
53886564c1
Refs #570
supernaut schemalade den här ändringsförfrågan för automatisk sammanfogning när alla kontroller lyckas 2026-10-08 19:29:05 +00:00
supernaut sammanfogade incheckning 706bcc4356 till main 2026-10-08 19:29:36 +00:00
supernaut tog bort grenen feat/keycloak-role 2026-10-08 19:29:36 +00:00
Logga in för att delta i denna konversation.
Inga granskare
Ingen milstolpe
Inget projekt
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!599
Ingen beskrivning angiven.