/** * Zero-dependency privilege drop for secure exec. * * Node's `spawn({uid,gid})` sets the primary uid/gid but does NOT clear root's * SUPPLEMENTARY groups, so the child would keep gid 0 et al. The classic fix is * the external `setpriv` (util-linux) binary — but that is NOT guaranteed to * exist on minimal hosts (alpine/musl, distroless, slim images), and secure exec * must work after a plain curl/npm install with NOTHING else to install. * * So we drop privilege IN-PROCESS using the agent's own bundled Node runtime: * the agent re-execs ITSELF (`process.execPath`) with the SENTINEL sub-command; * that child, still root, calls initgroups → setgid → setuid (exactly what * `setpriv --init-groups` does: supplementary groups reset to the target user's * own from /etc/group, root's groups dropped) and only THEN execs the target. * Works identically for the npm install (`node agent.js …`) and the single * self-contained binary (`agent …`) because execPath always points at a working * runtime — no external program, no PATH dependency. */ export declare const SECURE_EXEC_DROP_SENTINEL = "__secure-exec-drop"; /** * Build the argv to re-exec THIS runtime with the drop sub-command. Handles both * launch shapes: * - single self-contained binary (SEA): `binary __secure-exec-drop …` — argv[1] * is a normal arg, no script to re-pass. * - `node /path/agent.js …`: argv[1] is the script we MUST re-pass so the child * Node loads it again. We re-pass argv[1] unconditionally regardless of its * extension (extensionless global/npm bin shims have no `.js` suffix). */ export declare function buildDropReexec(extra: string[]): { cmd: string; args: string[]; }; /** * If `argv` carries the drop sentinel IN THE EXPECTED POSITION, perform the * privilege drop + exec the target and return true (the caller MUST then do * nothing else — this process is now the sandboxed command and will process.exit * with the child's code). Returns false for a normal agent launch. * * The sentinel is honoured ONLY as the FIRST real argument of our own re-exec — * never anywhere else in argv — so a stray token in a normal CLI invocation * (e.g. `status __secure-exec-drop …`) can NOT dispatch the drop parser: * - single self-contained binary: `binary __secure-exec-drop …` → argv[1] * - node+script: `node agent.js __secure-exec-drop …` → argv[2] * * Sentinel payload (immediately after the matched sentinel): uid gid username bin * [args…]. Runs as root on entry; fails closed (exit 127) on any privilege-drop * error so a misconfigured host can never silently run the command AS ROOT. */ export declare function maybeRunSecureExecDrop(argv: string[]): boolean;