RouterOS 007: Boot-script compiler from planned values (route A) #69

Closed
opened 2026-11-14 01:41:05 +00:00 by ginjiruu · 5 comments
Owner

Part of #43

Refs: lab/iac#45
Migrated from router-as-code tracker 007 (docs/routeros/tracker in this repo history). Research notes: docs/routeros/notes/.

The tool that turns Terraform truth into the factory .rsc for each device,
so reset/netinstall lands the device at plan-equivalent state. Full design
in note §5; this issue is the build list.

Components

  1. Path table code-gen: grep PropResourcePath over the pinned provider
    source → resource_type → {menu path, add|set kind, computed fields}.
    Checked-in generated file, regenerate on provider bump (the bump MR fails
    its own diff if the table drifts).
  2. Renderer: terraform plan -out → terraform show -json → iterate
    planned_values.root_module.resources; drop computed/read-only fields;
    add k=v ... for managed objects, set [find name=...] for setters of
    pre-existing entries; hard-error on any value unknown-at-plan (render
    must be total, never a script with holes).
  3. Ordering: canonical /export menu order across sections; within ordered
    menus, the #005 convention (numbered-comment sort, or place_before
    topo-sort — whichever #005 decides).
  4. Template: boot.tmpl = preamble (bootstrap #002 content, cert/NTP
    waits budgeted to 120 s, secret injection from vars) + rendered sections +
    postscript footer (enable bridge vlan-filtering=yes last, same trick the
    site renderer used).
  5. Taskfile: task boot-one DEVICE=..., task boot-all, golden cmp
    against golden/ committed renders.

Non-negotiables

  • Protected set lives in the template preamble only (no mgmt/www-ssl objects
    in the Terraform graph, so the compiler can't emit them anyway — enforce
    with a guard that fails on those resource types).
  • Output must pass the sim import test in #008 before any render is trusted.

Done when

  • task boot-all renders three byte-stable scripts; CI diff on every HCL
    change; #008 round-trip green in the pipeline.
Part of #43 Refs: lab/iac#45 Migrated from router-as-code tracker 007 (docs/routeros/tracker in this repo history). Research notes: docs/routeros/notes/. The tool that turns Terraform truth into the factory `.rsc` for each device, so reset/netinstall lands the device at `plan`-equivalent state. Full design in note §5; this issue is the build list. ## Components 1. **Path table code-gen**: `grep PropResourcePath` over the pinned provider source → `resource_type → {menu path, add|set kind, computed fields}`. Checked-in generated file, regenerate on provider bump (the bump MR fails its own diff if the table drifts). 2. **Renderer**: `terraform plan -out` → `terraform show -json` → iterate `planned_values.root_module.resources`; drop computed/read-only fields; `add k=v ...` for managed objects, `set [find name=...]` for setters of pre-existing entries; **hard-error on any value unknown-at-plan** (render must be total, never a script with holes). 3. **Ordering**: canonical /export menu order across sections; within ordered menus, the #005 convention (numbered-comment sort, or place_before topo-sort — whichever #005 decides). 4. **Template**: `boot.tmpl` = preamble (bootstrap #002 content, cert/NTP waits budgeted to 120 s, secret injection from vars) + rendered sections + postscript footer (enable bridge `vlan-filtering=yes` last, same trick the site renderer used). 5. **Taskfile**: `task boot-one DEVICE=...`, `task boot-all`, golden `cmp` against `golden/` committed renders. ## Non-negotiables - Protected set lives in the template preamble only (no mgmt/www-ssl objects in the Terraform graph, so the compiler can't emit them anyway — enforce with a guard that fails on those resource types). - Output must pass the sim import test in #008 before any render is trusted. ## Done when - `task boot-all` renders three byte-stable scripts; CI diff on every HCL change; #008 round-trip green in the pipeline.
Author
Owner

Elevated by #73 cutover plan: the rendered full boot .rsc is the cutover artifact (controller sits behind the router being replaced). Not optional.

Elevated by #73 cutover plan: the rendered full boot .rsc is the cutover artifact (controller sits behind the router being replaced). Not optional.
Author
Owner

ADR-0009 (2026-11-14): the boot template no longer self-signs. The renderer fetches the router's www-ssl cert+key from OpenBao (pki-net-caosh/routeros, #85) and embeds /certificate import + the www-ssl binding. The render must hard-fail when OpenBao is unreachable (never fall back to self-signed). The output holds a private key: treat it as a secret, keep it out of golden/ as plaintext (golden diffs use a placeholder for the PEM blocks). Cert objects and the www-ssl certificate binding move out of the protected set (Terraform renews them), see #64.

