Device-add one-liner cannot answer its own consent prompt under sudo's pty (sudo-rs on Ubuntu 26.04 / use_pty on 24.04): /dev/tty is sudo's inner pty fed by the dead curl pipe, the install is parked by SIGTTIN #2038

Closed
opened 2026-10-02 22:57:37 +00:00 by ben · 2 comments
Owner

Symptom (Whakatōhea Demo, device add, 2026-10-03)

Ben ran the published device-add one-liner on a stock Ubuntu 26.04.1 box (whakatohea, 100.98.84.207):

curl -sSf https://whakatohea-demo.idss.nz/get | sudo sh -s -- <CODE>

The agent installed, the standing idss-agent.service came up, the P2-S3 menu (How should this machine contribute?, [1] Full install …, > ) was drawn — and then nothing. Typing 1 + Enter produced no Choose 1–2., no consent text, no Type WIPE to consent. Re-running the one-liner reproduced it exactly. No error, no exit: a silent prompt, for over an hour.

Evidence

PID   PPID  PGID  TPGID SID   TTY   STAT ARGS
26023 23936 26022 26022 23936 pts/1 S+   sudo sh -s -- <CODE>          # outer sudo, the user's real terminal
26034 26023 26034 26035 26034 pts/0 Ss   sudo sh -s -- <CODE>          # sudo's monitor, session leader of a NEW pty
26035 26034 26035 26035 26034 pts/0 S+   sh -s -- <CODE>
26043 26035 26035 26035 26034 pts/0 Tl+  idss-agent install <CODE>     # STOPPED
  • /proc/26043/status: State: T (stopped), ShdPnd: 0000000000100000 (bit 20 = SIGTTIN), wchan do_signal_stop.
  • /proc/26043/fd/0 -> /dev/tty, which resolves to pts/0 — sudo's inner pty, not the user's pts/1.
  • /proc/26034/fd/0 -> pipe:[89641] — the inner pty's input source is the exhausted curl pipe.
  • sudo -V → sudo-rs 0.2.13-0ubuntu1.2. Ubuntu 26.04 ships sudo-rs as sudo; it always runs the command in its own pty.
  • /var/lib/idss/resume.json absent, idss-agent.service journal silent since start: the request never paired. The code survives.

Cause

GOTCHAS #113 (#938) fixed the curl … | sh EOF trap by reattaching /dev/tty in the served script (internal/controlapi/installscript.go) and belt-and-braces in the binary (agent/cmd/agent/consent_input.go). Both assume /dev/tty is the person's terminal. Under sudo with a pty (sudo-rs always; sudo 1.9.14+ with use_pty, the Debian/Ubuntu default since 24.04), /dev/tty is sudo's inner pty, whose input sudo feeds from its own stdin — the curl pipe. The user's keystrokes land on the outer pty and are never relayed. The consent prompt reads a terminal nobody can type into; the kernel job-control stop (SIGTTIN) makes it worse: the process is not even blocked in read(), it is stopped, so kill -TERM does nothing until a -CONT.

