feat(routeros): bootstrap v2 - host-driven REST delivery + netinstall driver #112

Merged
ginjiruu merged 9 commits from routeros-bootstrap-64 into master 2026-11-16 21:03:37 +00:00
Owner

Closes #64.

What this is

routeros/bootstrap/: render a per-device bootstrap .rsc (identity, clock, NTP, DNS, mgmt VLAN/address + route, terraform user, human SSH keys, OpenBao-issued certificate, service hardening), then deliver it over industry-standard mechanisms and prove it landed.

Two delivery paths, no hand-rolled console anything:

  • first-contact.sh — host-driven REST. A factory CHR serves www with blank admin: on its MAC-derived link-local IPv6; the host classifies the device with an early-401 retry loop, serves the rendered script from a one-shot HTTP server, and has the router /tool/fetch + /import it, exactly like the vendored chr-launch.sh first-boot. The /import response is treated as untrusted on purpose (the script disables www and rewrites the executing admin's password mid-flight); success is proven by read-back over www-ssl with CA and hostname verification.
  • netinstall-deliver.sh + BENCH-RUNBOOK.md — MikroTik's official tool for routers with no reachable IP, using the default-configuration slot (-s) for reset replay. Pinned decision: wipe (-e) by default, because a kept factory RB5009 config (DHCP client and WAN firewall on ether1) has never been exercised against this bootstrap; --keep-config exists and says so.

Proven live on CHR 7.25.1 (throwaway sandbox, destroyed after)

  • Full factory → bootstrap run: import answered Session closed http=400 (expected), read-back up in 1–2 s over verified TLS, acceptance checks a–d + protected set pass, reset → host re-provision → snapshot byte-identical.
  • NTP wait proven in every clock state reachable on CHR (the literal 1970 state is unreachable: /system clock set refuses dates before package build time).
  • 7-row user-gate matrix on live REST.
  • Renderer matches the working lab-router-certs.sh reference line for line (issuance, escaper); secrets never leave mode-600 gitignored files, verified by independent audit of the tree.

Findings that changed the design (details in README)

  • The per-user service= attribute is a no-op relic on 7.25.1 — REST rejects the parameter, CLI accepts any value with no effect. The real gate is group policy (api + write). We ship no service attribute rather than advertise a wall that does not exist.
  • GET /certificate reports subject: null for all certs via REST; subject proof is the TLS handshake itself.
  • /import of a script containing certificate imports answers {}, never ret:true; drivers must not gate on it.
  • /system default-configuration custom-script is writable only by netinstall, which is why replay testing is bench-scoped.

Not exercised here (bench list in BENCH-RUNBOOK.md)

netinstall end-to-end (containers do not netboot), RB5009 factory-config interactions, slow-boot 401 windows (retry logic covers them, not reproduced on fast KVM boots).

Notes

  • HANDOFF-64.md keeps the full v1 (console-era, superseded) and v2 records.
  • Renderer needs bao + python3; no pipeline/runner changes.
  • Complements #65 (per-device Terraform roots): this lands the protected set and a terraform user the roots can then adopt.
Closes #64. ## What this is `routeros/bootstrap/`: render a per-device bootstrap `.rsc` (identity, clock, NTP, DNS, mgmt VLAN/address + route, terraform user, human SSH keys, OpenBao-issued certificate, service hardening), then deliver it over industry-standard mechanisms and prove it landed. Two delivery paths, no hand-rolled console anything: - **`first-contact.sh`** — host-driven REST. A factory CHR serves `www` with blank `admin:` on its MAC-derived link-local IPv6; the host classifies the device with an early-401 retry loop, serves the rendered script from a one-shot HTTP server, and has the router `/tool/fetch` + `/import` it, exactly like the vendored `chr-launch.sh` first-boot. The `/import` response is treated as untrusted on purpose (the script disables `www` and rewrites the executing admin's password mid-flight); success is proven by read-back over `www-ssl` with CA and hostname verification. - **`netinstall-deliver.sh`** + `BENCH-RUNBOOK.md` — MikroTik's official tool for routers with no reachable IP, using the default-configuration slot (`-s`) for reset replay. Pinned decision: wipe (`-e`) by default, because a kept factory RB5009 config (DHCP client and WAN firewall on ether1) has never been exercised against this bootstrap; `--keep-config` exists and says so. ## Proven live on CHR 7.25.1 (throwaway sandbox, destroyed after) - Full factory → bootstrap run: import answered `Session closed` http=400 (expected), read-back up in 1–2 s over verified TLS, acceptance checks a–d + protected set pass, reset → host re-provision → snapshot byte-identical. - NTP wait proven in every clock state reachable on CHR (the literal 1970 state is unreachable: `/system clock set` refuses dates before package build time). - 7-row user-gate matrix on live REST. - Renderer matches the working `lab-router-certs.sh` reference line for line (issuance, escaper); secrets never leave mode-600 gitignored files, verified by independent audit of the tree. ## Findings that changed the design (details in README) - The per-user `service=` attribute is a no-op relic on 7.25.1 — REST rejects the parameter, CLI accepts any value with no effect. The real gate is group policy (`api` + `write`). We ship no `service` attribute rather than advertise a wall that does not exist. - `GET /certificate` reports `subject: null` for all certs via REST; subject proof is the TLS handshake itself. - `/import` of a script containing certificate imports answers `{}`, never `ret:true`; drivers must not gate on it. - `/system default-configuration custom-script` is writable only by netinstall, which is why replay testing is bench-scoped. ## Not exercised here (bench list in BENCH-RUNBOOK.md) netinstall end-to-end (containers do not netboot), RB5009 factory-config interactions, slow-boot 401 windows (retry logic covers them, not reproduced on fast KVM boots). ## Notes - `HANDOFF-64.md` keeps the full v1 (console-era, superseded) and v2 records. - Renderer needs `bao` + `python3`; no pipeline/runner changes. - Complements #65 (per-device Terraform roots): this lands the protected set and a terraform user the roots can then adopt.
stopped on coordinator steering: first-boot provisioning moves to the
in-house REST path (factory admin-blank www) and netinstall-cli; see
routeros/bootstrap/HANDOFF-64.md for state, stuck list, and what is
reusable (render.sh and the .rsc payload are delivery-agnostic).
The :len guard on [:find ...] makes the wait condition numeric-safe in every
clock state (the form proven live on CHR 7.25.1: immediate exit when synced,
loop-to-cap while the pattern is present, clean exit when 1970 disappears
mid-loop). Notes corrected for REST delivery: the import response is
unreliable (the session dies at the www-off line), netinstall has none.
Evidence and the honest note that the old form did not actually abort on
7.25.1: HANDOFF-64.md v2.
- umask 077 closes the creation window of the key-bearing render (review s3)
- the /interface vlan cleanup pass now runs even with MGMT_VLAN=0, so a
  config change from tagged to untagged stops leaving a stale VLAN iface
- intermediates import as lab-ca-N (harness spelling) with file names under
  ^tls- so the render-scheduled file cleanup removes them too
- the terraform user ships NO service= attribute: on 7.25.1 REST rejects it
  as unknown and the CLI accepts any value with zero gating effect; the
  group policy is the proven wall (matrix in HANDOFF-64.md v2, README)
first-contact.sh is the host twin of the harness chr-launch flow: factory
www on the link-local derived by EUI-64 from the router REAL MAC (input
FC_MAC, never the official image MAC+1 quirk), admin: blank, early 401s
retryable until BOOT_WAIT (classification also probes www-ssl so reruns
against a provisioned device exit idempotently). The router pulls the
render via /tool/fetch from one-shot-serve.py (one-shot host HTTP server,
link-local bind with %zone); /import fires with its response UNTRUSTED
(Session closed / 400 / dead connection / {} all expected, since the script
disables www and rewrites the executing admin password mid-flight) and
success is proven by CA-and-hostname-verified read-back over www-ssl with
the new credentials, including cleanup of the fetched key-bearing file.
Live-proven on CHR 7.25.1: boot:one green; import answered "Session
closed" http=400 while the full protected set landed (HANDOFF-64.md v2).

sim/r64-launch.sh is deleted: every provisioning responsibility is now
host-side, the container runs the plain mikrotik/chr image, and its one
worthwhile idea (early-401 classification retry) lives in first-contact.sh.
check-suite.sh runs the acceptance checks from the host against an arbitrary
target (API_IP/API_PORT/CA + the first-contact contract): docker-free, so
the same suite drives sim containers, clab lab routers and the bench RB5009.
All reads are unfiltered + client-side map(select(.name==...)) (7.25.1 filter
quirk + subject=null made filtered menu reads untrustworthy; subject proof
moved to the TLS handshake). The snapshot helper keeps its jq negation
inside select() and refuses empty/partial snapshots, so (e) cannot pass
vacuously. terraform checks assert the group field and the token-parsed
policy (RouterOS normalizes the list with !-tokens). (e) in sim = reset,
host re-provisions, snapshot byte-identical; --diff-only is the documented
bench slot-replay variant. boot-one.sh reworked to the plain image (no
entrypoint override) plus a host-side docker exec address handover;
boot-clean.sh also removes r64-net and shreds generated sim vars.
netinstall-deliver.sh covers routers with no reachable IP: it assembles
netinstall-cli -s out/<device>.rsc (the /system/default-configuration
custom-script slot, the only writer of the reset-replay payload) and pins
-e (wipe): the sim container IS an empty-configuration device and every
7.25.1 proof was earned there, while a kept factory RB5009 config layers an
ether1 DHCP client and WAN firewall over the bootstrap mgmt address and
static route — unproven interactions the runbook pins and marks bench-only.
netinstall-cli 7.25.1 demands packages (verified locally, as is --mac
parsing); the runbook carries the full bench procedure, the slot-replay
variant of check (e), and recovery. End-to-end netinstall cannot run from
sim (containers do not netboot) and was not pretended: every bench-only
step is marked. Taskfile: task boot:netinstall (DEVICE=..., flags after --).
HANDOFF-64.md gains a v2 status section (files, live evidence incl. the NTP
semantics matrix, the service=-is-a-noop matrix, and what sim cannot prove:
netinstall end-to-end, RB5009 keep-config interactions, slot replay); the v1
record is kept verbatim. README describes the shipped configuration against
the 7.25.1 evidence: group policy gates (api+write required for REST,
service tokens close the rest, no service= relic), the untrusted /import
response with read-back proof, the parameterized suite, and the bench
runbook pointer; the false "matches the existing harness tf user" precedent
wording is gone (no such source exists; the policy set is now justified by
the live matrix only).
Bench run 2026-11-16 (RB5009UPr+S+ HMK0BE3QXBH): RouterOS 7.25.1 plus
the bootstrap installed, check-suite all pass, NTP synced.

- netinstall-deliver.sh runs -r -s: -s alone keeps the old config and
  the bootstrap never runs; -e with -s is refused by netinstall-cli.
- Pin the netinstall-cli build to 2026-09-04 or older (7.24.2): later
  builds answer BOOTP with stale xids and loop (forum thread 273209).
- --mac is mandatory; byte-identical npks are dropped (routeros- and
  system-7.25.1-arm64.npk are the same file).
- Preflight: install iface needs IPv4 and the firewalld trusted zone.
- device-mode-advanced.rsc: optional -sm mode script (untested on
  hardware). Factory device-mode home blocks routerboard, scheduler
  and fetch.
- Runbook rewritten from the bench: host prep (NetworkManager resets
  the firewalld zone on every carrier drop), how to read the wire,
  button-free netboot via device-mode + boot-device, the button
  procedure from the board manual.
ginjiruu merged commit 29655f191b into master 2026-11-16 21:03:37 +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!112
No description provided.