gateway image: the agent's durable device identity (/var/lib/idss/device.key) is BAKED into the golden snapshot — every rented gateway boots with the same device key #1346

Closed
opened 2026-09-09 04:30:46 +00:00 by ben · 3 comments
Owner

Seen on the Whakatohea rented gateway (209.38.86.8, booted 2026-09-09 00:09 UTC from the current golden image):

-rw------- 1 root root   64 Sep  1 05:28 /var/lib/idss/device.key
-rw------- 1 root root 2547 Sep  9 00:51 /var/lib/idss/enroll.json

The key predates the box by eight days — it is the image build date. scripts/gateway-image/build.sh boots the build droplet with idss-agent.service enabled (nix/gateway-image/configuration.nix:116, byte-for-byte the install unit), the agent's first run mints the device key (devicekey.Load mints on absence, agent/cmd/agent/main.go ~112), and step 5 snapshots the disk with /var/lib/idss intact. Every rental from that snapshot therefore starts with the SAME device identity; installer-base-cache (Sep 1 07:30) confirms /var/lib/idss is deliberately carried (#1048's warm closure).

Why it matters: the device key is "the machine's durable device identity … the private half never leaves the machine" (#207). A key shared by every rented gateway means (a) two rentals are indistinguishable at the device-identity layer, (b) the private half has left the machine — it lives in a DO snapshot, and (c) the founding pairing binds a node identity to a key any other rental also holds. The gateway's node identity (node-req-0001) is minted at pairing so the community-level identity is still per-community — but the machine-level one is not, and anything that later leans on the device key (fleet removal guard #1219, the self-remove teardown #937, a future device-signed beat) inherits the collision.

Fix (image build): before the snapshot, clear the minted runtime identity so first boot mints its own — rm -f /var/lib/idss/device.key /var/lib/idss/resume.lease /var/lib/idss/enroll.json (keep installer-base-cache + agent-cache, which are content, not identity). Or stop the agent unit from starting during the build boot at all (a build-time systemd.services.idss-agent.enable = false overlay) if nothing else in the build needs it. Add a build-time assertion: the snapshot's /var/lib/idss carries no device.key. Audit the other snapshot-carried state under /var/lib (ssh host keys — sshd's ExecStartPre regenerates them per the build script header, so those are fine; anything else agent-minted).

Drive impact: every rented/device/device-vm drive since the image gained the agent unit has run on the shared key — no drive asserts device-key uniqueness, so nothing went red. Worth a leg: two rentals from one image carry different device keys.

