routeros: on-box judged rollback fuse (#74) #119

Merged
ginjiruu merged 7 commits from routeros-rollback-74b into master 2026-11-17 00:05:48 +00:00
Owner

Closes #74. Refs #98.

  • modules/rollback + rollback/after: a destroy-time guard arms a fuse before Terraform deletes anything; the normal arm takes it over as rollback-. The router judges with netwatch (http-get/dns/tcp-conn); all up -> commit, any down -> backup load + rolled-back- marker; judge error -> rollback + judge-error- marker, scheduler always removed. Re-apply guard, peer guard, early confirm. N = 600 s.
  • modules/www-cert: www-ssl issuance moved out of modules/router so a cert rotation re-arms (ADR-0009).
  • Secrets: none in state or plans from #74. Runner env ROUTEROS_PASSWORD, ROLLBACK_BACKUP_PASSWORD (12+), ROLLBACK_PEER_PASSWORD (routers). Wiring follows in lab/clusters.
  • Needs the lab runner image (bash, curl, jq, coreutils): harbor.animeteamspeak.moe/library/tf-runner:v0.16.6-lab.1.
  • docs/routeros/rollback.md: design, operation, env vars, air gap (ship code, not plans), remaining state secret (www-ssl key: vault 5.13 has no ephemeral PKI issue, routeros cert key not write-only).

Sim (CHR 7.25.1, scripts in an Alpine container with only bash/curl/jq/coreutils + tofu 1.12.1): PASS A good change, A2 early confirm, B bad change rolls back, C re-apply refused, D peer guard, E bench no-probe, F judge error, S no passwords in state/show -json/saved plan. .ids survive backup load. Not proven: real RB5009 timing, HTTPS path, air gap.

fmt, validate (3 roots + sim), routeros:guard, shellcheck pass. Rebased on master with #118; merges cleanly with #117.

Closes #74. Refs #98. - modules/rollback + rollback/after: a destroy-time guard arms a fuse before Terraform deletes anything; the normal arm takes it over as rollback-<hash>. The router judges with netwatch (http-get/dns/tcp-conn); all up -> commit, any down -> backup load + rolled-back-<hash> marker; judge error -> rollback + judge-error-<hash> marker, scheduler always removed. Re-apply guard, peer guard, early confirm. N = 600 s. - modules/www-cert: www-ssl issuance moved out of modules/router so a cert rotation re-arms (ADR-0009). - Secrets: none in state or plans from #74. Runner env ROUTEROS_PASSWORD, ROLLBACK_BACKUP_PASSWORD (12+), ROLLBACK_PEER_PASSWORD (routers). Wiring follows in lab/clusters. - Needs the lab runner image (bash, curl, jq, coreutils): harbor.animeteamspeak.moe/library/tf-runner:v0.16.6-lab.1. - docs/routeros/rollback.md: design, operation, env vars, air gap (ship code, not plans), remaining state secret (www-ssl key: vault 5.13 has no ephemeral PKI issue, routeros cert key not write-only). Sim (CHR 7.25.1, scripts in an Alpine container with only bash/curl/jq/coreutils + tofu 1.12.1): PASS A good change, A2 early confirm, B bad change rolls back, C re-apply refused, D peer guard, E bench no-probe, F judge error, S no passwords in state/show -json/saved plan. .ids survive backup load. Not proven: real RB5009 timing, HTTPS path, air gap. fmt, validate (3 roots + sim), routeros:guard, shellcheck pass. Rebased on master with #118; merges cleanly with #117.
The rollback arm re-runs when the cert serial changes, so a rotation is
armed like any other apply (ADR-0009). Every resource in modules/router
will wait for that arm, so issuing inside modules/router would be a graph
cycle. modules/www-cert holds vault_pki_secret_backend_cert;
modules/router/tls.tf keeps the device side (import + www-ssl binding) and
takes the leaf and key as inputs. moved blocks carry existing state over.
The #63 sim root and renewal-test.sh follow the new addresses.
terraform_data.arm (create-time) backs up the device and installs a judge
script plus a one-shot scheduler at device clock + N. At N the router
checks the netwatch probes that were up at arm time: all up commits, any
down writes rolled-back-<hash>.txt and loads the backup. A precondition
refuses a hash the router already rolled back; the arm refuses while the
peer is armed.

tofu destroys a removed object before it replaces what that object
depended on, so a create-time arm alone backs up too late for removals
(seen in the sim). rollback/after adds a guard that depends on the whole
device config; its destroy-time provisioner arms rollback-next first, and
the create-time arm adopts it. rollback/after also holds the early confirm.

The backup password lives in a disabled ppp secret: RouterOS logs script
sources and file contents in clear, but masks that field.

routeros/sim/rollback proves it on CHR 7.25.1 containers (run.sh).
Each root computes config_hash from its files, routeros/modules and its
inputs, calls modules/rollback, and puts depends_on = [module.rollback] on
module.router and module.recovery (crs309: on its three top resources).
rollback/after runs after the config. modules/router itself is unchanged.
New vars: rollback_delay (N, 600 s), rollback_backup_password, and on the
routers rollback_peer_host/rollback_peer_password.
The guard kept the arm settings, passwords included, in state because a
destroy-time provisioner can only read self. Now no secret goes through
tofu: arm.sh and confirm.sh read ROUTEROS_PASSWORD,
ROLLBACK_BACKUP_PASSWORD and ROLLBACK_PEER_PASSWORD from the runner
process environment, which local-exec inherits. State keeps endpoint,
user, N, probe names, hashes and the peer endpoint. The module drops its
password, backup_password and peer_password variables; the roots drop
rollback_backup_password and rollback_peer_password.

The sim root's provider reads ROS_PASSWORD, so it has no password
variable. run.sh scenario S greps both states, tofu show -json and a saved
plan for every sim password. RUNNER=1 runs tofu and the scripts in Alpine
with only bash, curl, jq and coreutils, the toolset of the lab runner image.
The judge body runs in :do { } on-error={ }. On any error nothing
confirmed the change, so the handler writes judge-error-<hash>.txt,
removes its scheduler first (a failed load cannot leave a spent fuse that
refuses every later arm), and loads the backup. Sim scenario F injects a
runtime :error into the installed judge and checks marker, scheduler,
restore and a later arm.
ginjiruu merged commit 9bb697dff9 into master 2026-11-17 00:05:48 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lab/iac!119
No description provided.