Router config as OpenTofu (terraform-routeros) via tofu-controller #45

Closed
opened 2026-11-05 16:59:34 +00:00 by ginjiruu · 2 comments
Owner

Part of lab/iac#43.

Chosen over the KCL->rsc->netinstall pattern after an independent review: incremental changes over the RouterOS REST API, tofu plan as drift detection, broad coverage (firewall, NAT, DHCP, DNS, WireGuard, BGP, PoE, bridge VLANs), native fit for the existing tofu-controller. nix-routeros is too thin to depend on (no VLAN/WireGuard/BGP modules).

Caveats from the review: existing singletons need import blocks or *_settings resources; ordered firewall rules need place_before/routeros_move_items; state holds secrets (encrypt it; OpenBao later); keep a periodic /export diff as a backstop for unmanaged config.

Done when

  • Full router config in git, applied by tofu-controller, plan clean
  • Migration from ER-X done with the DNS/DHCP behaviour from the internal-network epic
Part of lab/iac#43. Chosen over the KCL->rsc->netinstall pattern after an independent review: incremental changes over the RouterOS REST API, `tofu plan` as drift detection, broad coverage (firewall, NAT, DHCP, DNS, WireGuard, BGP, PoE, bridge VLANs), native fit for the existing tofu-controller. nix-routeros is too thin to depend on (no VLAN/WireGuard/BGP modules). Caveats from the review: existing singletons need `import` blocks or `*_settings` resources; ordered firewall rules need `place_before`/`routeros_move_items`; state holds secrets (encrypt it; OpenBao later); keep a periodic `/export` diff as a backstop for unmanaged config. ## Done when - [ ] Full router config in git, applied by tofu-controller, `plan` clean - [ ] Migration from ER-X done with the DNS/DHCP behaviour from the internal-network epic
Author
Owner

Migration inventory: what the ER-X (edge-01 / lab-erx-01, EdgeRouter X SFP, EdgeOS 3.0.1) runs today. Read-only pull of show configuration commands plus live state, 2026-11-06. Secrets left out.

WAN

  • eth0: PPPoE, untagged (no VLAN 35), 1G, MTU 1492, MSS clamp 1452 (firewall options mss-clamp interface-type pppoe). Session stable 5d+.
  • NAT: masquerade out pppoe0 (rule 5010). Hardware NAT offload on.
  • dhcpv6-pd on eth0 is dead config: Bell has no residential IPv6.
  • Firewall: WAN_IN / WAN_LOCAL = allow established/related, drop invalid, default drop. IPv6 equivalents unused.

LAN (switch0, VLAN-aware, eth1-eth4)

VLAN Subnet Gateway Contents
untagged 10.15.1.0/24 .1 mini-01 .170, arch-ws .87, truenas .204, technitium-01 .203, lab-sw-01 .38, Nextcloud .47, cameras
1000 PI-network 10.10.1.0/24 .1 pi-01..04 .11-.14, think-01..03 .21-.23, lab-poesw-01 .32, old portable-* VMs
1001 Management 10.16.1.0/26 .1 asrock-mgt1 .8, asusbc-rtl8117 .6, truenas .3, nextcloud .4, pihole .12
1002 workload 172.16.0.0/16 .1 Proxmox-era VMs (rke2-deb-*, gitaly, mysql, redis, ipa-01, haproxy, wireguard-01...), mostly stale
1101 Noah Network 10.69.0.0/20 .1 separate household network

Port roles: eth1, eth3 trunk all VLANs; eth2, eth4 PVID 1001 (Management untagged) + tagged others; eth2 no link.

