RouterOS SSH host keys: assigned from OpenBao at bootstrap, rendered into known_hosts (SSH CA exception) #41

Open
opened 2026-11-17 23:34:07 +00:00 by ginjiruu · 0 comments
Owner

Child of the SSH certificate epic lab/machine-configs#19. The permanent RouterOS exception to the host-cert story: RouterOS can neither present nor validate SSH certificates, so the routers need provisioned known_hosts entries instead of @cert-authority trust.

Why RouterOS is an exception

Checked 2026-11-17 against the RouterOS 7.26 manual:

  • SSH server: the host key is a raw key (/ip/ssh/export-host-key, /ip/ssh/import-host-key). There is no HostCertificate equivalent, so a CA-signed host cert cannot be installed.
  • SSH login: /user/ssh-keys/import per user. No TrustedUserCAKeys equivalent.
  • The router's own SSH client (/ip/ssh/known-hosts) pins raw ssh-ed25519/ssh-rsa lines only.
  • Certificate support is an old, unanswered MikroTik feature request. Treat it as permanent.

Without this issue, every OpenSSH box gets TOFU-free trust from the epic, but ssh admin@rb5009-* and crs309 still prompt (or hard-fail under StrictHostKeyChecking=yes).

Design: the host key is assigned, not harvested

Each router gets a host key generated once per device name, stored in OpenBao, and imported by the bootstrap. The device never keeps a key of its own making.

  • A re-image (netinstall) or a hardware swap brings back the same SSH identity. Routers stay fungible (lab/iac#72's premise), and nothing has to be re-harvested.
  • A live key that differs from the stored one is always an incident. There is no "re-imaged, re-harvest pending" state to tell apart from an attack.
  • The private key lives in Bao next to the router's other secrets (secret/routeros-secrets already holds its admin and terraform passwords). No new class of secret.

Rejected: harvesting the device-generated key (REST export-host-key or ssh-keyscan). It needs a re-harvest after every re-image, leaves an ambiguous mismatch window, and export-host-key writes the private key to flash as a file that would have to be cleaned up each time.

Scope

  1. Verify first (gate for the rest). On a throwaway CHR 7.25.x: /ip/ssh/import-host-key accepts an ed25519 private key generated off-device, the server then presents exactly that key (ssh-keyscan matches), and the key survives a reboot. If ed25519 import is unsupported, fall back to RSA 4096 and note it here.
  2. Generate and store. One key per device name (rb5009-a, rb5009-b, crs309, future devices), created once, kept in Bao (proposed secret/routeros-secrets/<device>/ssh-host-key, private + public). Never regenerated unless a rotation is intended.
  3. Import at bootstrap. lab/iac#64's bootstrap template imports the key (upload to flash, import-host-key, delete the file in the same step) before SSH is reachable from anywhere but the bench. Already-deployed routers get it once through the same path; record the date here.
  4. Render. The ssh-ca module from lab/machine-configs#18 composes /etc/ssh/ssh_known_hosts: @cert-authority <fleet domain> <host CA pubkey> for OpenSSH hosts, plus one raw line per router listing every name and address used as an SSH target: canonical name (ADR-0005), VLAN 10 management address, legacy LAN address while it exists (10.15.1.252/.253), and the VLAN 20 router address (10.30.20.2/.3). Example: rb5009-a.net.caosh.int.animeteamspeak.moe,10.15.1.252,10.30.10.2,10.30.20.2 ssh-ed25519 AAAA.... The same file lands on arch-ws via home-manager.
  5. Tighten. StrictHostKeyChecking stays yes. Retire the StrictHostKeyChecking=no / UserKnownHostsFile=/dev/null paths in Taskfiles wherever the rendered file covers the target (installer and VM bootstrap stay exempt as today).
  6. Detect. A periodic check (can hang off lab/iac#72's nightly drift job) compares each router's live host-key-fingerprint with the stored public key and alerts on any mismatch.

Out of scope: the routers' own SSH client (/ip/ssh/known-hosts). Nothing scripts out of the routers over SSH; mktxp and terraform use REST with the pki-net-caosh x509 cert.

Done when

  • Step 1 verified on CHR and recorded here (key type used).
  • From think-01 and arch-ws, with an empty user ~/.ssh/known_hosts, ssh -o BatchMode=yes admin@<each name/address> succeeds under StrictHostKeyChecking=yes.
  • Re-image the bench device through the normal bootstrap: the same check passes with no extra step.
  • A deliberately wrong key on the bench device triggers the mismatch alert.
  • docs/ssh-ca.md (from #18) documents the RouterOS exception and the assigned-key design.
  • The TOFU lines accepted for 10.15.1.252/.253 on 2026-11-17 are removed from the owner's ~/.ssh/known_hosts.

Links: epic lab/machine-configs#19, renderer/host side lab/machine-configs#18, OpenBao host signer lab/iac#49, bootstrap lab/iac#64, drift job lab/iac#72.

Child of the SSH certificate epic lab/machine-configs#19. The permanent RouterOS exception to the host-cert story: RouterOS can neither present nor validate SSH certificates, so the routers need provisioned `known_hosts` entries instead of `@cert-authority` trust. ## Why RouterOS is an exception Checked 2026-11-17 against the RouterOS 7.26 manual: - SSH server: the host key is a raw key (`/ip/ssh/export-host-key`, `/ip/ssh/import-host-key`). There is no `HostCertificate` equivalent, so a CA-signed host cert cannot be installed. - SSH login: `/user/ssh-keys/import` per user. No `TrustedUserCAKeys` equivalent. - The router's own SSH client (`/ip/ssh/known-hosts`) pins raw `ssh-ed25519`/`ssh-rsa` lines only. - Certificate support is an old, unanswered MikroTik feature request. Treat it as permanent. Without this issue, every OpenSSH box gets TOFU-free trust from the epic, but `ssh admin@rb5009-*` and `crs309` still prompt (or hard-fail under `StrictHostKeyChecking=yes`). ## Design: the host key is assigned, not harvested Each router gets a host key generated once per device **name**, stored in OpenBao, and imported by the bootstrap. The device never keeps a key of its own making. - A re-image (netinstall) or a hardware swap brings back the same SSH identity. Routers stay fungible (lab/iac#72's premise), and nothing has to be re-harvested. - A live key that differs from the stored one is always an incident. There is no "re-imaged, re-harvest pending" state to tell apart from an attack. - The private key lives in Bao next to the router's other secrets (`secret/routeros-secrets` already holds its admin and terraform passwords). No new class of secret. Rejected: harvesting the device-generated key (REST `export-host-key` or `ssh-keyscan`). It needs a re-harvest after every re-image, leaves an ambiguous mismatch window, and `export-host-key` writes the private key to flash as a file that would have to be cleaned up each time. ## Scope 1. **Verify first (gate for the rest).** On a throwaway CHR 7.25.x: `/ip/ssh/import-host-key` accepts an ed25519 private key generated off-device, the server then presents exactly that key (`ssh-keyscan` matches), and the key survives a reboot. If ed25519 import is unsupported, fall back to RSA 4096 and note it here. 2. **Generate and store.** One key per device name (`rb5009-a`, `rb5009-b`, `crs309`, future devices), created once, kept in Bao (proposed `secret/routeros-secrets/<device>/ssh-host-key`, private + public). Never regenerated unless a rotation is intended. 3. **Import at bootstrap.** lab/iac#64's bootstrap template imports the key (upload to flash, `import-host-key`, delete the file in the same step) before SSH is reachable from anywhere but the bench. Already-deployed routers get it once through the same path; record the date here. 4. **Render.** The ssh-ca module from lab/machine-configs#18 composes `/etc/ssh/ssh_known_hosts`: `@cert-authority <fleet domain> <host CA pubkey>` for OpenSSH hosts, plus one raw line per router listing **every name and address used as an SSH target**: canonical name (ADR-0005), VLAN 10 management address, legacy LAN address while it exists (10.15.1.252/.253), and the VLAN 20 router address (10.30.20.2/.3). Example: `rb5009-a.net.caosh.int.animeteamspeak.moe,10.15.1.252,10.30.10.2,10.30.20.2 ssh-ed25519 AAAA...`. The same file lands on arch-ws via home-manager. 5. **Tighten.** `StrictHostKeyChecking` stays `yes`. Retire the `StrictHostKeyChecking=no` / `UserKnownHostsFile=/dev/null` paths in Taskfiles wherever the rendered file covers the target (installer and VM bootstrap stay exempt as today). 6. **Detect.** A periodic check (can hang off lab/iac#72's nightly drift job) compares each router's live `host-key-fingerprint` with the stored public key and alerts on any mismatch. Out of scope: the routers' own SSH client (`/ip/ssh/known-hosts`). Nothing scripts out of the routers over SSH; mktxp and terraform use REST with the `pki-net-caosh` x509 cert. ## Done when - [ ] Step 1 verified on CHR and recorded here (key type used). - [ ] From think-01 and arch-ws, with an empty user `~/.ssh/known_hosts`, `ssh -o BatchMode=yes admin@<each name/address>` succeeds under `StrictHostKeyChecking=yes`. - [ ] Re-image the bench device through the normal bootstrap: the same check passes with no extra step. - [ ] A deliberately wrong key on the bench device triggers the mismatch alert. - [ ] `docs/ssh-ca.md` (from #18) documents the RouterOS exception and the assigned-key design. - [ ] The TOFU lines accepted for 10.15.1.252/.253 on 2026-11-17 are removed from the owner's `~/.ssh/known_hosts`. Links: epic lab/machine-configs#19, renderer/host side lab/machine-configs#18, OpenBao host signer lab/iac#49, bootstrap lab/iac#64, drift job lab/iac#72.
ginjiruu changed title from known_hosts for RouterOS: harvest host keys over REST, distribute fleet-wide (SSH CA exception) to RouterOS SSH host keys: assigned from OpenBao at bootstrap, rendered into known_hosts (SSH CA exception) 2026-11-17 23:55:02 +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/machine-configs#41
No description provided.