Skip to content

fix: a server running as root starts Claude, and a headless install gets past sudo - #863

Merged
Ark0N merged 2 commits into
masterfrom
fix/first-run-as-root
Dec 3, 2026
Merged

Ark0N merged 2 commits into
masterfrom
fix/first-run-as-root

Conversation

@Ark0N

@Ark0N Ark0N commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Two first-run failures of the public installer, found with a clean-machine check (curl -fsSL https://getcodeman.com/install | bash in fresh ubuntu:24.04 containers, 1.51.1). As a normal user at a terminal everything passed. Two other common setups did not.

1. A server running as root: every Claude session died at once

Installed and started as root, which is the normal account on many VPSes and in Proxmox LXC containers, the install succeeds and shell sessions work, but every local Claude session is a dead pane:

--dangerously-skip-permissions cannot be used with root/sudo privileges for security reasons
Pane is dead (status 1, ...)

The default permission mode launches Claude Code with --dangerously-skip-permissions, and Claude Code refuses that flag under uid 0. Docker cases already handle the same refusal for a root container with overlays.docker.rootCommand. This adds the host-level form, as registry data:

  • An enum launch param may declare rootValue: a map from a value to the value it takes when the server process runs as uid 0 and the launch is local. Claude declares claudeMode: { 'dangerously-skip-permissions': 'normal' }. The schema requires the keys and replacements to be among the param's values. No code outside stock.ts names a CLI.
  • applyRootValues() (src/config/cli-registry/root-launch.ts, pure) rewrites the param values before the argv engine sees them. When nothing changes it returns the object it was given, so a launch that is not root is byte-identical; the spawn goldens are untouched.
  • serverRunsAsRoot() (src/utils/server-uid.ts) reads the uid at call time. Under vitest it answers false unless a test stubs it, so the suite gives the same command lines when run as root.
  • The uid is asked in two places. serverRootSpawnOptions() feeds the two tmux launches (createSession, respawnPane), which cover new session, resume, dead-pane respawn, restartCli(), cron, quick-start and reboot restore. buildPermissionArgs() covers the two launches without tmux: the direct-PTY fallback and the one-shot run.
  • Remote and Docker launches never read it (those run under another account), and auto, allowedTools and normal pass through unchanged. IS_SANDBOX is not set: the bypass is not forced back on.
  • Each swap writes one server log line naming the cause and the way out (run Codeman as a normal user).

So under root, Claude starts in normal mode and asks before it acts. docs/wiki/Troubleshooting.md gets a section for that, and docs/cli-registry.md documents rootValue.

2. The installer stopped in headless runs with a passwordless sudo

A non-root account with 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 but cannot be opened; install.sh tested [[ -e /dev/tty ]] and then ran sudo -v < /dev/tty, whose redirect fails before sudo starts.

  • 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 in sudo_session_start, and the three sites of 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: it asks for a password as soon as one sudoers entry of the account does, 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 on a file test of /dev/tty and on 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. Bash 3.2 clean.

How it was checked

  • End to end, in throwaway ubuntu:24.04 containers, installing this branch with its own install.sh:
    • as root: install OK, the server answers in 3 s, the first Claude session is alive on its first-run screen, its pane command has no bypass flag, and the log line is there;
    • as a non-root user with passwordless sudo and no terminal (su - user -c, CODEMAN_NONINTERACTIVE=1): install exits 0 and the server answers. The same run on 1.51.1 stops at the sudo step;
    • as a normal user, the flag is kept.
  • Not run end to end: the dead-pane respawn, direct-PTY and one-shot paths under root (unit tests only), and the Homebrew branch (no macOS here).
  • Static checks and tests, rebased onto 1.52.0: typecheck, lint, format, generate:cli-catalog --check, check:frontend-syntax and bash -n install.sh pass. Full npm test: 774 files passed, 1 skipped; 17,851 tests passed, 13 skipped.

Two changesets (patch). Also one sentence in CLAUDE.md's CLI registry paragraph pointing at rootValue.

Not fixed here: on an image without the en_US.UTF-8 locale every pane starts with setlocale: LC_ALL: cannot change locale (en_US.UTF-8). Cosmetic, separate change.

…s flag

Installed and started as root (a VPS, an LXC container), every local Claude
session died at once: the default permission mode launches Claude Code with
--dangerously-skip-permissions, and Claude Code refuses that flag under uid 0
("cannot be used with root/sudo privileges for security reasons", pane dead
with status 1). Shell sessions were fine. Measured 2026-11-27 with the public
installer in a fresh ubuntu:24.04 container.

Docker cases already answer the same refusal for a root container with
overlays.docker.rootCommand. This is the host-level form, as registry data:

- An enum launch param may declare rootValue, a map from a value to the value
  it takes when the server process runs as uid 0 and the launch is local.
  Claude declares claudeMode: dangerously-skip-permissions -> normal. The
  schema holds keys and replacements to the param's values.
- applyRootValues() (config/cli-registry/root-launch.ts, pure) rewrites the
  param values before the argv engine sees them and hands back the object it
  was given when nothing changes, so a launch that is not root is
  byte-identical (the spawn goldens are untouched).
- serverRunsAsRoot() (utils/server-uid.ts) reads the uid at call time. Under
  vitest it answers false unless a test stubs it.
- The uid is asked in two places only. serverRootSpawnOptions() feeds the two
  tmux launches (createSession, respawnPane), which every local tmux launch
  goes through: new session, resume, dead-pane respawn, restartCli(), cron,
  quick-start, reboot restore. buildPermissionArgs() covers the two launches
  with no tmux, the direct-PTY fallback and the one-shot run.
- Remote and Docker pane commands never read it, and auto, allowedTools and
  normal are passed through unchanged. IS_SANDBOX is not set.
- Each swap is logged once per launch, naming the cause and the way out.

Checked end to end in a throwaway ubuntu:24.04 container running this tree's
server as root with Claude Code 2.1.332: the pane command carries no bypass
flag, the pane stays alive on Claude's first-run screen, and the log line is
there. The same run as an ordinary user keeps the flag.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…udo 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>
@Ark0N
Ark0N merged commit 95ad7f2 into master Dec 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants