Back up and drill-restore the Keycloak database #572

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

Cover the keycloak database in backups and the restore drill.

  • Add pg_dump of keycloak to bitborg-backup.sh.j2 and the hot job, beside the other databases.
  • Drill: restore the dump on scratch, start the same image, check /health/ready, count users, groups and clients.
  • Metrics bitborg_backup_drill_keycloak_{users,groups,clients}. Replace the Kanidm metrics and alert.
  • Remove the kanidmd database backup steps after cutover.

Done when: a drill restores Keycloak from backup and the metrics report non-zero counts.

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

Cover the `keycloak` database in backups and the restore drill. - [ ] Add `pg_dump` of `keycloak` to `bitborg-backup.sh.j2` and the hot job, beside the other databases. - [ ] Drill: restore the dump on scratch, start the same image, check `/health/ready`, count users, groups and clients. - [ ] Metrics `bitborg_backup_drill_keycloak_{users,groups,clients}`. Replace the Kanidm metrics and alert. - [ ] Remove the `kanidmd database backup` steps after cutover. Done when: a drill restores Keycloak from backup and the metrics report non-zero counts. Depends on: #570 Epic: bitborg/bitborg-docs#127
Upphovsperson
Ägare

Staging check, 2026-10-09. The full drill does not run on staging: site.yml limits the backup and backup-drill roles to prod, and staging has no backup bucket or drill credentials.

Replayed the Keycloak steps of bitborg-backup.sh.j2 and restore-on-scratch.sh.j2 by hand on staging, in a throwaway pod:

  • pg_dump --format=custom of keycloak: 281029 bytes.
  • Restored into a scratch postgres:17.11-trixie, started bitborg-keycloak:26.8.0-1 start --optimized on it.
  • /health/ready UP. Counts with the drill's SQL: users 9, groups 7, clients 21.
  • Pod removed, live Keycloak unaffected.

