rented gateway deploy: control-plane probe hard-refuses on a changed SSH host key the rented (VMMode) path's own design says can never change #707

Closed
opened 2026-08-23 13:53:28 +00:00 by matou-build-agent · 1 comment

Failure

Drive 20260823T132050Z, leg activation, signature 4c82deb1e678. The journey's throwOnDeployFailure fired on a real, honestly-surfaced deploy failure (not a hang/journey-fault — #700 already fixed that presentation bug):

Error: the gateway deploy failed — The gateway deploy failed. [There is no old operating system to roll back to — this machine was taken over for the community.]

logs/founding-state.log's standup.deploy.failure.tail carries the real transport error from probeControlPlaneActive (internal/founding/deploy.go:1105-1143, called at deploy.go:527):

clan: probe idss-control-plane.service on gateway over ssh: exit status 255:
@@@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @@@
...
Offending ED25519 key in .../state/own-vps/known_hosts:1
Host key for 134.199.162.232 has changed and you have requested strict checking.

The droplet was unreachable by the time evidence-gather ran post-drive (logs/droplet-journal.txt: ssh: connect ... Connection timed out), so live re-inspection of the box is not possible from this evidence alone.

Why this should not be possible on the rented path

The rented carrier is explicitly documented as never rotating the box's host key:

  • internal/founding/rentedpath.go:31-35: "minus the takeover... nothing to install and nothing to overwrite", "no RotateHostKey (no reboot — the box keeps the host key connect learned)".
  • internal/founding/standuprented.go:15-22: "no host-key rotation across a reboot ... 'Rent a server' IS the consent (a fresh...)".
  • Contrast own-VPS, which DOES expect+handle a key change: internal/founding/deploy.go:346-388 calls RotateHostKey specifically because its FullInstall takeover reboots into a fresh NixOS with a new identity.

Yet this run's known_hosts (state/own-vps/known_hosts, 1 entry — the key pinned at the connect leg) is exactly what the later deploy leg's UnitActive probe checked and hard-refused against, per internal/clan/adapter.go:66-73's own comment: sshKnownHostsFile pins UnitActive's host-key check so it isn't fooled by "a stale ~/.ssh/known_hosts entry for a DigitalOcean-reused IP, whose changed key StrictHostKeyChecking=accept-new HARD-refuses as a false MITM alarm" — the exact symptom seen here, just ~21 minutes into the SAME drive rather than across drives/IP-reuse.

Between connect (host key learned, pinned) and the deploy leg's post-activation probe, enroll-configure logs "machine vars generated (clan-core generators, unsandboxed — pinned code, ADR 0126)" and enroll-build/enroll-copy/enroll-activate apply the composed gateway config via clan machines update ... --host-key-check none (internal/clan/enrollment.go:917) — activation deliberately does NOT check the host key going IN. The leading theory: something in the composed gateway config or clan-core's machine-vars generators manages/regenerates the box's SSH host key as a side effect of applying community config (a services.openssh.hostKeys declaration or a clan-core generator that mints a fresh host identity), silently violating the rented path's "box keeps the key connect learned" guarantee. The alternative — a genuine one-off DigitalOcean-side event (droplet rebuild/migration) — is possible but doesn't explain why deploy.go:536-537 already carries a comment naming a PRIOR rented drive (#700) that hit this identical class of failure ("the rented #700 drive" — REMOTE HOST IDENTIFICATION HAS CHANGED on the rented path), suggesting this is reproducible, not a one-off.

What plugging it needs

  1. Reproduce live against a fresh rented droplet: capture /etc/ssh/ssh_host_ed25519_key.pub right after connect pins it, then again after enroll-activate completes, to confirm the key actually changes during config convergence (not at boot).
  2. If confirmed: find what in the composed gateway config / clan-core generators (the enroll-configure "machine vars generated" step) touches SSH host keys, and either (a) make the composed config preserve the golden image's pre-existing host key, or (b) give the rented path its own post-activation host-key re-learn/re-pin step (parallel to own-VPS's RotateHostKey, deploy.go:346-388) that updates state/own-vps/known_hosts before probeControlPlaneActive runs. Option (b) is a real design call (the rented path's whole pitch is "no rotation needed") — likely ADR-worthy, same as #700's ADR-0174 two-way-door ruling.
  3. Separately (found during this diagnosis, does not itself explain the red): buildDeployFailure (internal/founding/deploy.go:979-999) branches only on mode == enroll.ModeVM vs else, so a rented-path failure (which also carries enroll.ModeFull, same as own-VPS/self-hosted) gets the own-VPS/self-hosted copy verbatim — "this machine was taken over for the community", "no old operating system to roll back to" — even though the rented path's own S9 card explicitly says the opposite ("no takeover — a fresh server has nothing to erase", visible in this run's error-context.md FACTS line). This directly contradicts the app's own copy elsewhere and should key off Draft.Access.Kind (mirroring selfHostedFullInstall, internal/founding/selfhostedpath.go:86-88) rather than Mode alone — worth fixing alongside item 2, but on its own it would not have turned this drive green.

