device-add: the printed install one-liner needs root but carries no sudo — as an ordinary user it dies with a bare curl: (23) #2002

Closed
opened 2026-09-30 01:11:55 +00:00 by ben · 3 comments
Owner

Symptom

The control panel's device-add code screen prints curl -sSf https://<apex>/get | sh -s -- <CODE> (dashboard/src/lib/deviceAdd.ts:321). Run as it is printed, by the machine's ordinary user, it dies:

idss: fetching this community's pinned agent from whakatohea-demo.idss.nz…
curl: (23) Failure writing output to destination

Seen 2026-09-30 00:3xZ on bens-mac-04 (Ubuntu 24.04) joining Whakatōhea Demo by hand.

Cause

The served script (internal/controlapi/installscript.go:46) writes the agent to /usr/local/bin/.idss-agent.tmp, which is root-owned. Nothing in the script checks id -u, and nothing in the printed command or the code screen's copy says the command needs root. The only signal is curl's exit 23, which names neither the path nor the reason.

Fix

  • The served script refuses at the top when it is not root, with one honest line: what it needs to write and that the command must run under sudo (… | sudo sh -s -- <CODE>). Exit non-zero before any fetch.
  • The printed command (dashboard installCommand, and the rented/own-VPS forms that build the same line in internal/controlapi/enroll_rent.go:271) carries the sudo, or the code screen's copy says it plainly beside the command. The wireframe for P2-S2 is the contract — check it before changing the printed line.
  • A seam test for the script's non-root refusal; the dashboard test for the printed command.

Found in the same hand run as the cold-install VM-create defect and the silent guest download (filed alongside).

Siblings

Found in the one hand run (bens-mac-04 → Whakatōhea Demo, 2026-09-30): #2003 #2004 #2005 #2006 #2007

## Symptom The control panel's device-add code screen prints `curl -sSf https://<apex>/get | sh -s -- <CODE>` (`dashboard/src/lib/deviceAdd.ts:321`). Run as it is printed, by the machine's ordinary user, it dies: ``` idss: fetching this community's pinned agent from whakatohea-demo.idss.nz… curl: (23) Failure writing output to destination ``` Seen 2026-09-30 00:3xZ on `bens-mac-04` (Ubuntu 24.04) joining Whakatōhea Demo by hand. ## Cause The served script (`internal/controlapi/installscript.go:46`) writes the agent to `/usr/local/bin/.idss-agent.tmp`, which is root-owned. Nothing in the script checks `id -u`, and nothing in the printed command or the code screen's copy says the command needs root. The only signal is curl's exit 23, which names neither the path nor the reason. ## Fix - The served script refuses at the top when it is not root, with one honest line: what it needs to write and that the command must run under `sudo` (`… | sudo sh -s -- <CODE>`). Exit non-zero before any fetch. - The printed command (dashboard `installCommand`, and the rented/own-VPS forms that build the same line in `internal/controlapi/enroll_rent.go:271`) carries the `sudo`, or the code screen's copy says it plainly beside the command. The wireframe for P2-S2 is the contract — check it before changing the printed line. - A seam test for the script's non-root refusal; the dashboard test for the printed command. ## Related Found in the same hand run as the cold-install VM-create defect and the silent guest download (filed alongside). ## Siblings Found in the one hand run (bens-mac-04 → Whakatōhea Demo, 2026-09-30): #2003 #2004 #2005 #2006 #2007

swarm-claim host=bens-mac-04 run=36153
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=bens-mac-04 run=36153 (automated multi-host claim — lowest live claim id works this ticket)

Ruled by agent under ADR 0174 — veto anytime.