Every surface that prints the one-liner prints the sudo form: dashboard/src/lib/deviceAdd.ts:358 (the CodeScreen), installscript.go:32/36 (the script's own usage lines), docs/ux/wireframes/p2-device-add-cli/p2-s2-code-and-install-command.html. #2002 added the root refusal that makes sudo mandatory. So on any current Ubuntu the published doorway cannot answer its own consent prompt — the exact failure class #938 was meant to close, one layer further out.

Fix (proposed — two-way door, ADR 0174)

Make the served script immune to the wrapper it is run under, rather than teaching every surface a new incantation:

  1. Change the printed one-liner's shape so the script never rides stdin and sudo's stdin stays the real terminal. Inside sudo's pty there is no path back to the user's terminal, so no in-script /dev/tty trick can fix this; the fix is one layer out, in the command people copy. Recommended form (one line, no temp file, copy-pasteable):

    sudo sh -c "$(curl -sSf https://<apex>/get)" sh <CODE>
    

    The shell evaluates $(curl …) BEFORE sudo runs, sudo's fd 0 is the terminal, its pty relays keystrokes, and /dev/tty inside is answerable. (curl … | sudo sh -s -- <CODE> < /dev/tty does NOT work: the script arrives on the pipe. curl -o f && sudo sh f <CODE> works but is two commands.)

  2. Update every printing surface to the new form: deviceAdd.ts (installCommand), installscript.go usage/no-code lines, the agent's consentInput error hint, the p2-s2 wireframe, ADR 0054's example, enroll_rent.go:273 if the rented box path prints it too.

  3. consentInput (the binary's belt-and-braces): when /dev/tty opens but is not the foreground, or when the first read is interrupted by SIGTTIN, fail loud naming the fix (run it as: sudo sh -c "$(curl -sSf https://<origin>/get)" sh <CODE>) instead of letting the kernel park the process. Catch SIGTTIN via signal.Notify so the stop becomes a typed error, never a silent T.

  4. Seam test: render the script, run it with dash under a fake sudo that wraps the command in a fresh pty whose input is a closed pipe (the sudo-rs shape), assert the consent prompt is answered from the outer pty within the timeout. The existing #938 test covers the pipe-only case and stays green on this bug — that is why it was not caught.

Acceptance

  • On Ubuntu 26.04 (sudo-rs) and 24.04 (sudo use_pty), the one-liner the control panel's CodeScreen prints reaches Type WIPE to consent, accepts WIPE, and prints ✓ connection request sent.
  • Running the OLD curl … | sudo sh -s -- form prints one honest line naming the new form and exits non-zero within seconds — never a stopped process.
  • go test ./internal/controlapi/... ./agent/... ./internal/join/... green; the dashboard deviceAdd unit test asserts the new command shape.
  • GOTCHAS #388 (filed with this ticket) stays accurate; update it in the same commit if the chosen form differs.

GOTCHAS #113 (#938), #2002 (root refusal), ADR 0054, ADR 0024, internal/controlapi/installscript.go, agent/cmd/agent/consent_input.go, dashboard/src/lib/deviceAdd.ts.

## Symptom (Whakatōhea Demo, device add, 2026-10-03) Ben ran the published device-add one-liner on a stock Ubuntu 26.04.1 box (`whakatohea`, 100.98.84.207): ``` curl -sSf https://whakatohea-demo.idss.nz/get | sudo sh -s -- <CODE> ``` The agent installed, the standing `idss-agent.service` came up, the P2-S3 menu (`How should this machine contribute?`, `[1] Full install …`, `> `) was drawn — and then nothing. Typing `1` + Enter produced no `Choose 1–2.`, no consent text, no `Type WIPE to consent`. Re-running the one-liner reproduced it exactly. No error, no exit: a silent prompt, for over an hour. ## Evidence ``` PID PPID PGID TPGID SID TTY STAT ARGS 26023 23936 26022 26022 23936 pts/1 S+ sudo sh -s -- <CODE> # outer sudo, the user's real terminal 26034 26023 26034 26035 26034 pts/0 Ss sudo sh -s -- <CODE> # sudo's monitor, session leader of a NEW pty 26035 26034 26035 26035 26034 pts/0 S+ sh -s -- <CODE> 26043 26035 26035 26035 26034 pts/0 Tl+ idss-agent install <CODE> # STOPPED ``` - `/proc/26043/status`: `State: T (stopped)`, `ShdPnd: 0000000000100000` (bit 20 = **SIGTTIN**), wchan `do_signal_stop`. - `/proc/26043/fd/0 -> /dev/tty`, which resolves to **pts/0** — sudo's inner pty, not the user's pts/1. - `/proc/26034/fd/0 -> pipe:[89641]` — the inner pty's input source is the **exhausted curl pipe**. - `sudo -V` → `sudo-rs 0.2.13-0ubuntu1.2`. Ubuntu 26.04 ships sudo-rs as `sudo`; it always runs the command in its own pty. - `/var/lib/idss/resume.json` absent, `idss-agent.service` journal silent since start: the request never paired. The code survives. ## Cause GOTCHAS #113 (#938) fixed the `curl … | sh` EOF trap by reattaching `/dev/tty` in the served script (`internal/controlapi/installscript.go`) and belt-and-braces in the binary (`agent/cmd/agent/consent_input.go`). Both assume `/dev/tty` **is the person's terminal**. Under `sudo` with a pty (sudo-rs always; sudo 1.9.14+ with `use_pty`, the Debian/Ubuntu default since 24.04), `/dev/tty` is sudo's inner pty, whose input sudo feeds from **its own stdin** — the curl pipe. The user's keystrokes land on the outer pty and are never relayed. The consent prompt reads a terminal nobody can type into; the kernel job-control stop (SIGTTIN) makes it worse: the process is not even blocked in `read()`, it is stopped, so `kill -TERM` does nothing until a `-CONT`. Every surface that prints the one-liner prints the `sudo` form: `dashboard/src/lib/deviceAdd.ts:358` (the CodeScreen), `installscript.go:32/36` (the script's own usage lines), `docs/ux/wireframes/p2-device-add-cli/p2-s2-code-and-install-command.html`. #2002 added the root refusal that makes `sudo` mandatory. So on any current Ubuntu the published doorway **cannot answer its own consent prompt** — the exact failure class #938 was meant to close, one layer further out. ## Fix (proposed — two-way door, ADR 0174) Make the served script immune to the wrapper it is run under, rather than teaching every surface a new incantation: 1. **Change the printed one-liner's shape so the script never rides stdin and sudo's stdin stays the real terminal.** Inside sudo's pty there is no path back to the user's terminal, so no in-script `/dev/tty` trick can fix this; the fix is one layer out, in the command people copy. Recommended form (one line, no temp file, copy-pasteable): ``` sudo sh -c "$(curl -sSf https://<apex>/get)" sh <CODE> ``` The shell evaluates `$(curl …)` BEFORE sudo runs, sudo's fd 0 is the terminal, its pty relays keystrokes, and `/dev/tty` inside is answerable. (`curl … | sudo sh -s -- <CODE> < /dev/tty` does NOT work: the script arrives on the pipe. `curl -o f && sudo sh f <CODE>` works but is two commands.) 2. Update every printing surface to the new form: `deviceAdd.ts` (`installCommand`), `installscript.go` usage/no-code lines, the agent's `consentInput` error hint, the p2-s2 wireframe, ADR 0054's example, `enroll_rent.go:273` if the rented box path prints it too. 3. `consentInput` (the binary's belt-and-braces): when `/dev/tty` opens but is **not the foreground**, or when the first read is interrupted by SIGTTIN, fail loud naming the fix (`run it as: sudo sh -c "$(curl -sSf https://<origin>/get)" sh <CODE>`) instead of letting the kernel park the process. Catch `SIGTTIN` via `signal.Notify` so the stop becomes a typed error, never a silent `T`. 4. Seam test: render the script, run it with `dash` under a fake `sudo` that wraps the command in a fresh pty whose input is a closed pipe (the sudo-rs shape), assert the consent prompt is answered from the outer pty within the timeout. The existing #938 test covers the pipe-only case and stays green on this bug — that is why it was not caught. ## Acceptance - On Ubuntu 26.04 (sudo-rs) and 24.04 (sudo `use_pty`), the one-liner the control panel's CodeScreen prints reaches `Type WIPE to consent`, accepts `WIPE`, and prints `✓ connection request sent`. - Running the OLD `curl … | sudo sh -s --` form prints one honest line naming the new form and exits non-zero within seconds — never a stopped process. - `go test ./internal/controlapi/... ./agent/... ./internal/join/...` green; the dashboard `deviceAdd` unit test asserts the new command shape. - GOTCHAS #388 (filed with this ticket) stays accurate; update it in the same commit if the chosen form differs. ## Related GOTCHAS #113 (#938), #2002 (root refusal), ADR 0054, ADR 0024, `internal/controlapi/installscript.go`, `agent/cmd/agent/consent_input.go`, `dashboard/src/lib/deviceAdd.ts`.

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

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

close-report for #2038 — status success

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

⚠️ cross_repo_waiver: No changed file is a cross-repo-mirrors.tsv trigger (the app-door and spaces-door goldens are untouched).

envelope
{
  "issue": 2038,
  "status": "success",
  "commits": [
    "fe071837d21f4b7ad29b53b035265411fe6d88ec"
  ],
  "changed_files": [
    "STATUS.md",
    "agent/cmd/agent/consent_input.go",
    "agent/cmd/agent/consent_input_test.go",
    "app/tests/e2e/fixtures/deviceAdd.test.ts",
    "app/tests/e2e/fixtures/deviceAdd.ts",
    "dashboard/src/lib/deviceAdd.ts",
    "dashboard/tests/unit/deviceAdd.test.ts",
    "docs/GOTCHAS.md",
    "docs/adr/0054-install-artifacts-split-gateway-serves-script-agent.md",
    "docs/ux/wireframes/p2-device-add-cli/p2-s2-code-and-install-command.html",
    "internal/controlapi/install_doorway.go",
    "internal/controlapi/install_doorway_test.go",
    "internal/controlapi/installscript.go",
    "internal/join/cli.go",
    "internal/join/cli_test.go"
  ],
  "tests": [
    {
      "command": "go test ./internal/controlapi/... ./agent/... ./internal/join/...",
      "exit_code": 0
    },
    {
      "command": "CI=true pnpm exec vitest run tests/unit/deviceAdd.test.ts (dashboard)",
      "exit_code": 0
    },
    {
      "command": "CI=true pnpm exec vitest run tests/e2e/fixtures/deviceAdd.test.ts (app)",
      "exit_code": 0
    },
    {
      "command": "pre-push gate: nix develop .#go-ci (gofmt/build/vet/go test ./.../golangci-lint, main + broker) and .#default pnpm run lint — passed on push",
      "exit_code": 0
    }
  ],
  "criteria": {
    "On Ubuntu 26.04 (sudo-rs) and 24.04 (sudo use_pty), the one-liner the CodeScreen prints reaches Type WIPE to consent, accepts WIPE, and prints the connection-request confirmation": "The CodeScreen prints installCommand() = `sudo sh -c \"$(curl -sSf https://<apex>/get)\" sh <CODE>` (dashboard/src/lib/deviceAdd.ts) — curl evaluated BEFORE sudo, so sudo's fd0/pty is the operator's terminal and the served script's stdin IS that terminal; consentInput returns the terminal stdin unchanged (agent/cmd/agent/consent_input.go, TestConsentInput_TerminalStdinIsReadNotDetoured). Live sudo-rs pty leg noted unproven_by_seam.",
    "Running the OLD curl … | sudo sh -s -- form prints one honest line naming the new form and exits non-zero within seconds — never a stopped process": "consent_input.go ignores SIGTTIN (signal.Ignore) so the dead-pty read returns EIO rather than parking in state T, and guardedTTY translates that EIO into a loud error naming `sudo sh -c \"$(curl …)\" sh <CODE>` (TestGuardedTTY_BackgroundReadFailsLoudNamingTheForm); join/cli.go chooseMode now surfaces that read error instead of flattening to \"terminal closed\" (TestTerminal_ConsentReadErrorSurfaces). The app fixture rejects the old pipe form (app/tests/e2e/fixtures/deviceAdd.test.ts).",
    "go test ./internal/controlapi/... ./agent/... ./internal/join/... green; the dashboard deviceAdd unit test asserts the new command shape": "go test of the three suites exit 0; dashboard/tests/unit/deviceAdd.test.ts asserts `sudo sh -c \"$(curl -sSf https://admin.example.nz/get)\" sh <code>` and that the command never contains `| sudo sh`.",
    "GOTCHAS #388 stays accurate; update it in the same commit if the chosen form differs": "Chosen form matches #388's recommendation exactly; docs/GOTCHAS.md #388 gets a Fixed (#2038) note and the Rule's signal detail corrected to signal.Ignore (POSIX: EIO only when SIGTTIN is ignored)."
  },
  "cross_repo_waiver": "No changed file is a cross-repo-mirrors.tsv trigger (the app-door and spaces-door goldens are untouched).",
  "summary": "The published device-add one-liner now uses the sudo-pty-safe `sudo sh -c \"$(curl …)\" sh <CODE>` shape across every printing surface, and the agent fails loud (never SIGTTIN-parked) on the old pipe form.",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #2038 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. > :warning: **cross_repo_waiver:** No changed file is a cross-repo-mirrors.tsv trigger (the app-door and spaces-door goldens are untouched). <details><summary>envelope</summary> ```json { "issue": 2038, "status": "success", "commits": [ "fe071837d21f4b7ad29b53b035265411fe6d88ec" ], "changed_files": [ "STATUS.md", "agent/cmd/agent/consent_input.go", "agent/cmd/agent/consent_input_test.go", "app/tests/e2e/fixtures/deviceAdd.test.ts", "app/tests/e2e/fixtures/deviceAdd.ts", "dashboard/src/lib/deviceAdd.ts", "dashboard/tests/unit/deviceAdd.test.ts", "docs/GOTCHAS.md", "docs/adr/0054-install-artifacts-split-gateway-serves-script-agent.md", "docs/ux/wireframes/p2-device-add-cli/p2-s2-code-and-install-command.html", "internal/controlapi/install_doorway.go", "internal/controlapi/install_doorway_test.go", "internal/controlapi/installscript.go", "internal/join/cli.go", "internal/join/cli_test.go" ], "tests": [ { "command": "go test ./internal/controlapi/... ./agent/... ./internal/join/...", "exit_code": 0 }, { "command": "CI=true pnpm exec vitest run tests/unit/deviceAdd.test.ts (dashboard)", "exit_code": 0 }, { "command": "CI=true pnpm exec vitest run tests/e2e/fixtures/deviceAdd.test.ts (app)", "exit_code": 0 }, { "command": "pre-push gate: nix develop .#go-ci (gofmt/build/vet/go test ./.../golangci-lint, main + broker) and .#default pnpm run lint — passed on push", "exit_code": 0 } ], "criteria": { "On Ubuntu 26.04 (sudo-rs) and 24.04 (sudo use_pty), the one-liner the CodeScreen prints reaches Type WIPE to consent, accepts WIPE, and prints the connection-request confirmation": "The CodeScreen prints installCommand() = `sudo sh -c \"$(curl -sSf https://<apex>/get)\" sh <CODE>` (dashboard/src/lib/deviceAdd.ts) — curl evaluated BEFORE sudo, so sudo's fd0/pty is the operator's terminal and the served script's stdin IS that terminal; consentInput returns the terminal stdin unchanged (agent/cmd/agent/consent_input.go, TestConsentInput_TerminalStdinIsReadNotDetoured). Live sudo-rs pty leg noted unproven_by_seam.", "Running the OLD curl … | sudo sh -s -- form prints one honest line naming the new form and exits non-zero within seconds — never a stopped process": "consent_input.go ignores SIGTTIN (signal.Ignore) so the dead-pty read returns EIO rather than parking in state T, and guardedTTY translates that EIO into a loud error naming `sudo sh -c \"$(curl …)\" sh <CODE>` (TestGuardedTTY_BackgroundReadFailsLoudNamingTheForm); join/cli.go chooseMode now surfaces that read error instead of flattening to \"terminal closed\" (TestTerminal_ConsentReadErrorSurfaces). The app fixture rejects the old pipe form (app/tests/e2e/fixtures/deviceAdd.test.ts).", "go test ./internal/controlapi/... ./agent/... ./internal/join/... green; the dashboard deviceAdd unit test asserts the new command shape": "go test of the three suites exit 0; dashboard/tests/unit/deviceAdd.test.ts asserts `sudo sh -c \"$(curl -sSf https://admin.example.nz/get)\" sh <code>` and that the command never contains `| sudo sh`.", "GOTCHAS #388 stays accurate; update it in the same commit if the chosen form differs": "Chosen form matches #388's recommendation exactly; docs/GOTCHAS.md #388 gets a Fixed (#2038) note and the Rule's signal detail corrected to signal.Ignore (POSIX: EIO only when SIGTTIN is ignored)." }, "cross_repo_waiver": "No changed file is a cross-repo-mirrors.tsv trigger (the app-door and spaces-door goldens are untouched).", "summary": "The published device-add one-liner now uses the sudo-pty-safe `sudo sh -c \"$(curl …)\" sh <CODE>` shape across every printing surface, and the agent fails loud (never SIGTTIN-parked) on the old pipe form.", "blockers": [], "no_code_change": "" } ``` </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#2038
No description provided.