RouterOS 005: Firewall rule ordering convention #67
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
lab/iac#67
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of #43
Refs: lab/iac#45
Migrated from router-as-code tracker 005 (docs/routeros/tracker in this repo history). Research notes: docs/routeros/notes/.
Ordered menus (firewall filter/nat/mangle, bridge filter) are the one place
where Terraform's object-set model and RouterOS's ordered-list model grind.
Decide the lab convention before writing the first rule, because it also
constrains the boot-script compiler (#007). Findings in note §2, verified in
provider source.
The tools and their teeth
place_before: real attribute on those resources, but ForceNew + write-onlywith the firewall data source. Reordering churn = rule destroy/create, and a
created-into-position rule that later gets a reordered neighbour re-creates.
routeros_move_items: reorders existing items by ID sequence; read-backcarries an author TODO warning it misses cases. Treat as a janitor, not the
mechanism.
Candidate conventions
place_beforechains off a data source (provider-native, churn-prone).when chains are small and purpose-built.
comment="010-allow-wireguard-mgmt") as the human-orderintent, rules otherwise independent; compiler (#007) sorts by the number and
emits in that order — order guaranteed at boot, and day-2 edits to rule
bodies don't reorder anything.
Default lean: 3 for the compiler's determinism plus 2 to keep chains small;
decide hands-on in sim (#001) with a 15-rule chain that must be reordered, and
record the winner as an ADR-lite section here.
Done when
live apply), written into the terraform tree's README.
Status 2026-11-17: the renderer emits ordered firewall chains and the gate enforces ordering on every render (24-rule chain loaded rb5009-a; sim proved .ids survive backup load, #74). BUT done-when wants the convention written into the tree README - docs/routeros/README.md currently only carries the issue-map table row, no convention section. Review: adopt what the renderer already does and document it, or leave for #71/#72 work. Marking ready-for-human.
Read akpw/mktxp in full (HEAD 6c2311d). Premise correction: mktxp is not a Go apply CLI and has no terraform-like write path. It is a Python exporter/GitOps toolkit whose
rscmodule does live/export-> AST -> normalize ->format/split, device-to-git only (mktxp/rsc/dispatcher.py:36-40registers exactly two actions; no apply, no state, no router writes in the tree). It did not solve ordering on apply; it dodged the problem by never applying anything and treats the device's order as the record. That is itself data here: nobody in this niche has made placement work, and the surviving tools all treat export order as load order.What mktxp does encode, worth borrowing:
/ip(v6) firewall {filter,nat,mangle,raw},/ip(v6) route,/routing rule,/interface bridge port,/interface bridge vlan,/ip dhcp-server lease. Inside those, top-down order is copied, never sorted; every other menu is alphabetized by a fixed key ladder (target/find-expr, list+interface, name, interface, address) for zero-jitter diffs (rsc/middleware/sorter.py:19-78, pinned bytests/rsc/test_sorter.py).01-base ... 06-firewall ... 99-other, longest-prefix path match, user-extendable in config (rsc/handlers/chain.py:21-170); filename numbers ARE load order.comment=is never a sort key or placement input anywhere. No numbered-comment idiom exists there, so candidate 3 in this issue remains our own invention (mktxp-compatible, but not validated by it).99-other.rsc, volatile fields (bridgemac-addressunderauto-mac=yes) are sanitized (rsc/middleware/sanitizer.py:26-37).The convention, now written into docs/routeros/README.md by PR #134, absorbing the above:
place_beforeanywhere. Ordered menus are mktxp's list plus/interface bridge filter(their list misses it; the provider places there)."<chain>: <purpose> [tf:<key>]", comma-free (REST import-key constraint). Step-10 numbers enter with #69: the compiler is the first tool needing a total order fromplanned_valuesalone; until then numbers would be documentation only, and adding them later is a cheap commentupdate, never destroy/create.routeros_move_itemsstays the janitor: one per chain, declared ID order, gate-allowlisted create that provably moves nothing; the provider's read-back TODO is covered by gate.sh byte-comparing the export, not by trusting it.render.py normalizegained mktxp's unordered-menu sort (ORDERED_MENUS+SORT_LADDER) so gate comparisons and #72 diffs are jitter-free. #72 can additionally vendormktxp rsc splititself (GPL-2, cron-ready) instead of the port.Full citations with path:line: docs/routeros/notes/2026-11-17-mktxp-patterns.md (in PR #134).
Done in #134: convention in docs/routeros/README.md (declared order = device order = render order; one move_items per chain; comments as import keys + metric identity), sim-proven reorder (routeros/sim/ordering/run.sh, re-run PASS on provider 1.99.1004 after the rebase), normalize sorts only SORTABLE_MENUS. mktxp notes: docs/routeros/notes/2026-11-17-mktxp-patterns.md.