RouterOS: nightly drift detection against Terraform (no config backups) #72

Open
opened 2026-11-14 01:41:06 +00:00 by ginjiruu · 0 comments
Owner

Part of #43. Rewritten 2026-11-17: drift detection, not backup.

Premise

Routers are fungible. Every setting flows through the Terraform pipeline; anything the provider can't express gets added to the lab fork (lab/terraform-provider-routeros). The rest is code too: the protected set lives in routeros/bootstrap/bootstrap.rsc.tmpl plus OpenBao, and packages, device-mode and RouterBOARD firmware are bench-runbook steps (later #71). Device-generated state (SSH host keys, dynamic leases, conntrack, the PPPoE session) is disposable. Replacing a router is netinstall, then the bootstrap, then the render (#70), proven by the gate on all three devices. So nothing on a router needs a backup, and there are no blessed exports in git.

What this issue enforces is the rule: nobody changes a router outside the pipeline.

Shape

  1. Nightly comparison against Terraform. For each device: take the router's /export terse, normalize it (render.py normalize: one line per command, sorts only SORTABLE_MENUS, ordered menus copied, #67), and compare it with the render of the current root at master, normalized the same way. The reference is Terraform itself, the same comparison gate.sh makes, so there's no blessed copy to maintain. Out of scope: menus Terraform deliberately doesn't own (EXCLUDED_MENUS, the protected set) and the known-benign lines gate.sh already ignores. Any other difference raises an alert (Gotify, plus a metric for clusters#1722). This is also the "#008 round-trip" tail that #69 handed over.
  2. Real-time signal. Send RouterOS's system log (topics system,info, account) to VictoriaLogs. Alert whenever a config change is logged by a user other than terraform-* (RouterOS logs "... changed by "), and on any admin login, since admin is break-glass only.
  3. Coverage stays strict. render.py coverage already fails on objects in Terraform-owned menus that no resource holds. Run it in the nightly job too, so an object added by hand is caught even in a menu the export comparison normalizes.

Done when

  • The nightly job runs on mini against all three devices, using a read-only identity (the monitoring slots from #139 if their read policy is enough for /export, otherwise a dedicated read-only user on the same two-slot pattern).
  • A one-week trial catches a deliberate hand change, both nightly and in real time, and an admin login.
  • A false positive gets fixed in normalize or the ignore list, never by blessing an export.

Refs #67 (normalize), #69 (round-trip tail), #70 (render/gate), #139 (monitoring identity, mktxp), #147 (credentials).

Part of #43. Rewritten 2026-11-17: **drift detection, not backup.** ## Premise Routers are fungible. Every setting flows through the Terraform pipeline; anything the provider can't express gets added to the lab fork (`lab/terraform-provider-routeros`). The rest is code too: the protected set lives in `routeros/bootstrap/bootstrap.rsc.tmpl` plus OpenBao, and packages, `device-mode` and RouterBOARD firmware are bench-runbook steps (later #71). Device-generated state (SSH host keys, dynamic leases, conntrack, the PPPoE session) is disposable. Replacing a router is netinstall, then the bootstrap, then the render (#70), proven by the gate on all three devices. So nothing on a router needs a backup, and there are no blessed exports in git. What this issue enforces is the rule: **nobody changes a router outside the pipeline.** ## Shape 1. **Nightly comparison against Terraform.** For each device: take the router's `/export terse`, normalize it (`render.py normalize`: one line per command, sorts only `SORTABLE_MENUS`, ordered menus copied, #67), and compare it with the render of the current root at master, normalized the same way. The reference is Terraform itself, the same comparison `gate.sh` makes, so there's no blessed copy to maintain. Out of scope: menus Terraform deliberately doesn't own (`EXCLUDED_MENUS`, the protected set) and the known-benign lines `gate.sh` already ignores. Any other difference raises an alert (Gotify, plus a metric for clusters#1722). This is also the "#008 round-trip" tail that #69 handed over. 2. **Real-time signal.** Send RouterOS's system log (topics `system,info`, `account`) to VictoriaLogs. Alert whenever a config change is logged by a user other than `terraform-*` (RouterOS logs "... changed by <user>"), and on any `admin` login, since admin is break-glass only. 3. **Coverage stays strict.** `render.py coverage` already fails on objects in Terraform-owned menus that no resource holds. Run it in the nightly job too, so an object added by hand is caught even in a menu the export comparison normalizes. ## Done when - The nightly job runs on mini against all three devices, using a read-only identity (the monitoring slots from #139 if their `read` policy is enough for `/export`, otherwise a dedicated read-only user on the same two-slot pattern). - A one-week trial catches a deliberate hand change, both nightly and in real time, and an `admin` login. - A false positive gets fixed in `normalize` or the ignore list, never by blessing an export. Refs #67 (normalize), #69 (round-trip tail), #70 (render/gate), #139 (monitoring identity, mktxp), #147 (credentials).
ginjiruu changed title from RouterOS 010: Periodic /export backstop for unmanaged config to RouterOS: nightly drift detection against Terraform (no config backups) 2026-11-17 22:11:57 +00:00
Sign in to join this conversation.
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#72
No description provided.