gateway-image build.sh still creates its build droplet with EVERY DO account key — narrow it to the executor's own (#744 defence in depth) #860

Closed
opened 2026-08-25 22:29:43 +00:00 by matou-build-agent · 1 comment

Defence in depth left over from #744 (which fixed the leak itself — the golden snapshot no longer carries the build box's /root/.ssh/authorized_keys, proven live on idss-gateway-d49ece2b7e0c).

scripts/gateway-image/build.sh still creates its throwaway build droplet with every key on the DigitalOcean account:

ssh_keys="$(doctl compute ssh-key list --format FingerPrint --no-header | paste -sd,)"
… --ssh-keys "$ssh_keys" …

Only ONE of those keys is ever used: the executor host's own, the one nixos-anywhere and wait_ssh SSH in with. The other ten-plus ride along for no reason — and they are what made #744 possible in the first place (nixos-anywhere copies the installer environment's authorized_keys into the installed system). #744 closed the escape route; this closes the source.

Worth noting the account key set is not static: the #744 probe caught a stale idss-guest-trust line — another rental's app-minted operator key — baked into the snapshot, because the broker registers each rental's key at DO and the build happened to run while one was registered. Narrowing the create to the executor's own key removes that whole class.

Suggested fix

scripts/gateway-image/preflight-ssh-key.sh (#856) already resolves exactly the right fingerprint — the executor host's registered keypair — and dies loud when there isn't one. Have it print that fingerprint and have build.sh pass only that to --ssh-keys, instead of the account-wide paste -sd,. The preflight's existing seam test (scripts/gateway-image/tests/preflight-ssh-key-test.sh) extends to cover the new output; #744's scripts/gateway-image/tests/gateway-image-generic-test.sh keeps proving the belt-and-braces scrub still runs.

Two-way door: a one-line revertible change to a script, provable by the existing offline seam tests plus one live build. Confirmation is a rebuild — so ready-for-session, same standing #744 used.

Also noted, deliberately not done

The three pre-fix snapshots (idss-gateway-28d0dff9c0de, -3e75735dc9d0, -f086c9cac29c) still carry the 12 baked keys. They are left in place on purpose: they are #744's one-command revert path. They are also a footgun — anything that pins an older snapshot by id gets the door back. scripts/lib/gateway-image-rebuild-lib.sh already keeps a bounded snapshot window; whether that reaper should be trusted to age these out, or they should be deleted by hand once the new image has driven green a few times, is a call for whoever picks this up.

Filed by the #744 session under ADR 0174 rule 1 (file follow-ups, don't widen the ticket).

Defence in depth left over from #744 (which fixed the leak itself — the golden snapshot no longer carries the build box's `/root/.ssh/authorized_keys`, proven live on `idss-gateway-d49ece2b7e0c`). `scripts/gateway-image/build.sh` still creates its throwaway build droplet with **every** key on the DigitalOcean account: ``` ssh_keys="$(doctl compute ssh-key list --format FingerPrint --no-header | paste -sd,)" … --ssh-keys "$ssh_keys" … ``` Only ONE of those keys is ever used: the executor host's own, the one `nixos-anywhere` and `wait_ssh` SSH in with. The other ten-plus ride along for no reason — and they are what made #744 possible in the first place (`nixos-anywhere` copies the installer environment's `authorized_keys` into the installed system). #744 closed the *escape route*; this closes the *source*. Worth noting the account key set is not static: the #744 probe caught a stale `idss-guest-trust` line — **another rental's app-minted operator key** — baked into the snapshot, because the broker registers each rental's key at DO and the build happened to run while one was registered. Narrowing the create to the executor's own key removes that whole class. ## Suggested fix `scripts/gateway-image/preflight-ssh-key.sh` (#856) already resolves exactly the right fingerprint — the executor host's registered keypair — and dies loud when there isn't one. Have it *print* that fingerprint and have `build.sh` pass only that to `--ssh-keys`, instead of the account-wide `paste -sd,`. The preflight's existing seam test (`scripts/gateway-image/tests/preflight-ssh-key-test.sh`) extends to cover the new output; #744's `scripts/gateway-image/tests/gateway-image-generic-test.sh` keeps proving the belt-and-braces scrub still runs. Two-way door: a one-line revertible change to a script, provable by the existing offline seam tests plus one live build. Confirmation is a rebuild — so `ready-for-session`, same standing #744 used. ## Also noted, deliberately not done The three pre-fix snapshots (`idss-gateway-28d0dff9c0de`, `-3e75735dc9d0`, `-f086c9cac29c`) still carry the 12 baked keys. They are left in place on purpose: they are #744's one-command revert path. They are also a footgun — anything that pins an older snapshot by id gets the door back. `scripts/lib/gateway-image-rebuild-lib.sh` already keeps a bounded snapshot window; whether that reaper should be trusted to age these out, or they should be deleted by hand once the new image has driven green a few times, is a call for whoever picks this up. Filed by the #744 session under ADR 0174 rule 1 (file follow-ups, don't widen the ticket).
Author
Member

Close report — landed under ADR 0174 (two-way door)

Commit: 487a2df6 on main — session: #860 — narrow the gateway-image build droplet to the executor's own DO key, not the whole account.

What landed

scripts/gateway-image/build.sh no longer rents its throwaway build droplet with the account-wide key set. The line

ssh_keys="$(doctl compute ssh-key list --format FingerPrint --no-header | paste -sd,)"

is gone. Instead, scripts/gateway-image/preflight-ssh-key.sh (#856) — which already resolves and dies loud on exactly the executor host's own DO-registered keypair — now prints that one fingerprint on stdout (the confirm line stays on stderr), and build.sh captures it at the same fail-fast call site:

ssh_keys="$(bash "$here/preflight-ssh-key.sh")"

The assignment is plain (not local), so set -e still propagates a non-zero preflight exit — the build still refuses at second 0 when this host holds no registered key, and no droplet is rented. The old paste -sd, line is replaced by a belt-and-braces [ -n "$ssh_keys" ] guard. The droplet is now created with --ssh-keys "$ssh_keys" = the executor's own fingerprint alone.

This closes the source #744 named: nixos-anywhere copies the installer environment's authorized_keys into the installed system, so the account-wide set is what baked a dozen keys — including a stale idss-guest-trust (another rental's app-minted operator key) — into the golden snapshot. #744 closed the escape route (scrubs the leaked file); #860 removes what rides in.

The #744 belt-and-braces scrub + generic-image assertion (step 4) are untouched — even the single remaining key is the build host's, so the scrub still drops the file. Its comment block was updated to reflect the narrowing.

Proof (offline seam tests, red before / green after)

  • scripts/gateway-image/tests/preflight-ssh-key-test.sh — 6 checks pass (was 4). Two new:
    • green path prints only the matched fingerprint on stdout (build.sh feeds this exact stdout to --ssh-keys);
    • build.sh captures the preflight fingerprint into ssh_keys, passes it to --ssh-keys, and no longer carries paste -sd,.
    • Confirmed red before the fix (green path must print ONLY the matched fingerprint on stdout, got: '').
  • scripts/gateway-image/tests/gateway-image-generic-test.sh (#744) — 5 checks pass, the scrub + assertion still pinned.
  • bash -n clean on all three touched scripts; set -e-through-assignment fail-fast verified with a fake preflight.

Live confirmation is a rebuild — a two-way door, the same standing #744 used. Not run in this session (no rebuild is in scope here); the next scripts/gateway-image/build.sh run proves it end to end.

Deliberately not done (residue, per the ticket)

The three pre-fix snapshots (idss-gateway-28d0dff9c0de, -3e75735dc9d0, -f086c9cac29c) still carry the 12 baked keys and are left in place — they are #744's one-command revert path. Whether the bounded snapshot reaper (scripts/lib/gateway-image-rebuild-lib.sh) should be trusted to age them out, or they should be deleted by hand once the new image has driven green a few times, is a call for a follow-up — a one-way door (data destruction), not smuggled in here.

Ruled by agent under ADR 0174 — veto anytime.

## Close report — landed under ADR 0174 (two-way door) **Commit:** `487a2df6` on `main` — *session: #860 — narrow the gateway-image build droplet to the executor's own DO key, not the whole account*. ### What landed `scripts/gateway-image/build.sh` no longer rents its throwaway build droplet with the account-wide key set. The line ``` ssh_keys="$(doctl compute ssh-key list --format FingerPrint --no-header | paste -sd,)" ``` is gone. Instead, `scripts/gateway-image/preflight-ssh-key.sh` (#856) — which already resolves and dies loud on exactly the executor host's own DO-registered keypair — now **prints that one fingerprint on stdout** (the confirm line stays on stderr), and `build.sh` **captures it at the same fail-fast call site**: ``` ssh_keys="$(bash "$here/preflight-ssh-key.sh")" ``` The assignment is plain (not `local`), so `set -e` still propagates a non-zero preflight exit — the build still refuses at second 0 when this host holds no registered key, and no droplet is rented. The old `paste -sd,` line is replaced by a belt-and-braces `[ -n "$ssh_keys" ]` guard. The droplet is now created with `--ssh-keys "$ssh_keys"` = the executor's own fingerprint alone. This closes the **source** #744 named: nixos-anywhere copies the installer environment's `authorized_keys` into the installed system, so the account-wide set is what baked a dozen keys — including a stale `idss-guest-trust` (another rental's app-minted operator key) — into the golden snapshot. #744 closed the escape route (scrubs the leaked file); #860 removes what rides in. The #744 belt-and-braces scrub + generic-image assertion (step 4) are untouched — even the single remaining key is the build host's, so the scrub still drops the file. Its comment block was updated to reflect the narrowing. ### Proof (offline seam tests, red before / green after) - `scripts/gateway-image/tests/preflight-ssh-key-test.sh` — **6 checks pass** (was 4). Two new: - green path prints **only** the matched fingerprint on stdout (build.sh feeds this exact stdout to `--ssh-keys`); - `build.sh` captures the preflight fingerprint into `ssh_keys`, passes it to `--ssh-keys`, and no longer carries `paste -sd,`. - Confirmed red before the fix (`green path must print ONLY the matched fingerprint on stdout, got: ''`). - `scripts/gateway-image/tests/gateway-image-generic-test.sh` (#744) — **5 checks pass**, the scrub + assertion still pinned. - `bash -n` clean on all three touched scripts; `set -e`-through-assignment fail-fast verified with a fake preflight. **Live confirmation is a rebuild** — a two-way door, the same standing #744 used. Not run in this session (no rebuild is in scope here); the next `scripts/gateway-image/build.sh` run proves it end to end. ### Deliberately not done (residue, per the ticket) The three pre-fix snapshots (`idss-gateway-28d0dff9c0de`, `-3e75735dc9d0`, `-f086c9cac29c`) still carry the 12 baked keys and are **left in place** — they are #744's one-command revert path. Whether the bounded snapshot reaper (`scripts/lib/gateway-image-rebuild-lib.sh`) should be trusted to age them out, or they should be deleted by hand once the new image has driven green a few times, is a call for a follow-up — a one-way door (data destruction), not smuggled in here. Ruled by agent under ADR 0174 — veto anytime.
matou-build-agent 2026-08-26 23:35:19 +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
Matou/idss#860
No description provided.