fix(opentofu): keep instances on a key change, narrow the opentofu client scope #826

Sammanfogat
supernaut sammanfogade 3 incheckningar från fix/tofu-instances-and-master-scope in i main 2026-10-19 22:53:16 +00:00
Ägare

Closes #611. Closes #800.

#611: a key change no longer replaces the instances

ssh_public_key reaches the instances only through user_data, which is ForceNew. The prod,
monitoring and staging instances now ignore user_data changes. The keypair resource still takes
the new key: Nova reads it at boot, and the instances refer to it by name, so it does not force a
replace. The runbook has a new section, "Rotate the admin SSH key", that rotates through the
Ansible authorized_key module.

A deliberate rebuild with new cloud-init now needs -replace.

#800: full scope off on the master-realm opentofu client

full_scope_allowed = false, and a keycloak_generic_role_mapper maps the master admin
composite into the client scope. That composite holds every realm's admin roles, so the provider,
the admin_token lookup and the keycloak role's admin-events call keep their access.

Keycloak checks the client scope on every admin call. One apply would flip the flag before it
creates the mapping, and -target on the mapping applies the client change too. So the runbook
("The opentofu client scope") adds the mapping over the API first. It also describes a repair
path through a temporary bootstrap-opentofu service client, created with
kc.sh bootstrap-admin service (Keycloak 26.8).

No workflow applies opentofu/keycloak. CI only runs fmt and validate, so nothing applies the
flag before the operator adds the mapping.

Checks

  • tofu fmt -check -recursive in opentofu/: clean.
  • tofu validate in opentofu/ and opentofu/keycloak/ (fresh init -backend=false): valid.
  • prettier and markdownlint on docs/runbook.md: clean.

Operator steps

  • #611: pnpm tofu:plan against prod state shows no changes to the three instances.
  • #611: optional proof: plan with a changed ssh_public_key. Only
    openstack_compute_keypair_v2.bitborg is replaced.
  • #800 staging: add the scope mapping over the API (runbook, "The opentofu client scope").
  • #800 staging: full realm plan and apply. A second tofu plan -detailed-exitcode exits 0.
  • #800 staging: run --tags keycloak and the health gate. Both still pass.
  • #800 staging: Loki shows no "Full scope allowed" warning for opentofu.
  • #800 prod: the same four steps.
Closes #611. Closes #800. ## #611: a key change no longer replaces the instances `ssh_public_key` reaches the instances only through `user_data`, which is ForceNew. The prod, monitoring and staging instances now ignore `user_data` changes. The keypair resource still takes the new key: Nova reads it at boot, and the instances refer to it by name, so it does not force a replace. The runbook has a new section, "Rotate the admin SSH key", that rotates through the Ansible `authorized_key` module. A deliberate rebuild with new cloud-init now needs `-replace`. ## #800: full scope off on the master-realm `opentofu` client `full_scope_allowed = false`, and a `keycloak_generic_role_mapper` maps the master `admin` composite into the client scope. That composite holds every realm's admin roles, so the provider, the `admin_token` lookup and the keycloak role's admin-events call keep their access. Keycloak checks the client scope on every admin call. One apply would flip the flag before it creates the mapping, and `-target` on the mapping applies the client change too. So the runbook ("The `opentofu` client scope") adds the mapping over the API first. It also describes a repair path through a temporary `bootstrap-opentofu` service client, created with `kc.sh bootstrap-admin service` (Keycloak 26.8). No workflow applies `opentofu/keycloak`. CI only runs `fmt` and `validate`, so nothing applies the flag before the operator adds the mapping. ## Checks - `tofu fmt -check -recursive` in `opentofu/`: clean. - `tofu validate` in `opentofu/` and `opentofu/keycloak/` (fresh `init -backend=false`): valid. - prettier and markdownlint on `docs/runbook.md`: clean. ## Operator steps - [ ] #611: `pnpm tofu:plan` against prod state shows no changes to the three instances. - [ ] #611: optional proof: plan with a changed `ssh_public_key`. Only `openstack_compute_keypair_v2.bitborg` is replaced. - [ ] #800 staging: add the scope mapping over the API (runbook, "The `opentofu` client scope"). - [ ] #800 staging: full realm plan and apply. A second `tofu plan -detailed-exitcode` exits 0. - [ ] #800 staging: run `--tags keycloak` and the health gate. Both still pass. - [ ] #800 staging: Loki shows no "Full scope allowed" warning for `opentofu`. - [ ] #800 prod: the same four steps.
supernaut lade till 3 incheckningar 2026-10-19 19:09:04 +00:00
ssh_public_key is rendered into user_data, which is ForceNew. A key
rotation planned a rebuild of prod and monitoring, and cloud-init on the
kept root disk would only have appended the new key. Rotate the key with
Ansible instead, as the runbook now describes. Staging gets the same
lifecycle rule so the shared variable cannot rebuild it either.

Closes #611
Keycloak warns on every token request from a full-scope client and will
drop the switch. The client scope now maps the master admin composite,
which still covers every realm's admin roles.

Admin calls check the scope live, and one apply would flip the flag
before it creates the mapping. The runbook adds the mapping over the API
first and keeps a repair path through a temporary bootstrap client.

Closes #800
docs(runbook): spell out the key-rotation and scope-recovery commands
Alla kontroller lyckades
ci / ci (pull_request) Successful in 8m44s
d51fcb7fdc
The scope recovery now gives the exact bootstrap-admin service run for
Keycloak 26.8, with the secret passed through the environment. The key
rotation covers staging, names the private-key setting, says when the old
key may go, and notes that ignored user_data needs -replace.

Refs #611
Refs #800
supernaut sammanfogade incheckning b409645c8e till main 2026-10-19 22:53:16 +00:00
supernaut tog bort grenen fix/tofu-instances-and-master-scope 2026-10-19 22:53:17 +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!826
Ingen beskrivning angiven.