Coach: chown of the job directory locked the parent out of it
Every Coach run failed instantly on Kubernetes -- "Claude Code native binary ... exists but failed to launch. This usually means the binary does not match this system's libc" -- with a musl binary on a musl host, which the SDK's own --version printed happily one shell command earlier. The message is the Agent SDK's guess at any spawn failure. The real errno was EACCES, and the cause is the job directory rather than the binary: libuv chdir()s into cwd BEFORE dropping to the child's uid, so handing the directory to `coach` locks out the very process that has to enter it first. mkdtemp creates 0700, and `drop: [ALL]` leaves root without CAP_DAC_OVERRIDE to ignore that with -- so the child never starts. cf7e4cc fixed the same class of bug for the fixture provider by skipping the chown when the child stays root. It does not help here: claude and codex do drop, and the chdir still happens before they do. The directory now stays owned by the server and `coach\' reaches it through the group (0770, coach gid). The child writes, the parent still chdirs and still cleans up, nothing else on the container can read it. chmod before chown, while the server is still the owner: CAP_FOWNER is not in the set either, so the other order fails with EPERM. Verified in the running container: chown -> EACCES, group handover -> exit 0, child writes, parent removes.
This commit is contained in:
1 parent
acff80348f
commit
e8095b01c4
1 file changed
+21
-2
+21
-2
@@ -294,7 +294,7 @@ async function execute(job) {
|
||||
const env = cfgStore.jobEnv(jobDir || os.tmpdir(), cfgStore.credentialFor(job.uid));
|
||||
try {
|
||||
const ids = jobDir && unprivilegedIds();
|
||||
if (ids) fs.chownSync(jobDir, ids.uid, ids.gid);
|
||||
if (ids) shareJobDir(jobDir, ids);
|
||||
|
||||
const attempt = await runPipeline({
|
||||
adapter, cfg, kind: job.kind, payload, model: cfgStore.modelFor(cfg), timeoutMs: TIMEOUT_MS,
|
||||
@@ -342,6 +342,25 @@ export function resolvePending(uid, { accepted = [], rejected = [], dismissed =
|
||||
/* ---------- admin test + boot recovery ---------- */
|
||||
|
||||
/** A2's "Test the Coach": the real adapter, a trivial round-trip, no user data anywhere near it. */
|
||||
/* Give the unprivileged `coach` user its job directory without locking this process out of it.
|
||||
*
|
||||
* The obvious move is chown(jobDir, coach) — and it breaks the spawn outright. libuv chdir()s
|
||||
* into cwd BEFORE it drops to the child's uid, so the parent still has to be able to enter the
|
||||
* directory it just gave away; mkdtemp creates 0700, and a container started with `drop: [ALL]`
|
||||
* has no CAP_DAC_OVERRIDE for root to ignore that with. The child never starts and node reports
|
||||
* EACCES, which the Agent SDK renders as "the native binary failed to launch … does not match
|
||||
* this system's libc" — a guess, and a misleading one.
|
||||
*
|
||||
* So the directory stays owned by this process and `coach` reaches it through the group: 0770
|
||||
* with the coach gid. The child can write, the parent can still chdir and still clean up
|
||||
* afterwards, and nobody else on the container can read it. chmod before chown, while this
|
||||
* process is still the owner — CAP_FOWNER is not in the capability set either.
|
||||
*/
|
||||
function shareJobDir(jobDir, ids) {
|
||||
fs.chmodSync(jobDir, 0o770);
|
||||
fs.chownSync(jobDir, process.getuid ? process.getuid() : 0, ids.gid);
|
||||
}
|
||||
|
||||
export async function testRun() {
|
||||
const cfg = cfgStore.load();
|
||||
const adapter = adapterFor(cfg.provider);
|
||||
@@ -354,7 +373,7 @@ export async function testRun() {
|
||||
// a credential that belongs to a profile.
|
||||
const env = cfgStore.jobEnv(jobDir || os.tmpdir(), cfgStore.credentialFor(cfgStore.boundUidFor(cfg)));
|
||||
const ids = jobDir && unprivilegedIds();
|
||||
if (ids) fs.chownSync(jobDir, ids.uid, ids.gid);
|
||||
if (ids) shareJobDir(jobDir, ids);
|
||||
const check = await adapter.check(cfg, env);
|
||||
if (!check.ok) return { ok: false, error: check.error || 'the provider runtime could not be run' };
|
||||
const r = await adapter.invoke({
|
||||
|
||||
Reference in new issue
Block a user