**Seen** on the Whakatohea rented gateway (209.38.86.8, booted 2026-09-09 00:09 UTC from the current golden image): ``` -rw------- 1 root root 64 Sep 1 05:28 /var/lib/idss/device.key -rw------- 1 root root 2547 Sep 9 00:51 /var/lib/idss/enroll.json ``` The key predates the box by eight days — it is the image build date. `scripts/gateway-image/build.sh` boots the build droplet with `idss-agent.service` enabled (nix/gateway-image/configuration.nix:116, byte-for-byte the install unit), the agent's first run mints the device key (`devicekey.Load` mints on absence, agent/cmd/agent/main.go ~112), and step 5 snapshots the disk with `/var/lib/idss` intact. Every rental from that snapshot therefore starts with the SAME device identity; `installer-base-cache` (Sep 1 07:30) confirms `/var/lib/idss` is deliberately carried (#1048's warm closure). **Why it matters:** the device key is "the machine's durable device identity … the private half never leaves the machine" (#207). A key shared by every rented gateway means (a) two rentals are indistinguishable at the device-identity layer, (b) the private half has left the machine — it lives in a DO snapshot, and (c) the founding pairing binds a node identity to a key any other rental also holds. The gateway's node identity (`node-req-0001`) is minted at pairing so the community-level identity is still per-community — but the machine-level one is not, and anything that later leans on the device key (fleet removal guard #1219, the self-remove teardown #937, a future device-signed beat) inherits the collision. **Fix (image build):** before the snapshot, clear the minted runtime identity so first boot mints its own — `rm -f /var/lib/idss/device.key /var/lib/idss/resume.lease /var/lib/idss/enroll.json` (keep `installer-base-cache` + `agent-cache`, which are content, not identity). Or stop the agent unit from starting during the build boot at all (a build-time `systemd.services.idss-agent.enable = false` overlay) if nothing else in the build needs it. Add a build-time assertion: the snapshot's `/var/lib/idss` carries no `device.key`. Audit the other snapshot-carried state under `/var/lib` (ssh host keys — sshd's ExecStartPre regenerates them per the build script header, so those are fine; anything else agent-minted). **Drive impact:** every rented/device/device-vm drive since the image gained the agent unit has run on the shared key — no drive asserts device-key uniqueness, so nothing went red. Worth a leg: two rentals from one image carry different device keys.

This was generated by AI during triage.

Agent Brief

Category: bug
Summary: The build boot mints the agent's device identity (/var/lib/idss/device.key) and the genericness scrub never clears it, so every rented gateway boots from the golden snapshot carrying the same device key — the private half has left the machine and lives in a DO snapshot.

Current behavior:
During the golden-image build the idss-agent unit is enabled and starts on the build droplet's first boot; devicekey.Load mints /var/lib/idss/device.key on absence. The image build then scrubs only the build box's SSH identity — /etc/ssh/ssh_host_* and /root/.ssh/authorized_keys — before snapshotting, and the genericness assertion checks only those two. /var/lib/idss is deliberately carried into the snapshot (the #1048 warm closure), so the minted device.key (plus any other agent-minted runtime identity such as enroll.json / resume.lease) rides into the snapshot and every rental boots with it. Confirmed by inspection: the scrub command emitted by oc_gateway_image_scrub_cmd removes only the two SSH artefacts, and oc_gateway_image_generic_cmd asserts only their absence.

Desired behavior:
The golden snapshot must carry no agent-minted machine identity, so each rented gateway mints its own unique device.key on its own first boot (matching how each rental already mints a unique SSH host key). The genericness contract must fail loud — refusing to snapshot, naming the file — if agent-minted identity survived, exactly as it already does for a leaked host key (#707) or authorized_keys (#744).

The scrub must be precise: it removes the agent's minted identity (device.key, and the minted runtime state that binds to it — enroll.json, resume.lease) but must NOT touch the content the image legitimately carries and depends on for a warm founding — installer-base-cache, agent-cache, and the existing agent-state fixture the offline test already guards.

Key interfaces:

  • The scrub/genericness contract library (the oc_gateway_image_scrub_cmd / oc_gateway_image_generic_cmd pair, path-prefixed so the same strings run against a fake root offline and against / on the build box). Extend the scrub to remove the agent-minted identity under /var/lib/idss; extend the assertion to fail-by-name when device.key survives.
  • The device-identity contract: devicekey.Load mints on absence and the private half must never leave the machine (#207). The fix restores that invariant by ensuring absence at snapshot time.
  • Alternative/adjacent option the reporter raised: disable idss-agent during the build boot (a build-time systemd.services.idss-agent.enable = false overlay) so nothing mints identity in the first place — acceptable only if nothing else in the build depends on the agent having run. The scrub-before-snapshot path is preferred because it is a positive assertion the contract test can pin regardless of what runs during the build.

Acceptance criteria:

  • The offline generic-image contract test (scripts/gateway-image/tests/gateway-image-generic-test.sh) is extended: the scrub removes /var/lib/idss/device.key (and enroll.json / resume.lease) from a fake root, and leaves installer-base-cache/agent-cache/agent-state-class content untouched.
  • The genericness assertion FAILS, naming the file, when device.key survives on the fake root (a new case alongside the existing #707/#744 cases C/D), and PASSES on a scrubbed root.
  • The scrub is idempotent (a device.key-absent root is rc=0), matching the existing SSH-scrub behavior.
  • bash scripts/gateway-image/tests/gateway-image-generic-test.sh passes offline (no DO account, no droplet).
  • Optional but recommended: a drive leg asserting two rentals from one image carry different device.key values (the reporter notes no current drive asserts device-key uniqueness, which is why this went red-free).

Out of scope:

  • Rotating or re-minting device keys on already-running rented gateways (this fixes the image; existing shared-key boxes are a separate remediation).
  • Changing what /var/lib/idss legitimately carries for the warm closure (#1048) — content stays; only minted identity is scrubbed.
  • The downstream device-key consumers (fleet removal guard #1219, self-remove teardown #937) — they inherit the fix, no change needed here.

Ruled by agent under ADR 0174 — veto anytime. Considered ready-for-human and ruled ready-for-agent. This is a two-way door: (a) revertible by a single commit to unprotected paths (scripts/lib/gateway-image-generic-lib.sh and its offline test — neither is a .sandcastle/.forgejo protected path); (b) provable offline by the existing gateway-image-generic-test.sh harness, which already path-prefixes the scrub/assert pair against a fake root and already models a legitimately-carried /var/lib/idss/agent-state. It is not on the one-way-door list: it is a security tightening (removing a shared secret), not a widening; the device key is a machine-minted runtime artefact, not a personal credential; and clearing a build-time key that regenerates on first boot is not data destruction. The fix lives in snapshot-baking paths (scripts/gateway-image/**), so once merged the executor will swap it to snapshot-pending for the #661 auto-rebuild rail to verify against a real image — the offline test is the agent's acceptance gate, not a live build.

> *This was generated by AI during triage.* ## Agent Brief **Category:** bug **Summary:** The build boot mints the agent's device identity (`/var/lib/idss/device.key`) and the genericness scrub never clears it, so every rented gateway boots from the golden snapshot carrying the *same* device key — the private half has left the machine and lives in a DO snapshot. **Current behavior:** During the golden-image build the `idss-agent` unit is enabled and starts on the build droplet's first boot; `devicekey.Load` mints `/var/lib/idss/device.key` on absence. The image build then scrubs only the build box's SSH identity — `/etc/ssh/ssh_host_*` and `/root/.ssh/authorized_keys` — before snapshotting, and the genericness assertion checks only those two. `/var/lib/idss` is deliberately carried into the snapshot (the #1048 warm closure), so the minted `device.key` (plus any other agent-minted runtime identity such as `enroll.json` / `resume.lease`) rides into the snapshot and every rental boots with it. Confirmed by inspection: the scrub command emitted by `oc_gateway_image_scrub_cmd` removes only the two SSH artefacts, and `oc_gateway_image_generic_cmd` asserts only their absence. **Desired behavior:** The golden snapshot must carry **no** agent-minted machine identity, so each rented gateway mints its own unique `device.key` on its own first boot (matching how each rental already mints a unique SSH host key). The genericness contract must fail loud — refusing to snapshot, naming the file — if agent-minted identity survived, exactly as it already does for a leaked host key (#707) or `authorized_keys` (#744). The scrub must be **precise**: it removes the agent's minted *identity* (`device.key`, and the minted runtime state that binds to it — `enroll.json`, `resume.lease`) but must NOT touch the *content* the image legitimately carries and depends on for a warm founding — `installer-base-cache`, `agent-cache`, and the existing `agent-state` fixture the offline test already guards. **Key interfaces:** - The scrub/genericness contract library (the `oc_gateway_image_scrub_cmd` / `oc_gateway_image_generic_cmd` pair, path-prefixed so the same strings run against a fake root offline and against `/` on the build box). Extend the scrub to remove the agent-minted identity under `/var/lib/idss`; extend the assertion to fail-by-name when `device.key` survives. - The device-identity contract: `devicekey.Load` mints on absence and the private half must never leave the machine (#207). The fix restores that invariant by ensuring absence at snapshot time. - Alternative/adjacent option the reporter raised: disable `idss-agent` during the build boot (a build-time `systemd.services.idss-agent.enable = false` overlay) so nothing mints identity in the first place — acceptable only if nothing else in the build depends on the agent having run. The scrub-before-snapshot path is preferred because it is a positive assertion the contract test can pin regardless of what runs during the build. **Acceptance criteria:** - [ ] The offline generic-image contract test (`scripts/gateway-image/tests/gateway-image-generic-test.sh`) is extended: the scrub removes `/var/lib/idss/device.key` (and `enroll.json` / `resume.lease`) from a fake root, and leaves `installer-base-cache`/`agent-cache`/`agent-state`-class content untouched. - [ ] The genericness assertion FAILS, naming the file, when `device.key` survives on the fake root (a new case alongside the existing #707/#744 cases C/D), and PASSES on a scrubbed root. - [ ] The scrub is idempotent (a `device.key`-absent root is rc=0), matching the existing SSH-scrub behavior. - [ ] `bash scripts/gateway-image/tests/gateway-image-generic-test.sh` passes offline (no DO account, no droplet). - [ ] Optional but recommended: a drive leg asserting two rentals from one image carry *different* `device.key` values (the reporter notes no current drive asserts device-key uniqueness, which is why this went red-free). **Out of scope:** - Rotating or re-minting device keys on already-running rented gateways (this fixes the image; existing shared-key boxes are a separate remediation). - Changing what `/var/lib/idss` legitimately carries for the warm closure (#1048) — content stays; only minted identity is scrubbed. - The downstream device-key consumers (fleet removal guard #1219, self-remove teardown #937) — they inherit the fix, no change needed here. --- **Ruled by agent under ADR 0174 — veto anytime.** Considered `ready-for-human` and ruled `ready-for-agent`. This is a **two-way door**: (a) revertible by a single commit to unprotected paths (`scripts/lib/gateway-image-generic-lib.sh` and its offline test — neither is a `.sandcastle`/`.forgejo` protected path); (b) provable **offline** by the existing `gateway-image-generic-test.sh` harness, which already path-prefixes the scrub/assert pair against a fake root and already models a legitimately-carried `/var/lib/idss/agent-state`. It is **not** on the one-way-door list: it is a security *tightening* (removing a shared secret), not a widening; the device key is a machine-minted runtime artefact, not a personal credential; and clearing a build-time key that regenerates on first boot is not data destruction. The fix lives in snapshot-baking paths (`scripts/gateway-image/**`), so once merged the executor will swap it to `snapshot-pending` for the #661 auto-rebuild rail to verify against a real image — the offline test is the agent's acceptance gate, not a live build.

swarm-claim host=matou-dev-server-01 run=20418
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=20418 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #1346 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 1346,
  "status": "success",
  "commits": [
    "df1c0607"
  ],
  "changed_files": [
    "scripts/lib/gateway-image-generic-lib.sh",
    "scripts/gateway-image/tests/gateway-image-generic-test.sh",
    "docs/GOTCHAS.md",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash scripts/gateway-image/tests/gateway-image-generic-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "The offline generic-image contract test is extended: the scrub removes /var/lib/idss/device.key (and enroll.json / resume.lease) from a fake root, and leaves installer-base-cache/agent-cache/agent-state-class content untouched": "gateway-image-generic-test.sh check A: mkfake now seeds device.key/ssh_host_ed25519_key/resume.json/resume.lease/enroll.json plus installer-base-cache/, agent-cache/x86_64/vm-guest.tar and agent-state; after oc_gateway_image_scrub_cmd the five identity files are asserted absent and all content + agent-state asserted present",
    "The genericness assertion FAILS, naming the file, when device.key survives (a new case alongside C/D), and PASSES on a scrubbed root": "new case F asserts rc!=0, out contains 'device.key' and '1346' when only the /var/lib/idss identity survives; case B asserts rc=0 + 'generic' on a scrubbed root",
    "The scrub is idempotent (a device.key-absent root is rc=0), matching the existing SSH-scrub behavior": "existing idempotent check (root with only etc/ssh + root/.ssh, no /var/lib/idss) runs the extended scrub rc=0 then assertion rc=0; scrub uses rm -f on exact names",
    "bash scripts/gateway-image/tests/gateway-image-generic-test.sh passes offline (no DO account, no droplet)": "test run exit_code 0, 6 checks passed",
    "Optional but recommended: a drive leg asserting two rentals from one image carry different device.key values": "NOT done — a live build/drive, out of the offline agent gate; rides #661's auto-rebuild rail once the image is rebuilt from this fix (issue marks it optional)"
  },
  "summary": "The generic-image scrub/assertion now also drops (and proves absent) the agent-minted machine identity under /var/lib/idss so each rented gateway mints its own unique device.key instead of sharing the build box's.",
  "reason": "Extends the ADR 0048 generic-image contract from SSH-only to every minted identity, closing the shared-device-key leak (#1346) provably offline.",
  "blockers": []
}
**close-report** for #1346 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 1346, "status": "success", "commits": [ "df1c0607" ], "changed_files": [ "scripts/lib/gateway-image-generic-lib.sh", "scripts/gateway-image/tests/gateway-image-generic-test.sh", "docs/GOTCHAS.md", "STATUS.md" ], "tests": [ { "command": "bash scripts/gateway-image/tests/gateway-image-generic-test.sh", "exit_code": 0 } ], "criteria": { "The offline generic-image contract test is extended: the scrub removes /var/lib/idss/device.key (and enroll.json / resume.lease) from a fake root, and leaves installer-base-cache/agent-cache/agent-state-class content untouched": "gateway-image-generic-test.sh check A: mkfake now seeds device.key/ssh_host_ed25519_key/resume.json/resume.lease/enroll.json plus installer-base-cache/, agent-cache/x86_64/vm-guest.tar and agent-state; after oc_gateway_image_scrub_cmd the five identity files are asserted absent and all content + agent-state asserted present", "The genericness assertion FAILS, naming the file, when device.key survives (a new case alongside C/D), and PASSES on a scrubbed root": "new case F asserts rc!=0, out contains 'device.key' and '1346' when only the /var/lib/idss identity survives; case B asserts rc=0 + 'generic' on a scrubbed root", "The scrub is idempotent (a device.key-absent root is rc=0), matching the existing SSH-scrub behavior": "existing idempotent check (root with only etc/ssh + root/.ssh, no /var/lib/idss) runs the extended scrub rc=0 then assertion rc=0; scrub uses rm -f on exact names", "bash scripts/gateway-image/tests/gateway-image-generic-test.sh passes offline (no DO account, no droplet)": "test run exit_code 0, 6 checks passed", "Optional but recommended: a drive leg asserting two rentals from one image carry different device.key values": "NOT done — a live build/drive, out of the offline agent gate; rides #661's auto-rebuild rail once the image is rebuilt from this fix (issue marks it optional)" }, "summary": "The generic-image scrub/assertion now also drops (and proves absent) the agent-minted machine identity under /var/lib/idss so each rented gateway mints its own unique device.key instead of sharing the build box's.", "reason": "Extends the ADR 0048 generic-image contract from SSH-only to every minted identity, closing the shared-device-key leak (#1346) provably offline.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
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#1346
No description provided.