Suspected layer: clan-core machine-vars generation / composed gateway NixOS config (SSH host key management), surfaced through internal/founding/deploy.go's control-plane probe and internal/clan/adapter.go's known-hosts pin.

drive 20260823T132050Z red at activation: the gateway deploy failed — The gateway deploy failed. [There is no old operating system to roll back to — this machine was taken over for the community.]
evidence: test-results/…/20260823T132050Z/ on matou-workstation (legs.json, droplet-journal.txt, trace) — a representative screenshot is attached here if one was captured (#596)

## Failure Drive `20260823T132050Z`, leg `activation`, signature `4c82deb1e678`. The journey's `throwOnDeployFailure` fired on a real, honestly-surfaced deploy failure (not a hang/journey-fault — #700 already fixed that presentation bug): ``` Error: the gateway deploy failed — The gateway deploy failed. [There is no old operating system to roll back to — this machine was taken over for the community.] ``` `logs/founding-state.log`'s `standup.deploy.failure.tail` carries the real transport error from `probeControlPlaneActive` (`internal/founding/deploy.go:1105-1143`, called at `deploy.go:527`): ``` clan: probe idss-control-plane.service on gateway over ssh: exit status 255: @@@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @@@ ... Offending ED25519 key in .../state/own-vps/known_hosts:1 Host key for 134.199.162.232 has changed and you have requested strict checking. ``` The droplet was unreachable by the time evidence-gather ran post-drive (`logs/droplet-journal.txt`: `ssh: connect ... Connection timed out`), so live re-inspection of the box is not possible from this evidence alone. ## Why this should not be possible on the rented path The rented carrier is explicitly documented as never rotating the box's host key: - `internal/founding/rentedpath.go:31-35`: "minus the takeover... nothing to install and nothing to overwrite", "no RotateHostKey (no reboot — the box keeps the host key connect learned)". - `internal/founding/standuprented.go:15-22`: "no host-key rotation across a reboot ... 'Rent a server' IS the consent (a fresh...)". - Contrast own-VPS, which DOES expect+handle a key change: `internal/founding/deploy.go:346-388` calls `RotateHostKey` specifically because its `FullInstall` takeover reboots into a fresh NixOS with a new identity. Yet this run's `known_hosts` (`state/own-vps/known_hosts`, 1 entry — the key pinned at the `connect` leg) is exactly what the later `deploy` leg's `UnitActive` probe checked and hard-refused against, per `internal/clan/adapter.go:66-73`'s own comment: `sshKnownHostsFile` pins `UnitActive`'s host-key check so it isn't fooled by "a stale ~/.ssh/known_hosts entry for a DigitalOcean-reused IP, whose changed key StrictHostKeyChecking=accept-new HARD-refuses as a false MITM alarm" — the exact symptom seen here, just ~21 minutes into the SAME drive rather than across drives/IP-reuse. Between `connect` (host key learned, pinned) and the `deploy` leg's post-activation probe, `enroll-configure` logs "machine vars generated (clan-core generators, unsandboxed — pinned code, ADR 0126)" and `enroll-build`/`enroll-copy`/`enroll-activate` apply the composed gateway config via `clan machines update ... --host-key-check none` (`internal/clan/enrollment.go:917`) — activation deliberately does NOT check the host key going IN. The leading theory: something in the composed gateway config or clan-core's machine-vars generators manages/regenerates the box's SSH host key as a side effect of applying community config (a `services.openssh.hostKeys` declaration or a clan-core generator that mints a fresh host identity), silently violating the rented path's "box keeps the key connect learned" guarantee. The alternative — a genuine one-off DigitalOcean-side event (droplet rebuild/migration) — is possible but doesn't explain why `deploy.go:536-537` already carries a comment naming a PRIOR rented drive (`#700`) that hit this identical class of failure ("the rented #700 drive" — REMOTE HOST IDENTIFICATION HAS CHANGED on the rented path), suggesting this is reproducible, not a one-off. ## What plugging it needs 1. Reproduce live against a fresh rented droplet: capture `/etc/ssh/ssh_host_ed25519_key.pub` right after `connect` pins it, then again after `enroll-activate` completes, to confirm the key actually changes during config convergence (not at boot). 2. If confirmed: find what in the composed gateway config / clan-core generators (the `enroll-configure` "machine vars generated" step) touches SSH host keys, and either (a) make the composed config preserve the golden image's pre-existing host key, or (b) give the rented path its own post-activation host-key re-learn/re-pin step (parallel to own-VPS's `RotateHostKey`, `deploy.go:346-388`) that updates `state/own-vps/known_hosts` before `probeControlPlaneActive` runs. Option (b) is a real design call (the rented path's whole pitch is "no rotation needed") — likely ADR-worthy, same as #700's ADR-0174 two-way-door ruling. 3. Separately (found during this diagnosis, does not itself explain the red): `buildDeployFailure` (`internal/founding/deploy.go:979-999`) branches only on `mode == enroll.ModeVM` vs else, so a rented-path failure (which also carries `enroll.ModeFull`, same as own-VPS/self-hosted) gets the own-VPS/self-hosted copy verbatim — "this machine was taken over for the community", "no old operating system to roll back to" — even though the rented path's own S9 card explicitly says the opposite ("no takeover — a fresh server has nothing to erase", visible in this run's `error-context.md` FACTS line). This directly contradicts the app's own copy elsewhere and should key off `Draft.Access.Kind` (mirroring `selfHostedFullInstall`, `internal/founding/selfhostedpath.go:86-88`) rather than `Mode` alone — worth fixing alongside item 2, but on its own it would not have turned this drive green. Suspected layer: clan-core machine-vars generation / composed gateway NixOS config (SSH host key management), surfaced through `internal/founding/deploy.go`'s control-plane probe and `internal/clan/adapter.go`'s known-hosts pin. drive `20260823T132050Z` red at `activation`: `the gateway deploy failed — The gateway deploy failed. [There is no old operating system to roll back to — this machine was taken over for the community.]` evidence: `test-results/…/20260823T132050Z/` on matou-workstation (legs.json, droplet-journal.txt, trace) — a representative screenshot is attached here if one was captured (#596) <!-- rehearsal-sig: 4c82deb1e678 -->
Author
Member

Close report — root cause found, reproduced live, fixed, and the fix proven live

Ruled by agent under ADR 0174 — veto anytime. Two-way door: two revertible source changes, proven by Go contract tests, a real nix eval of the composed image, and a live before/after on rented droplets. No security-posture widening — the posture TIGHTENS (from one shared host identity across every community to one unique per box).

What actually happened

The ticket's leading theory was the composed gateway config or a clan-core machine-vars generator minting a host identity. That is not it — I checked: nothing in this repo declares services.openssh.hostKeys, and clan-core's only host-key generators live in the sshd and admin clanServices, neither of which the inventory attaches.

It is the image, and two defects compound. Reproduced live on two droplets rented from snapshot idss-gateway-01eedc890405:

  1. scripts/gateway-image/build.sh snapshotted the build droplet with /etc/ssh/ssh_host_*_key in place. The "generic" image (ADR 0048) therefore carried an SSH identity. Both probe droplets served the byte-identical ed25519 key …RDQpZNx — every community's rented gateway presents the same host key, and that is the key connect pins and the pair record carries.

  2. cloud-init's ssh config module defaults ssh_deletekeys: true — it deletes /etc/ssh/ssh_host_* and mints fresh ones. That module is load-bearing here (it is what lands DO's create-time ssh_keys in /root/.ssh/authorized_keys), but nixpkgs orders cloud-config.service against nothing sshd.service waits on: only cloud-init.service is before sshd, and the ssh module does not run in that stage.

