Keycloak realm, clients and service accounts in OpenTofu #571

Stängd
öppnade 2026-10-08 14:52:38 +00:00 av supernaut · 1 kommentar
Ägare

Define the whole bitborg realm declaratively with the keycloak/keycloak provider.

  • New root opentofu/keycloak/ with its own state and the same state encryption. Pin the provider. One var file per environment.
  • Realm: default locale sv, en enabled, registration off, reset password on, username not editable, no duplicate emails, verify email on, SSO session max 24 h, brute-force detection, login events 30 days, admin events on.
  • Policies: WebAuthn passwordless, OTP, password minimum length 10.
  • Required actions: CONFIGURE_TOTP, webauthn-register, webauthn-register-passwordless, CONFIGURE_RECOVERY_AUTHN_CODES, UPDATE_PASSWORD, UPDATE_EMAIL, VERIFY_EMAIL.
  • Browser flow: passkey as an alternative to password. After a password the second factor is required, so no password-only session exists. Reset flow: email link then reset password, no OTP reset step.
  • User profile: read-only username, email, one display name emitted as name.
  • Clients forgejo, bitborg-web, grafana (confidential, PKCE S256, secrets from vault) and bitborg-web-dev on staging only. Group-scoped access: forgejo_users for Forgejo and the portal, grafana_admins for Grafana.
  • Mappers: groups (bare names), entitlements (realm roles), preferred_username.
  • Groups tier_participant, tier_trial, tier_basic, tier_pro, forgejo_users, forgejo_admins, grafana_admins. Realm roles ent_runners_shared, ent_runners_priority, ent_runners_dedicated, ent_sso_entra, ent_orgs, ent_renovate. Tier groups carry the role mappings.
  • Service accounts with fine-grained admin permissions v2. bitborg-web-admin: create and read users, send action emails, manage membership of tier_participant, tier_trial, forgejo_users, map ent_renovate. bitborg-billing: manage tier_pro membership, map paid ent_* roles. bitborg-reconciler: read users, groups and roles. Never grant manage-users or view-users to a writer.
  • SMTP through the existing sending domain, password from vault. Swedish message overrides for the worst strings.
  • Health gate: the portal client can write each portal group. Negative check: it cannot write tier_pro.

Done when: tofu apply builds the realm on staging from scratch and a second plan is empty.

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

Define the whole `bitborg` realm declaratively with the `keycloak/keycloak` provider. - [ ] New root `opentofu/keycloak/` with its own state and the same state encryption. Pin the provider. One var file per environment. - [ ] Realm: default locale `sv`, `en` enabled, registration off, reset password on, username not editable, no duplicate emails, verify email on, SSO session max 24 h, brute-force detection, login events 30 days, admin events on. - [ ] Policies: WebAuthn passwordless, OTP, password minimum length 10. - [ ] Required actions: `CONFIGURE_TOTP`, `webauthn-register`, `webauthn-register-passwordless`, `CONFIGURE_RECOVERY_AUTHN_CODES`, `UPDATE_PASSWORD`, `UPDATE_EMAIL`, `VERIFY_EMAIL`. - [ ] Browser flow: passkey as an alternative to password. After a password the second factor is required, so no password-only session exists. Reset flow: email link then reset password, no OTP reset step. - [ ] User profile: read-only `username`, `email`, one display name emitted as `name`. - [ ] Clients `forgejo`, `bitborg-web`, `grafana` (confidential, PKCE S256, secrets from vault) and `bitborg-web-dev` on staging only. Group-scoped access: `forgejo_users` for Forgejo and the portal, `grafana_admins` for Grafana. - [ ] Mappers: `groups` (bare names), `entitlements` (realm roles), `preferred_username`. - [ ] Groups `tier_participant`, `tier_trial`, `tier_basic`, `tier_pro`, `forgejo_users`, `forgejo_admins`, `grafana_admins`. Realm roles `ent_runners_shared`, `ent_runners_priority`, `ent_runners_dedicated`, `ent_sso_entra`, `ent_orgs`, `ent_renovate`. Tier groups carry the role mappings. - [ ] Service accounts with fine-grained admin permissions v2. `bitborg-web-admin`: create and read users, send action emails, manage membership of `tier_participant`, `tier_trial`, `forgejo_users`, map `ent_renovate`. `bitborg-billing`: manage `tier_pro` membership, map paid `ent_*` roles. `bitborg-reconciler`: read users, groups and roles. Never grant `manage-users` or `view-users` to a writer. - [ ] SMTP through the existing sending domain, password from vault. Swedish message overrides for the worst strings. - [ ] Health gate: the portal client can write each portal group. Negative check: it cannot write `tier_pro`. Done when: `tofu apply` builds the realm on staging from scratch and a second plan is empty. Depends on: #570 Epic: bitborg/bitborg-docs#127
Upphovsperson
Ägare

Done on staging.

  • Realm root in opentofu/keycloak/ (#622), staging secrets (#623), plan-time lookups (#624).
  • Applied to staging. The bootstrap client is deleted and its secret dropped (#625). The root now authenticates as opentofu, and a second plan is empty.
  • --tags keycloak apply reconciled clean. A second --check gives changed=0. The health gate passes, including the negative tier_pro check.
  • SMTP proven: an action email to a temporary user was delivered, and the user was deleted.

Deviations from the list above, all documented in the runbook and the docs:

  • The reset flow requires an existing second factor. Email alone would give a session without one.
  • The direct grant flow is bound to a deny flow.
  • A new realm needs a targeted first apply of keycloak_realm.bitborg.
Done on staging. - Realm root in `opentofu/keycloak/` (#622), staging secrets (#623), plan-time lookups (#624). - Applied to staging. The bootstrap client is deleted and its secret dropped (#625). The root now authenticates as `opentofu`, and a second plan is empty. - `--tags keycloak` apply reconciled clean. A second `--check` gives `changed=0`. The health gate passes, including the negative `tier_pro` check. - SMTP proven: an action email to a temporary user was delivered, and the user was deleted. Deviations from the list above, all documented in the runbook and the docs: - The reset flow requires an existing second factor. Email alone would give a session without one. - The direct grant flow is bound to a deny flow. - A new realm needs a targeted first apply of `keycloak_realm.bitborg`.
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#571
Ingen beskrivning angiven.