Not yet proven: off-site fetch and decrypt for the Keycloak dump, and the bitborg_backup_drill_keycloak_* metrics. Deferred to the first prod drill at cutover (#575). Also check there that the soundness check rejects groups=0.

Staging check, 2026-10-09. The full drill does not run on staging: `site.yml` limits the `backup` and `backup-drill` roles to prod, and staging has no backup bucket or drill credentials. Replayed the Keycloak steps of `bitborg-backup.sh.j2` and `restore-on-scratch.sh.j2` by hand on staging, in a throwaway pod: - `pg_dump --format=custom` of `keycloak`: 281029 bytes. - Restored into a scratch `postgres:17.11-trixie`, started `bitborg-keycloak:26.8.0-1 start --optimized` on it. - `/health/ready` UP. Counts with the drill's SQL: users 9, groups 7, clients 21. - Pod removed, live Keycloak unaffected. Not yet proven: off-site fetch and decrypt for the Keycloak dump, and the `bitborg_backup_drill_keycloak_*` metrics. Deferred to the first prod drill at cutover (#575). Also check there that the soundness check rejects `groups=0`.
Upphovsperson
Ägare

Decision 2026-10-10: the code part is done, and the live proof waits for the first prod drill after cutover.

Already on main:

  • keycloak.dump in the full backup, the hot backup and backup verify. All are gated by keycloak_enabled.
  • The drill restores the dump on the scratch VM, starts the pinned image, waits for ready, and counts users, groups and clients. It fails the drill on a zero count.
  • Metrics bitborg_backup_drill_keycloak_{users,groups,clients}. A failed Keycloak check fails the whole drill, so BackupDrillFailed covers it.

Staging cannot run the drill: it has no backup volume and no off-site destination.

Left for after cutover:

  • The first prod drill reports non-zero Keycloak counts.
  • Remove the Kanidm drill metrics, the Kanidm wording in BackupDrillFailed, and the kanidmd backup steps.
Decision 2026-10-10: the code part is done, and the live proof waits for the first prod drill after cutover. Already on `main`: - `keycloak.dump` in the full backup, the hot backup and backup verify. All are gated by `keycloak_enabled`. - The drill restores the dump on the scratch VM, starts the pinned image, waits for ready, and counts users, groups and clients. It fails the drill on a zero count. - Metrics `bitborg_backup_drill_keycloak_{users,groups,clients}`. A failed Keycloak check fails the whole drill, so `BackupDrillFailed` covers it. Staging cannot run the drill: it has no backup volume and no off-site destination. Left for after cutover: - [ ] The first prod drill reports non-zero Keycloak counts. - [ ] Remove the Kanidm drill metrics, the Kanidm wording in `BackupDrillFailed`, and the `kanidmd` backup steps.
Upphovsperson
Ägare

Staging drill, 2026-10-11.

The backup role does not apply to staging: backup_enabled: false in group_vars/staging/vars.yml, and the bitborg_env == 'prod' guard on backup and backup-drill in site.yml. Staging has no backup volume.

I ran the dump and restore by hand with the role's pg_dump --format=custom flags. The dump was 334 KiB and took under 1 s. The restore into a scratch DB took 2 s. The scratch DB was dropped afterwards.

Count Live Restored
users 15 15
groups 7 7
clients 21 21
realm roles 14 14
credentials 14 14

#652 makes the drill script also count realm roles and credentials and export them as metrics.

Not yet proven: the scripted drill end to end, with image start and /health/ready, and non-zero metrics from a real run. Both come from the first prod weekly drill after cutover.

Staging drill, 2026-10-11. The backup role does not apply to staging: `backup_enabled: false` in `group_vars/staging/vars.yml`, and the `bitborg_env == 'prod'` guard on `backup` and `backup-drill` in `site.yml`. Staging has no backup volume. I ran the dump and restore by hand with the role's `pg_dump --format=custom` flags. The dump was 334 KiB and took under 1 s. The restore into a scratch DB took 2 s. The scratch DB was dropped afterwards. | Count | Live | Restored | | --- | --- | --- | | users | 15 | 15 | | groups | 7 | 7 | | clients | 21 | 21 | | realm roles | 14 | 14 | | credentials | 14 | 14 | #652 makes the drill script also count realm roles and credentials and export them as metrics. Not yet proven: the scripted drill end to end, with image start and `/health/ready`, and non-zero metrics from a real run. Both come from the first prod weekly drill after cutover.
Upphovsperson
Ägare

Decision 2026-10-11: no staging backup volume. This issue closes when the first prod weekly drill after cutover reports non-zero Keycloak counts (users, groups, clients, realm roles, credentials) and passes the image start and /health/ready check.

Decision 2026-10-11: no staging backup volume. This issue closes when the first prod weekly drill after cutover reports non-zero Keycloak counts (users, groups, clients, realm roles, credentials) and passes the image start and `/health/ready` check.
Upphovsperson
Ägare

First prod restore drill after the Keycloak cutover, 2026-10-11, archive bitborg-20261011T120407Z: passed.

  • keycloak.dump restored with pg_restore on the scratch VM.
  • The pinned image bitborg-keycloak:26.8.0-5 started against it.
  • Counts: users 11, groups 7, clients 21, realm roles 14, credentials 2. All non-zero.
  • forgejo doctor: no errors. No Kanidm leg.

The close condition from the 2026-10-11 comment is met. Closing.

First prod restore drill after the Keycloak cutover, 2026-10-11, archive `bitborg-20261011T120407Z`: passed. - `keycloak.dump` restored with `pg_restore` on the scratch VM. - The pinned image `bitborg-keycloak:26.8.0-5` started against it. - Counts: users 11, groups 7, clients 21, realm roles 14, credentials 2. All non-zero. - `forgejo doctor`: no errors. No Kanidm leg. The close condition from the 2026-10-11 comment is met. Closing.
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#572
Ingen beskrivning angiven.