The measurement

15:36:41  sshd started, serving         …RDQpZNx   (the snapshot-baked key)
15:36:42  cloud-config finished, having rewritten
          /etc/ssh/ssh_host_ed25519_key.pub to …hIKA
          (all three host keys rewritten, same second; authorized_keys too)

So the box served an identity that no longer existed on disk for the whole drive. connect pinned the orphan. Then:

served BEFORE `systemctl restart sshd`:  …RDQpZNx
served AFTER  `systemctl restart sshd`:  …hIKA     == on-disk

The first thing to restart sshd is enroll-activate's switch-to-configuration switch. The box flips identity there, and the deploy stage's pinned probeControlPlaneActive correctly screams MITM. Deterministic, not a one-off — which is why #700, #704 and this drive all wear the same signature.

The fix (commit d62a7252)

  • nix/gateway-image/configuration.nix pins services.cloud-init.settings.ssh_deletekeys = false — cloud-init generates only MISSING keys, so the key sshd mints in its own ExecStartPre (sshd-pre-start, immediately before it binds) is the box's permanent identity. The ssh module still runs, so DO key injection is untouched.
  • scripts/gateway-image/build.sh scrubs /etc/ssh/ssh_host_* off the build droplet before the snapshot (new step 4), so that boot-minted key is unique per droplet rather than shared.