Scope note on enroll_rent.go (line ~271, deviceEnrolCloudInit). The Fix lists the rented/own-VPS form as a place to carry sudo, but that builder emits cloud-init user-data (#!/bin/sh run at the generic gateway image's first boot, CloudInit: at enroll_rent.go:213) — cloud-init runs it as root, so the served script's new non-root guard passes there without a change. Adding sudo to that path would be wrong: a minimal cloud image may not ship sudo and there is no controlling terminal at first boot, so it could break the auto-enrol the operator never sees. Left unchanged.

Two-way door: revertible by a one-line edit; proven by go test ./internal/controlapi/ (the served-script root guard) and the dashboard unit test on the printed command.

Shipped: the served script (installscript.go) refuses before any fetch when id -u is non-zero, naming /usr/local/bin and the | sudo sh -s -- <CODE> form; the printed operator one-liner (dashboard installCommand) and the P2-S2 wireframe both carry sudo.

Ruled by agent under ADR 0174 — veto anytime. **Scope note on `enroll_rent.go` (line ~271, `deviceEnrolCloudInit`).** The Fix lists the rented/own-VPS form as a place to carry `sudo`, but that builder emits **cloud-init user-data** (`#!/bin/sh` run at the generic gateway image's first boot, `CloudInit:` at enroll_rent.go:213) — cloud-init runs it **as root**, so the served script's new non-root guard passes there without a change. Adding `sudo` to that path would be wrong: a minimal cloud image may not ship sudo and there is no controlling terminal at first boot, so it could break the auto-enrol the operator never sees. Left unchanged. **Two-way door:** revertible by a one-line edit; proven by `go test ./internal/controlapi/` (the served-script root guard) and the dashboard unit test on the printed command. **Shipped:** the served script (`installscript.go`) refuses before any fetch when `id -u` is non-zero, naming `/usr/local/bin` and the `| sudo sh -s -- <CODE>` form; the printed operator one-liner (dashboard `installCommand`) and the P2-S2 wireframe both carry `sudo`.

close-report for #2002 — status success

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

envelope
{
  "issue": 2002,
  "status": "success",
  "commits": [
    "c03ce4abe8d633db171851df5e38a9be29ff1f3c"
  ],
  "changed_files": [
    "internal/controlapi/installscript.go",
    "internal/controlapi/install_doorway_test.go",
    "dashboard/src/lib/deviceAdd.ts",
    "dashboard/tests/unit/deviceAdd.test.ts",
    "docs/ux/wireframes/p2-device-add-cli/p2-s2-code-and-install-command.html"
  ],
  "tests": [
    {
      "command": "nix develop .#go-ci --command go test ./internal/controlapi/",
      "exit_code": 0
    },
    {
      "command": "npx vitest run tests/unit/deviceAdd.test.ts",
      "exit_code": 0
    }
  ],
  "criteria": {
    "The served script refuses at the top when not root, with one honest line (what it writes + the sudo form), exiting non-zero before any fetch": "installscript.go adds `if [ \"$(id -u)\" -ne 0 ]` naming /usr/local/bin and `| sudo sh -s -- <CODE>`, `exit 1`, placed before the arch/curl fetch; proven by TestInstallDoorway_ScriptRefusesWhenNotRoot (install_doorway_test.go) which asserts the guard text and that it precedes the fetch line",
    "The printed command carries sudo (dashboard installCommand); the P2-S2 wireframe contract stays in sync": "deviceAdd.ts installCommand now returns `curl -sSf https://<domain>/get | sudo sh -s -- <code>`; p2-s2-code-and-install-command.html codebox updated to `| sudo sh -s --`; proven by deviceAdd.test.ts (printed command carries `| sudo sh -s --`)",
    "A seam test for the script's non-root refusal; the dashboard test for the printed command": "TestInstallDoorway_ScriptRefusesWhenNotRoot (seam) + deviceAdd.test.ts assertions (printed command)"
  },
  "summary": "The device-add install one-liner now carries sudo and the served script refuses loud before any fetch when not root, replacing the bare curl: (23).",
  "blockers": []
}
**close-report** for #2002 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 2002, "status": "success", "commits": [ "c03ce4abe8d633db171851df5e38a9be29ff1f3c" ], "changed_files": [ "internal/controlapi/installscript.go", "internal/controlapi/install_doorway_test.go", "dashboard/src/lib/deviceAdd.ts", "dashboard/tests/unit/deviceAdd.test.ts", "docs/ux/wireframes/p2-device-add-cli/p2-s2-code-and-install-command.html" ], "tests": [ { "command": "nix develop .#go-ci --command go test ./internal/controlapi/", "exit_code": 0 }, { "command": "npx vitest run tests/unit/deviceAdd.test.ts", "exit_code": 0 } ], "criteria": { "The served script refuses at the top when not root, with one honest line (what it writes + the sudo form), exiting non-zero before any fetch": "installscript.go adds `if [ \"$(id -u)\" -ne 0 ]` naming /usr/local/bin and `| sudo sh -s -- <CODE>`, `exit 1`, placed before the arch/curl fetch; proven by TestInstallDoorway_ScriptRefusesWhenNotRoot (install_doorway_test.go) which asserts the guard text and that it precedes the fetch line", "The printed command carries sudo (dashboard installCommand); the P2-S2 wireframe contract stays in sync": "deviceAdd.ts installCommand now returns `curl -sSf https://<domain>/get | sudo sh -s -- <code>`; p2-s2-code-and-install-command.html codebox updated to `| sudo sh -s --`; proven by deviceAdd.test.ts (printed command carries `| sudo sh -s --`)", "A seam test for the script's non-root refusal; the dashboard test for the printed command": "TestInstallDoorway_ScriptRefusesWhenNotRoot (seam) + deviceAdd.test.ts assertions (printed command)" }, "summary": "The device-add install one-liner now carries sudo and the served script refuses loud before any fetch when not root, replacing the bare curl: (23).", "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#2002
No description provided.