mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-01 00:49:33 +01:00
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:
1 parent
6db166f3f8
commit
d9fce03444
15 files changed
+785
-10
No files matched your search
@@ -71,6 +71,20 @@ function renderToken(value: string, style: QuoteStyle | undefined): string {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The value an enum param resolves to: the caller's when it is a declared one, else the
|
||||
* default. Exported so `applyRootValues()` (root-launch.ts) judges the same value the
|
||||
* renderer is about to emit, rather than restating this rule.
|
||||
*/
|
||||
export function resolveEnumValue(
|
||||
spec: Extract<ParamSpec, { type: 'enum' }>,
|
||||
raw: string | boolean | undefined
|
||||
): string | undefined {
|
||||
if (raw === undefined) return spec.default;
|
||||
const s = String(raw);
|
||||
return spec.values.includes(s) ? s : spec.default;
|
||||
}
|
||||
|
||||
/** Resolve one parameter to a plain string, or undefined if it is unset / invalid. */
|
||||
function resolveParam(
|
||||
name: string,
|
||||
@@ -82,13 +96,10 @@ function resolveParam(
|
||||
if (spec.type === 'engine') return engineValues[spec.source];
|
||||
|
||||
const raw = params[name];
|
||||
if (raw === undefined) return spec.type === 'enum' ? spec.default : undefined;
|
||||
if (spec.type === 'enum') return resolveEnumValue(spec, raw);
|
||||
if (raw === undefined) return undefined;
|
||||
|
||||
if (spec.type === 'bool') return typeof raw === 'boolean' ? String(raw) : undefined;
|
||||
if (spec.type === 'enum') {
|
||||
const s = String(raw);
|
||||
return spec.values.includes(s) ? s : spec.default;
|
||||
}
|
||||
// token
|
||||
const s = String(raw);
|
||||
return matchesPattern(spec.pattern, s) ? s : undefined;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @fileoverview The launch params a CLI takes a different value for when it is started as
|
||||
* root. Pure: the caller says whether the launch runs as root, this module never asks.
|
||||
*
|
||||
* Claude Code refuses `--dangerously-skip-permissions` under uid 0 and exits, so a Codeman
|
||||
* server that runs as root (a VPS, an LXC container) showed a dead pane for every local
|
||||
* Claude session, the default permission mode being exactly that flag. Docker cases already
|
||||
* answer the same refusal for a root container with `overlays.docker.rootCommand`; this is
|
||||
* the host-level form, for a CLI the server process starts as its own child.
|
||||
*
|
||||
* Which value gives way to which is registry DATA (`ParamSpec.rootValue` on an enum param),
|
||||
* so no code here or at the call sites names a CLI. `applyRootValues()` runs BEFORE the argv
|
||||
* engine and only rewrites the param values handed to it: the engine, and with it every
|
||||
* command line of a launch that is not root, is untouched.
|
||||
*
|
||||
* ⚠️ Local launches only. A remote or Docker launch runs under another account, which the
|
||||
* server's uid says nothing about; those keep their own handling (`buildRemoteLaunchCommand`,
|
||||
* `rootCommand`). The callers decide that, by passing `runsAsRoot` false.
|
||||
*
|
||||
* @module config/cli-registry/root-launch
|
||||
*/
|
||||
|
||||
import { resolveEnumValue, type ParamValues } from './argv.js';
|
||||
import type { CliLaunch } from './types.js';
|
||||
|
||||
/** One param that was launched with its `rootValue` instead of the value it resolved to. */
|
||||
export interface RootValueChange {
|
||||
param: string;
|
||||
from: string;
|
||||
to: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply every declared `rootValue` to `params`.
|
||||
*
|
||||
* Returns the SAME `params` object when nothing changes (not root, or no param whose
|
||||
* resolved value has a replacement), so a caller can rely on a launch that is not root
|
||||
* rendering from exactly the values it passed in. Otherwise a copy, with `changes` naming
|
||||
* what was swapped so the caller can log it.
|
||||
*
|
||||
* The value judged is the one the renderer would emit: an absent or undeclared value counts
|
||||
* as the param's default, which is how the default permission mode is caught although no
|
||||
* caller ever sends it.
|
||||
*/
|
||||
export function applyRootValues(
|
||||
launch: CliLaunch,
|
||||
params: ParamValues,
|
||||
runsAsRoot: boolean
|
||||
): { params: ParamValues; changes: RootValueChange[] } {
|
||||
const changes: RootValueChange[] = [];
|
||||
if (!runsAsRoot) return { params, changes };
|
||||
let out = params;
|
||||
for (const [name, spec] of Object.entries(launch.params)) {
|
||||
if (spec.type !== 'enum' || !spec.rootValue) continue;
|
||||
const from = resolveEnumValue(spec, params[name]);
|
||||
if (from === undefined || !Object.hasOwn(spec.rootValue, from)) continue;
|
||||
const to = spec.rootValue[from];
|
||||
// Schema-validated at load; belt and braces, since a value outside `values` would
|
||||
// resolve back to the default, which is the very value being replaced.
|
||||
if (to === from || !spec.values.includes(to)) continue;
|
||||
if (out === params) out = { ...params };
|
||||
out[name] = to;
|
||||
changes.push({ param: name, from, to });
|
||||
}
|
||||
return { params: out, changes };
|
||||
}
|
||||
|
||||
/**
|
||||
* The one log line for a launch that took a `rootValue`. `what` names the launch ("Claude
|
||||
* Code session 0f9c2b14"); the wording stays free of any CLI's vocabulary because the
|
||||
* params and values in it are the registry's own.
|
||||
*/
|
||||
export function describeRootValueChanges(what: string, changes: readonly RootValueChange[]): string {
|
||||
const swapped = changes.map((c) => `${c.param} "${c.from}" as "${c.to}"`).join(', ');
|
||||
return (
|
||||
`${what} is launched with ${swapped}: the Codeman server runs as root (uid 0), and the CLI refuses ` +
|
||||
`the configured value under root. Run Codeman as a normal user to get the configured value back.`
|
||||
);
|
||||
}
|
||||
@@ -67,7 +67,13 @@ const condSchema: z.ZodType<import('./types.js').Cond> = z.lazy(() =>
|
||||
|
||||
const paramSpecSchema = z.union([
|
||||
z
|
||||
.object({ type: z.literal('enum'), values: z.array(z.string()).min(1).max(16), default: z.string().optional() })
|
||||
.object({
|
||||
type: z.literal('enum'),
|
||||
values: z.array(z.string()).min(1).max(16),
|
||||
default: z.string().optional(),
|
||||
// Cross-checked against `values` in launchSchema's superRefine below.
|
||||
rootValue: z.record(z.string(), z.string()).optional(),
|
||||
})
|
||||
.strict(),
|
||||
z.object({ type: z.literal('bool') }).strict(),
|
||||
z.object({ type: z.literal('token'), pattern: z.enum(TOKEN_PATTERNS as [string, ...string[]]) }).strict(),
|
||||
@@ -145,6 +151,29 @@ const launchSchema = z
|
||||
});
|
||||
}
|
||||
}
|
||||
// `rootValue` swaps one declared value for another when the server runs as root. A key or
|
||||
// a replacement outside `values` could never apply (or would launch with a value no arg
|
||||
// tests for), and a replacement that is itself replaced would make the outcome depend on
|
||||
// how many passes the reader makes.
|
||||
for (const [paramName, spec] of Object.entries(launch.params)) {
|
||||
if (spec.type !== 'enum' || !spec.rootValue) continue;
|
||||
for (const [from, to] of Object.entries(spec.rootValue)) {
|
||||
const path = ['params', paramName, 'rootValue', from];
|
||||
if (!spec.values.includes(from)) {
|
||||
ctx.addIssue({ code: 'custom', message: `rootValue key "${from}" is not one of this param's values`, path });
|
||||
}
|
||||
if (!spec.values.includes(to)) {
|
||||
ctx.addIssue({ code: 'custom', message: `rootValue "${to}" is not one of this param's values`, path });
|
||||
}
|
||||
if (to === from || Object.hasOwn(spec.rootValue, to)) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: `rootValue "${to}" must be a value that is launched as it is under root`,
|
||||
path,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (launch.legacyConfigAliases) {
|
||||
for (const paramName of Object.keys(launch.legacyConfigAliases)) {
|
||||
if (!paramNames.has(paramName)) {
|
||||
|
||||
@@ -142,6 +142,13 @@ const CLAUDE: CliEntry = {
|
||||
type: 'enum',
|
||||
values: ['dangerously-skip-permissions', 'auto', 'normal', 'allowedTools'],
|
||||
default: 'dangerously-skip-permissions',
|
||||
// ⚠️ Claude Code REFUSES the bypass flag under uid 0 ("cannot be used with root/sudo
|
||||
// privileges for security reasons") and exits, so under a server that runs as root (a
|
||||
// VPS, an LXC container) every local session was a dead pane, this being the default.
|
||||
// There it starts as `normal` and asks. The same refusal `overlays.docker.rootCommand`
|
||||
// below answers for a root container; the other three modes do not carry the flag
|
||||
// and stay as they are. Never force the bypass back on with `IS_SANDBOX`.
|
||||
rootValue: { 'dangerously-skip-permissions': 'normal' },
|
||||
},
|
||||
allowedTools: { type: 'token', pattern: 'tool-list' },
|
||||
model: { type: 'token', pattern: 'model-claude' },
|
||||
|
||||
@@ -45,7 +45,25 @@ export type EngineValue =
|
||||
* the only ones that need a pattern; `engine` params are produced in code.
|
||||
*/
|
||||
export type ParamSpec =
|
||||
| { type: 'enum'; values: string[]; default?: string }
|
||||
| {
|
||||
type: 'enum';
|
||||
values: string[];
|
||||
default?: string;
|
||||
/**
|
||||
* The value this param takes INSTEAD when the Codeman server process runs as uid 0 and
|
||||
* the launch is LOCAL (the CLI is then a child of that process, so it runs as root too).
|
||||
* Keyed by the value the param would otherwise resolve to, the default included; a
|
||||
* value with no key is launched as it is.
|
||||
*
|
||||
* For a value the CLI REFUSES under root, where the alternative is a pane that dies at
|
||||
* once. It is the host-level form of `overlays.docker.rootCommand`, which answers the
|
||||
* same refusal for a container whose exec user is uid 0. Remote and Docker launches
|
||||
* never read it: the server's uid says nothing about the account on the other side.
|
||||
* Applied by `applyRootValues()` (root-launch.ts); the schema requires every key and
|
||||
* every replacement to be one of `values`, and no replacement to be replaced again.
|
||||
*/
|
||||
rootValue?: Record<string, string>;
|
||||
}
|
||||
| { type: 'bool' }
|
||||
| { type: 'token'; pattern: TokenPattern }
|
||||
| { type: 'engine'; source: EngineValue };
|
||||
|
||||
Reference in new issue
Block a user