Proof

  1. nix eval of the composed image — the generated /etc/cloud/cloud.cfg now carries ssh_deletekeys: false with ssh still in cloud_config_modules.
  2. Live, on a rented droplet with the fix's runtime shape applied and rebooted:
    served (t0)          : …NvWR
    served (t0+40s)      : …NvWR
    on-disk              : …NvWR
    served after sshd restart : …NvWR
    authorized_keys      : 3869 bytes, written by cloud-init
    RESULT: identity STABLE across boot, cloud-init, and an sshd restart
    
  3. internal/clan/gateway_image_hostkey_test.go guards both halves (red before / green after).
  4. gofmt, go vet and the full internal/... suite green. Both lab droplets destroyed (zero idss-707-probe droplets remain).

Ticket item 3 — also fixed

buildDeployFailure (internal/founding/deploy.go) branched on Mode alone, so a rented failure (also enroll.ModeFull) got the own-VPS/self-hosted copy verbatim. The no-rollback sentence now keys off Draft.Access.Kind, mirroring selfHostedFullInstall: a rented failure says the server was rented fresh for the community, so nothing of yours was overwritten; a self-hosted one still names the takeover it really made. Two new seam tests, red before / green after.

Deliberately NOT done — ticket item 2 option (b)

I did not add a rented-path RotateHostKey re-learn. It would have turned the drive green by auto-accepting whatever key the box presents — laundering a real host-identity change into a silent accept, on the one path whose whole pitch is "no rotation needed". With the cause removed there is nothing to re-learn, and the refusal stays honest. This is recorded as a corollary in GOTCHAS #63, so a future session does not reach for it.

Left open / filed elsewhere

  • The box also going DARK after activation (Connection timed out) is not explained by this — a changed host key is a refusal, not a timeout. That remains #703, and GOTCHAS #62 still stands for it. This fix removes one of the two confounded symptoms, which should make #703's next drive much easier to read.
  • #708 (new): rented drives leak one DigitalOcean SSH key each — ~20 stale idss-gateway-rehearsal-rentfail-* keys on the account, name prefix doubled. Found during this diagnosis, out of scope here.
  • Not yet re-driven end to end. The fix only reaches a real drive once the golden image is rebuilt from this commit — which rehearsal-cycle.sh's auto-rebuild loop (#661) does on the next cycle. The next rented drive past enroll-activate is the tightening evidence.

GOTCHAS #63 added; STATUS.md header updated in the same commit.

