feat(keycloak): run keycloak and its own postgres as bitborg-id behind a flag #709
Inga granskare
Etiketter
Inga etiketter
area/backups
area/ci
area/control-panel
area/identity
area/infra
area/observability
area/payments
area/security
area/storage
area/web
blocked
needs-info
needs-triage
priority
high
priority
low
priority
medium
ready-for-implementation
type
bug
type
chore
type
docs
type
epic
type
feature
type
task
wontfix
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Inget förfallodatum satt.
Beroenden
Inga beroenden satta
Referens
bitborg/bitborg-infra!709
Läser in…
Hänvisa till i nytt ärende
Ingen beskrivning angiven.
Ta bort grenen "feat/keycloak-isolation"
Borttagning av en gren är permanent. Även om den borttagna grenen kan fortsätta existera en kort tid innan den faktiskt tas bort, kan det INTE ångras i de flesta fall. Vill du fortsätta?
Refs #670
Moves Keycloak to its own rootless user,
bitborg-id, with its own PostgreSQL. This is the role change from ADR 0042. A flag gates it:keycloak_isolated, defaultfalse. With the default, every template renders byte-identical on prod and staging. No host changes until an environment sets the flag.Design
keycloak-postgresruns underbitborg-idon the internalbitborg-id-datanetwork. It is not published. It uses the shared Postgres image pin, so one Renovate bump moves both. Superuserpostgreswith the newvault_keycloak_postgres_password. Thekeycloakapp role owns thekeycloakdatabase and has no superuser rights.max_connections50,MemoryMax512M.Notify=healthywith a TCPpg_isready, so the start returns only after a first-run initdb.bitborg-idandbitborg-id-data, readskeycloak-postgres, and trusts forwarded headers from thebitborg-idsubnet. It publishes127.0.0.1:18080and10.90.0.1:8080/:9000as before, so Caddy, the portal, billing, vmagent, the reconciler, the health gate and the admin forward do not change.keycloak-postgrespublishes no ports, so it starts beside the old Keycloak. The role creates the role and database and restores the dump. Only then, and only when the Keycloak image is inbitborg-id's store, does it stop and remove the main user's Keycloak unit and config directory. A bad dump path, a failed restore or a failed pull leaves the old Keycloak in place. The old database and Podman secrets stay as the rollback copy. Dropping them is a later change.-e keycloak_restore_from=<dump>restores a custom-format dump withpg_restore --no-owner --no-privileges --role=keycloak --single-transaction. Guards:bitborg-idmust be able to read it (test -r, also in check mode);keycloak-postgreswithout a dump fails, whatevervault_keycloak_bootstrap_client_secretholds. That secret is empty in both vaults today, so the existing bootstrap assert already blocked this. The new guard keeps it blocked if the secret is ever set again.keycloak_os_unitsbecomeskeycloak-postgresandkeycloak. The main user's unit metrics and health-gate list dropkeycloak. The bitborg-id copies (from #687) pick both up. Alert names do not change.bitborg-id. Until then they would dump the stale shared copy. The backup handoff is the next change.Runbook
New section "Move Keycloak to bitborg-id": preconditions, a fresh dump, the cutover, verification and rollback. Staging first, then prod.
Proof that prod is unchanged
keycloak.container, bothbitborg-unit-metrics.shcopies and the computed lists (keycloak_os_units,monitoring_core_units,health_check_services,health_check_id_services,keycloak_internal_url,keycloak_config_dir) with the prod and staging inventories, atmainand at this branch. Identical for both hosts.gitborg, uid 2000, Postgrespostgresasforgejo, handlerReload bitborg user systemd.ansible-playbook site.yml --syntax-checkpasses for both inventories.ansible-lintpasses on theproductionprofile.--check --diff --tags keycloakwith the default flag:changed=0,failed=0.Staging preview (check mode)
--check --diff --tags keycloak,monitoring-agent -e keycloak_isolated=true, with a readable placeholder forkeycloak_restore_from(check mode never restores):changed=9,failed=0. In order, it pulls Postgres asbitborg-id, installs thekeycloak-pgdatavolume andkeycloak-postgresunits, creates the config dir and health script, and pulls Keycloak. Then it stops and removes the main user's Keycloak unit and config, and installs the new unit with the new networks, DB URL and trusted subnet.Guards seen on staging: without
keycloak_restore_fromthe run fails before any change. With a path that does not exist yet it fails at thetest -rcheck, also before any change.Operator steps
vault_keycloak_postgres_password, setkeycloak_isolated: trueingroup_vars/staging/vars.yml, then follow the runbook section. Reboot once.Not in this change
bitborg-id(next change). Prod waits for it.keycloakdatabase and role from the shared Postgres.