ADR-0009 (2026-11-14): the boot template no longer self-signs. The renderer fetches the router's `www-ssl` cert+key from OpenBao (`pki-net-caosh`/`routeros`, #85) and embeds `/certificate import` + the `www-ssl` binding. The render must hard-fail when OpenBao is unreachable (never fall back to self-signed). The output holds a private key: treat it as a secret, keep it out of `golden/` as plaintext (golden diffs use a placeholder for the PEM blocks). Cert objects and the `www-ssl` certificate binding move out of the protected set (Terraform renews them), see #64.
Author
Owner

Status 2026-11-17: the compiler core exists as render.py + render/*.sh + the import gate (#70/#117): planned_values -> ordered /rsc, hard-error on unknowns, secrets injected only at render time, proven on all three devices (209-rule hardware plan PASS, reset-slot replay ~60s). Gaps vs done-when: golden/ byte-stable cmp + CI diff on HCL change not implemented; #008 round-trip not wired into a pipeline. Big chunk done, tail is CI work. ready-for-human to decide if the CI tail is worth keeping open or folds into #71/#72.

Status 2026-11-17: the compiler core exists as render.py + render/*.sh + the import gate (#70/#117): planned_values -> ordered /rsc, hard-error on unknowns, secrets injected only at render time, proven on all three devices (209-rule hardware plan PASS, reset-slot replay ~60s). Gaps vs done-when: golden/ byte-stable cmp + CI diff on HCL change not implemented; #008 round-trip not wired into a pipeline. Big chunk done, tail is CI work. ready-for-human to decide if the CI tail is worth keeping open or folds into #71/#72.
Author
Owner

Done 2026-11-17 per owner: compiler core shipped (render.py + render/*.sh + import gate + move_items ordering; proven on all three devices, 209-rule plan PASS, reset-slot replay ~60s). Remaining CI tail folds: path-table golden/byte-stable cmp + 'regenerate on provider bump' diff lands with the upgrade flow #71 (it is exactly the provider-bump test); the #008 /export round-trip gate lands with the export backstop #72 (same oracle). Comment here with 'golden'/'round-trip' keywords stays findable from both.

Done 2026-11-17 per owner: compiler core shipped (render.py + render/*.sh + import gate + move_items ordering; proven on all three devices, 209-rule plan PASS, reset-slot replay ~60s). Remaining CI tail folds: path-table golden/byte-stable cmp + 'regenerate on provider bump' diff lands with the upgrade flow #71 (it is exactly the provider-bump test); the #008 /export round-trip gate lands with the export backstop #72 (same oracle). Comment here with 'golden'/'round-trip' keywords stays findable from both.
Author
Owner

Settled 2026-11-17 (#67/#134, #139): no step-10 numbers in rule comments.

  • Order is the position of the rule in the module's list (modules/router/firewall.tf). The render reproduces it and routeros_move_items enforces it. Neither ever reads a number, so a number would only be a second copy of the order that can drift from the first.
  • Identity is the [tf:<key>] suffix. It is the import key (comma-free, #70) and, since #139, the Prometheus series label for per-rule counters (mktxp firewall_filter_total{name="| chain | action | comment"}). So a key never changes once a rule exists. Renaming one splits the rule's history.
  • The comment text before the suffix (<chain>: <purpose>) is for humans. Editing it is a comment-only plan (sim step 6), but it also renames the series, so treat it as stable too.
  • Reordering is free: one move_items update, every .id kept, no label change (sim step 2).

The CI tail stays where the earlier comment put it: the golden/provider-bump test with #71, the round-trip with #72.

**Settled 2026-11-17 (#67/#134, #139): no step-10 numbers in rule comments.** - **Order** is the position of the rule in the module's list (`modules/router/firewall.tf`). The render reproduces it and `routeros_move_items` enforces it. Neither ever reads a number, so a number would only be a second copy of the order that can drift from the first. - **Identity** is the `[tf:<key>]` suffix. It is the import key (comma-free, #70) and, since #139, the Prometheus series label for per-rule counters (mktxp `firewall_filter_total{name="| chain | action | comment"}`). So a key never changes once a rule exists. Renaming one splits the rule's history. - **The comment text** before the suffix (`<chain>: <purpose>`) is for humans. Editing it is a comment-only plan (sim step 6), but it also renames the series, so treat it as stable too. - **Reordering** is free: one `move_items` update, every `.id` kept, no label change (sim step 2). The CI tail stays where the earlier comment put it: the golden/provider-bump test with #71, the round-trip with #72.
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#69
No description provided.