## Close report — root cause found, reproduced live, fixed, and the fix proven live **Ruled by agent under ADR 0174 — veto anytime.** Two-way door: two revertible source changes, proven by Go contract tests, a real `nix eval` of the composed image, and a live before/after on rented droplets. **No security-posture widening — the posture TIGHTENS** (from one shared host identity across every community to one unique per box). ### What actually happened The ticket's leading theory was the composed gateway config or a clan-core machine-vars generator minting a host identity. **That is not it** — I checked: nothing in this repo declares `services.openssh.hostKeys`, and clan-core's only host-key generators live in the `sshd` and `admin` clanServices, neither of which the inventory attaches. It is the **image**, and two defects compound. Reproduced live on two droplets rented from snapshot `idss-gateway-01eedc890405`: 1. **`scripts/gateway-image/build.sh` snapshotted the build droplet with `/etc/ssh/ssh_host_*_key` in place.** The "generic" image (ADR 0048) therefore carried an SSH identity. Both probe droplets served the **byte-identical** ed25519 key `…RDQpZNx` — every community's rented gateway presents the *same* host key, and that is the key `connect` pins and the pair record carries. 2. **cloud-init's `ssh` config module defaults `ssh_deletekeys: true`** — it deletes `/etc/ssh/ssh_host_*` and mints fresh ones. That module is load-bearing here (it is what lands DO's create-time `ssh_keys` in `/root/.ssh/authorized_keys`), but nixpkgs orders `cloud-config.service` against nothing `sshd.service` waits on: only `cloud-init.service` is `before` sshd, and the `ssh` module does not run in that stage. ### The measurement ``` 15:36:41 sshd started, serving …RDQpZNx (the snapshot-baked key) 15:36:42 cloud-config finished, having rewritten /etc/ssh/ssh_host_ed25519_key.pub to …hIKA (all three host keys rewritten, same second; authorized_keys too) ``` So the box served an identity that **no longer existed on disk** for the whole drive. `connect` pinned the orphan. Then: ``` served BEFORE `systemctl restart sshd`: …RDQpZNx served AFTER `systemctl restart sshd`: …hIKA == on-disk ``` The first thing to restart sshd is `enroll-activate`'s `switch-to-configuration switch`. The box flips identity there, and the deploy stage's pinned `probeControlPlaneActive` **correctly** screams MITM. Deterministic, not a one-off — which is why #700, #704 and this drive all wear the same signature. ### The fix (commit `d62a7252`) - `nix/gateway-image/configuration.nix` pins `services.cloud-init.settings.ssh_deletekeys = false` — cloud-init generates only MISSING keys, so the key sshd mints in its own `ExecStartPre` (`sshd-pre-start`, immediately before it binds) is the box's permanent identity. The `ssh` module still runs, so DO key injection is untouched. - `scripts/gateway-image/build.sh` scrubs `/etc/ssh/ssh_host_*` off the build droplet before the snapshot (new step 4), so that boot-minted key is **unique per droplet** rather than shared. ### Proof 1. **`nix eval` of the composed image** — the generated `/etc/cloud/cloud.cfg` now carries `ssh_deletekeys: false` with `ssh` still in `cloud_config_modules`. 2. **Live, on a rented droplet with the fix's runtime shape applied and rebooted:** ``` served (t0) : …NvWR served (t0+40s) : …NvWR on-disk : …NvWR served after sshd restart : …NvWR authorized_keys : 3869 bytes, written by cloud-init RESULT: identity STABLE across boot, cloud-init, and an sshd restart ``` 3. `internal/clan/gateway_image_hostkey_test.go` guards both halves (red before / green after). 4. `gofmt`, `go vet` and the full `internal/...` suite green. Both lab droplets destroyed (zero `idss-707-probe` droplets remain). ### Ticket item 3 — also fixed `buildDeployFailure` (`internal/founding/deploy.go`) branched on `Mode` alone, so a rented failure (also `enroll.ModeFull`) got the own-VPS/self-hosted copy verbatim. The no-rollback sentence now keys off `Draft.Access.Kind`, mirroring `selfHostedFullInstall`: a rented failure says the server was **rented fresh for the community, so nothing of yours was overwritten**; a self-hosted one still names the takeover it really made. Two new seam tests, red before / green after. ### Deliberately NOT done — ticket item 2 option (b) I did **not** add a rented-path `RotateHostKey` re-learn. It would have turned the drive green by auto-accepting whatever key the box presents — laundering a real host-identity change into a silent accept, on the one path whose whole pitch is "no rotation needed". With the cause removed there is nothing to re-learn, and the refusal stays honest. This is recorded as a corollary in GOTCHAS #63, so a future session does not reach for it. ### Left open / filed elsewhere - **The box also going DARK** after activation (`Connection timed out`) is **not** explained by this — a changed host key is a refusal, not a timeout. That remains **#703**, and GOTCHAS #62 still stands for it. This fix removes one of the two confounded symptoms, which should make #703's next drive much easier to read. - **#708 (new):** rented drives leak one DigitalOcean SSH key each — ~20 stale `idss-gateway-rehearsal-rentfail-*` keys on the account, name prefix doubled. Found during this diagnosis, out of scope here. - **Not yet re-driven end to end.** The fix only reaches a real drive once the golden image is rebuilt from this commit — which `rehearsal-cycle.sh`'s auto-rebuild loop (#661) does on the next cycle. The next rented drive past `enroll-activate` is the tightening evidence. GOTCHAS #63 added; `STATUS.md` header updated in the same commit.
matou-build-agent 2026-08-23 15:55:45 +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.

Reference
Matou/idss#707
No description provided.