Keep these subnets on the RB5009s. OpenBao TLS, Raft retry_join and AppRole secret_id_bound_cidrs (lab/machine-configs#3, #8) bind to host addresses; same subnets = router-agnostic.

DHCP (dnsmasq)

  • Static leases for every lab host above (thinks, Pis, mini, arch-ws, BMCs, NAS). Carry all live ones.
  • DNS handed out: public resolvers (1.1.1.1/8.8.8.8, Pi net 8.8.4.4/8.8.8.8). The router's DNS forwarder listens on every VLAN but no client uses it. lab/machine-configs#16 (hand out 10.10.5.53, forward int.) is not implemented; do it here instead of on EdgeOS.
  • LAN carries option 43 for a UniFi controller at 10.10.5.5.
  • Pi net PXE: bootfile-server 10.10.2.4, pxelinux.0. Nothing routes 10.10.2.x.

Routing

  • BGP AS 64512, router-id 10.15.1.1.
    • mini-01 10.15.1.170 AS 64516: Established, 21 prefixes (LB 10.10.6.x/32, 10.44.0.0/24).
    • think/Pi 10.10.1.11-14, .21-23 AS 64515: never connected (lab/clusters#1672 not done).
    • 172.16.0.51-53, .61 AS 64514: old cluster, dead.
  • Static 10.8.0.0/24 via 10.10.5.7 (wireguard-kube, distance 2): 10.10.5.7 is not on any connected network, so it resolves via the default route out pppoe0. Broken.
  • PBR PBR_MAIL_REDIRECT on switch0: TCP to mail ports from 10.10.1.0/24 -> table 1 -> default via 37.59.107.172 (OVH VPS). Next hop is not on a connected network; probably falls through. Untested.

Port forwards (WAN pppoe0, hairpin NAT on, auto-firewall on)

# Name Ports Target State
1 web 80,443 10.10.6.14 live (mini LB)
2 wireguard 51820 10.10.6.18 live
3 forgejo-ssh 22 10.10.6.19 live
4 Valheim 2456-2457 10.10.6.10 live
5 azuracast 8000-8499 10.15.1.148 check
6 teamspeak 9987,30033 10.10.6.11 live
7 mail 25,143,587,465,993 10.10.5.9 dead (10.10.5.x unrouted)
8 nats-leaf 4222,7422 10.10.6.30 live
9 teamspeak6-voice 9988->9987 10.10.6.12 live
10 teamspeak6-files 30034->30033 10.10.6.12 live
11 turn 5349 10.10.5.21 dead
12 ldaps 636 10.10.6.14 live
13 iperf 5201 10.16.1.6 check (exposes a mgmt-VLAN host)

All forwards are tcp_udp regardless of service.

Services on the router

SSH on 1023, GUI 8080/8443 with older-ciphers, SNMP v2 community lab ro on 10.15.1.1, UPnP on switch0, syslog to 10.10.6.1, NTP ubnt pool, DPI + traffic analysis on, UNMS disabled (stale connection string in config).

Fix in the new config, do not copy

  1. User ramen: admin with a plaintext password stored in config. Drop it; key-only admin.
  2. No inter-VLAN firewall. Noah Network, workload and old VMs reach thinks, Pis and Management. Add zone policy: Management reachable only from admin hosts; Noah isolated from lab VLANs.
  3. Dead: static 10.8.0.0/24, forwards 7 and 11, AS 64514 peers, dhcpv6-pd, ipa-01 static host mapping, Pi PXE server 10.10.2.4, UNMS string.
  4. Noah DHCP DNS 4.4.4.4 is not a public resolver (8.8.4.4 intended?).
  5. Decide whether VLAN 1002 workload still has live hosts before carrying it.
  6. UPnP and GUI older ciphers off.
Migration inventory: what the ER-X (`edge-01` / `lab-erx-01`, EdgeRouter X SFP, EdgeOS 3.0.1) runs today. Read-only pull of `show configuration commands` plus live state, 2026-11-06. Secrets left out. ## WAN - eth0: PPPoE, **untagged** (no VLAN 35), 1G, MTU 1492, MSS clamp 1452 (`firewall options mss-clamp interface-type pppoe`). Session stable 5d+. - NAT: masquerade out `pppoe0` (rule 5010). Hardware NAT offload on. - `dhcpv6-pd` on eth0 is dead config: Bell has no residential IPv6. - Firewall: `WAN_IN` / `WAN_LOCAL` = allow established/related, drop invalid, default drop. IPv6 equivalents unused. ## LAN (switch0, VLAN-aware, eth1-eth4) | VLAN | Subnet | Gateway | Contents | |---|---|---|---| | untagged | 10.15.1.0/24 | .1 | mini-01 .170, arch-ws .87, truenas .204, technitium-01 .203, lab-sw-01 .38, Nextcloud .47, cameras | | 1000 PI-network | 10.10.1.0/24 | .1 | pi-01..04 .11-.14, think-01..03 .21-.23, lab-poesw-01 .32, old portable-* VMs | | 1001 Management | 10.16.1.0/26 | .1 | asrock-mgt1 .8, asusbc-rtl8117 .6, truenas .3, nextcloud .4, pihole .12 | | 1002 workload | 172.16.0.0/16 | .1 | Proxmox-era VMs (rke2-deb-*, gitaly, mysql, redis, ipa-01, haproxy, wireguard-01...), mostly stale | | 1101 Noah Network | 10.69.0.0/20 | .1 | separate household network | Port roles: eth1, eth3 trunk all VLANs; eth2, eth4 PVID 1001 (Management untagged) + tagged others; eth2 no link. **Keep these subnets on the RB5009s.** OpenBao TLS, Raft `retry_join` and AppRole `secret_id_bound_cidrs` (lab/machine-configs#3, #8) bind to host addresses; same subnets = router-agnostic. ## DHCP (dnsmasq) - Static leases for every lab host above (thinks, Pis, mini, arch-ws, BMCs, NAS). Carry all live ones. - DNS handed out: public resolvers (1.1.1.1/8.8.8.8, Pi net 8.8.4.4/8.8.8.8). The router's DNS forwarder listens on every VLAN but no client uses it. lab/machine-configs#16 (hand out 10.10.5.53, forward `int.`) is not implemented; do it here instead of on EdgeOS. - LAN carries option 43 for a UniFi controller at 10.10.5.5. - Pi net PXE: `bootfile-server 10.10.2.4`, `pxelinux.0`. Nothing routes 10.10.2.x. ## Routing - BGP AS 64512, router-id 10.15.1.1. - mini-01 10.15.1.170 AS 64516: **Established**, 21 prefixes (LB `10.10.6.x/32`, `10.44.0.0/24`). - think/Pi 10.10.1.11-14, .21-23 AS 64515: never connected (lab/clusters#1672 not done). - 172.16.0.51-53, .61 AS 64514: old cluster, dead. - Static `10.8.0.0/24 via 10.10.5.7` (wireguard-kube, distance 2): 10.10.5.7 is not on any connected network, so it resolves via the default route out `pppoe0`. Broken. - PBR `PBR_MAIL_REDIRECT` on switch0: TCP to mail ports from 10.10.1.0/24 -> table 1 -> default via 37.59.107.172 (OVH VPS). Next hop is not on a connected network; probably falls through. Untested. ## Port forwards (WAN `pppoe0`, hairpin NAT on, auto-firewall on) | # | Name | Ports | Target | State | |---|---|---|---|---| | 1 | web | 80,443 | 10.10.6.14 | live (mini LB) | | 2 | wireguard | 51820 | 10.10.6.18 | live | | 3 | forgejo-ssh | 22 | 10.10.6.19 | live | | 4 | Valheim | 2456-2457 | 10.10.6.10 | live | | 5 | azuracast | 8000-8499 | 10.15.1.148 | check | | 6 | teamspeak | 9987,30033 | 10.10.6.11 | live | | 7 | mail | 25,143,587,465,993 | 10.10.5.9 | **dead** (10.10.5.x unrouted) | | 8 | nats-leaf | 4222,7422 | 10.10.6.30 | live | | 9 | teamspeak6-voice | 9988->9987 | 10.10.6.12 | live | | 10 | teamspeak6-files | 30034->30033 | 10.10.6.12 | live | | 11 | turn | 5349 | 10.10.5.21 | **dead** | | 12 | ldaps | 636 | 10.10.6.14 | live | | 13 | iperf | 5201 | 10.16.1.6 | check (exposes a mgmt-VLAN host) | All forwards are `tcp_udp` regardless of service. ## Services on the router SSH on 1023, GUI 8080/8443 with `older-ciphers`, SNMP v2 community `lab` ro on 10.15.1.1, UPnP on switch0, syslog to 10.10.6.1, NTP ubnt pool, DPI + traffic analysis on, UNMS disabled (stale connection string in config). ## Fix in the new config, do not copy 1. User `ramen`: admin with a **plaintext password stored in config**. Drop it; key-only admin. 2. **No inter-VLAN firewall.** Noah Network, workload and old VMs reach thinks, Pis and Management. Add zone policy: Management reachable only from admin hosts; Noah isolated from lab VLANs. 3. Dead: static 10.8.0.0/24, forwards 7 and 11, AS 64514 peers, `dhcpv6-pd`, `ipa-01` static host mapping, Pi PXE server 10.10.2.4, UNMS string. 4. Noah DHCP DNS `4.4.4.4` is not a public resolver (`8.8.4.4` intended?). 5. Decide whether VLAN 1002 workload still has live hosts before carrying it. 6. UPnP and GUI older ciphers off.
Author
Owner

Done as of the 2026-11-16 adoption. Full router config renders from git (render.py + gate, iac#117/#120/#121), applied and adopted by tofu-controller on crs309/rb5009-a/rb5009-b with approvePlan auto and no drift (iac#129-133, provider fork 1.99.1003). ER-X migration closed with iac#73; DNS/DHCP behaviour follow-ups live in flux-clusters#1708 (wildcard records) and the BGP hardening in iac#125.

Done as of the 2026-11-16 adoption. Full router config renders from git (render.py + gate, iac#117/#120/#121), applied and adopted by tofu-controller on crs309/rb5009-a/rb5009-b with approvePlan auto and no drift (iac#129-133, provider fork 1.99.1003). ER-X migration closed with iac#73; DNS/DHCP behaviour follow-ups live in flux-clusters#1708 (wildcard records) and the BGP hardening in iac#125.
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#45
No description provided.