fix(install): a headless run with a passwordless sudo gets past the sudo step

A non-root account with a working passwordless sudo and no controlling
terminal (su - user -c, cron, a CI runner, cloud-init) ended on "Failed to
obtain sudo privileges". The /dev/tty node exists there and cannot be opened;
install.sh tested [[ -e /dev/tty ]] and then ran sudo -v < /dev/tty, whose
redirect fails before sudo starts. Measured 2026-11-27 in a fresh ubuntu:24.04
container: node present, open refused, sudo -n true fine, install dead at
"Installing Git via apt".

- tty_openable() opens the node, the probe has_tty() already used, and every
  redirect from /dev/tty now sits behind it instead of a file test:
  ensure_sudo, sudo_session_try, the message choice in sudo_session_start,
  and the three sites with the same shape (Homebrew, the Tailscale installer,
  tailscale up). With no terminal they fall back to the plain command.
- ensure_sudo returns as soon as sudo -n true works. sudo -v is no substitute
  for that test: it asks for a password as soon as one sudoers entry of the
  account asks for one, so an account in the sudo group with a NOPASSWD entry
  of its own (the cloud-image layout) runs sudo <command> freely and is
  refused by sudo -v (measured on sudo 1.9.15).

test/install-sh-invariants.test.ts fails for a file test on /dev/tty and for
a redirect from it that is not directly under the probe, and drives the sudo
helpers in a real bash with no controlling terminal against a stub sudo.

Checked in a throwaway ubuntu:24.04 container, through su - user -c with
CODEMAN_NONINTERACTIVE=1: the installer before this change stops at the sudo
step, this one installs git, tmux, Node.js and the build tools, clones and
was building when the check was stopped. The helpers were also run under
bash 3.2.57. The Homebrew branch could not be run here (no macOS).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-11-27 17:54:43 +01:00
1 parent d9fce03444
commit c51a7134eb
4 files changed
+199 -11

No files matched your search

+3 -1
View File
@@ -110,7 +110,9 @@ approve those steps. With nothing else said, that also installs the first agent
catalogue when none is found; `--ai-cli` (or `CODEMAN_AI_CLI`) says which one, or none.
`CODEMAN_TAILSCALE=1` preselects the Tailscale answer, and never
installs Tailscale itself non-interactively; a non-interactive run never renames the
machine and never starts a service. Everything the unattended steps print goes to
machine and never starts a service. With no terminal there is nowhere to type a password,
so a step that needs `sudo` works only where `sudo` asks for none (a `NOPASSWD` entry, as
cloud images and CI runners have). Everything the unattended steps print goes to
`~/.codeman/install.log`, and the last lines of it are shown when a step fails.
### Without administrator rights