fix(launch): a server running as root starts Claude without the bypass 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>
This commit is contained in:
Codeman maintainer committed 2026-11-27 17:54:43 +01:00
1 parent 6db166f3f8
commit d9fce03444
15 files changed
+785 -10

No files matched your search

+52
View File
@@ -81,6 +81,8 @@ import {
} from './session-cli-registry-bridge.js';
import { keepWarmOn } from './prompt-cache-keepwarm.js';
import type { CliEntry } from './config/cli-registry/types.js';
import { describeRootValueChanges, type RootValueChange } from './config/cli-registry/root-launch.js';
import { serverRunsAsRoot } from './utils/server-uid.js';
import {
resolveStatusLineCliCommand,
readPlanUsageTelemetryEnabled,
@@ -1258,6 +1260,44 @@ export function decideIdleCompactionOptOut(o: {
);
}
/** What `serverRootSpawnOptions()` adds to a `buildSpawnCommand` call; empty for every launch that is not root. */
export interface ServerRootSpawnOptions {
runsAsServerRoot?: true;
onRootValue?: (changes: RootValueChange[]) => void;
}
/**
* The `buildSpawnCommand` options for a launch under a Codeman server that itself runs as
* root (uid 0), which is common on a VPS and in an LXC container.
*
* A CLI started locally is the server's child and runs as root too, and Claude Code exits
* on `--dangerously-skip-permissions` there, so its default launch was a dead pane. With
* these options a param that declares a `rootValue` takes it (registry data, see
* config/cli-registry/root-launch.ts), and the swap is logged once per launch.
*
* ⚠️ The ONE place the tmux launch path asks for the uid. `createSession` and `respawnPane`
* both spread the result into `buildSpawnCommand`, and every local tmux launch (new
* session, resume, dead-pane respawn, `restartCli()`, cron, quick-start, reboot restore) is
* one of those two calls. The two launches with no tmux (direct-PTY fallback, one-shot) get
* the same registry data in `buildPermissionArgs()` (session-cli-builder.ts).
* ⚠️ `launchedElsewhere` (remote, Docker, adopted) returns nothing: that CLI runs under
* another account, and the local command built for it is never used. Docker answers the
* same refusal with `overlays.docker.rootCommand`, by the CONTAINER's uid.
* ⚠️ Not root returns `{}`, so the command line stays byte-identical.
*/
export function serverRootSpawnOptions(o: {
mode: SessionMode;
sessionId: string;
launchedElsewhere: boolean;
}): ServerRootSpawnOptions {
if (o.launchedElsewhere || !serverRunsAsRoot()) return {};
const what = `${getCli(o.mode)?.label ?? o.mode} session ${o.sessionId.slice(0, 8)}`;
return {
runsAsServerRoot: true,
onRootValue: (changes) => console.warn(`[TmuxManager] ${describeRootValueChanges(what, changes)}`),
};
}
export function buildSpawnCommand(options: {
mode: SessionMode;
sessionId: string;
@@ -1292,6 +1332,14 @@ export function buildSpawnCommand(options: {
* gate measuring the RIGHT binary, the local one.
*/
claudeCliVersion?: string | null;
/**
* The command will run as a child of a server process whose uid is 0, so a param declaring
* a `rootValue` takes it. Only ever supplied through `serverRootSpawnOptions()`, which the
* two local launch sites spread in; absent, the command is byte-identical.
*/
runsAsServerRoot?: boolean;
/** Told which params took their `rootValue` (see `serverRootSpawnOptions`). */
onRootValue?: (changes: RootValueChange[]) => void;
}): string {
// Every CLI's command shape is registry DATA, rendered by the argv engine — see
// config/cli-registry/argv.ts for why config can never contain shell text. A `shell`-kind
@@ -2731,6 +2779,8 @@ export class TmuxManager extends EventEmitter implements TerminalMultiplexer {
statusLineCommand,
idleCompactionOff,
sessionName: cliName,
// A local launch under a server that runs as root: see serverRootSpawnOptions.
...serverRootSpawnOptions({ mode, sessionId, launchedElsewhere: !!(remote || docker || adopt) }),
});
const config = niceConfig || DEFAULT_NICE_CONFIG;
@@ -3055,6 +3105,8 @@ export class TmuxManager extends EventEmitter implements TerminalMultiplexer {
statusLineCommand,
idleCompactionOff,
sessionName: cliName,
// Same as createSession: a respawn under a root server must not bring the refused value back.
...serverRootSpawnOptions({ mode, sessionId, launchedElsewhere: !!(remote || docker || adopt) }),
});
const config = niceConfig || DEFAULT_NICE_CONFIG;
const cmd = wrapWithNice(baseCmd, config);