Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(hcc): close Host execution container log descriptors
Alfredo Lopez7868fcc334c3
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex 449526342..363072972 100644--- a/host-context-controller/package-lock.json+++ b/host-context-controller/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-host-context-controller",- "version": "0.1.378",+ "version": "0.1.379","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.378",+ "version": "0.1.379","license": "SEE LICENSE IN LICENSE","dependencies": {"@clerum/codex-catalog-projection": "file:../packages/codex-catalog-projection",diff --git a/host-context-controller/package.json b/host-context-controller/package.jsonindex 020d17edc..61dc8a6c6 100644--- a/host-context-controller/package.json+++ b/host-context-controller/package.json@@ -1,6 +1,6 @@{"name": "clerum-host-context-controller",- "version": "0.1.378",+ "version": "0.1.379","description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API","main": "dist/main.js","engines": {diff --git a/host-context-controller/src/hostExecution/jobFactory.launcher.test.ts b/host-context-controller/src/hostExecution/jobFactory.launcher.test.tsnew file mode 100644index 000000000..f33d0c6f8--- /dev/null+++ b/host-context-controller/src/hostExecution/jobFactory.launcher.test.ts@@ -0,0 +1,117 @@+import { describe, expect, it } from 'vitest'+import type * as k8s from '@kubernetes/client-node'+import { spawnSync } from 'node:child_process'+import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { dirname, join } from 'node:path'+import {+ ApprovedExecutionRequest,+ EXECUTION_RUN_ENTRYPOINT,+ TrustedHostExecutionIdentity,+ buildHostExecutionJob,+} from './jobFactory'++const identity: TrustedHostExecutionIdentity = {+ hostName: 'chatllm',+ hostUid: '9f0e3a5c-5f1e-4a4e-9a2d-3f4c5b6a7d8e',+ namespace: 'mcp-host',+ operationId: '7b1f0d2c-3a4b-4c5d-8e9f-0a1b2c3d4e5f',+ hostGeneration: 7,+ image: 'registry.example.com/evenfire/mcp-host@sha256:0123456789abcdef',+ workspacePvcName: 'chatllm-workspace',+ userKey: '0123456789abcdef',+ workspaceLayoutPrefix: 'workspace/',+}++const baseRequest: ApprovedExecutionRequest = {+ kind: 'workspace',+ argv: [],+ timeoutMs: 60_000,+ scratchBytes: 33_554_432,+}++function podSpec(job: k8s.V1Job): k8s.V1PodSpec {+ return job.spec!.template.spec!+}++/**+ * Local launch-contract falsifier, not a Linux /proc or Kubernetes check. The+ * assembled Job command is executed with only its fixed image entrypoint+ * replaced by a synthetic Node fixture, so the wrapper's real descriptors,+ * output sinks and argument passing are observed from a child process.+ */+describe('executor launcher contract', () => {+ it('keeps wrapper stdio private and passes the approved vector literally', () => {+ const dir = mkdtempSync(join(tmpdir(), 'host-execution-launcher-'))+ try {+ const reportPath = join(dir, 'report.json')+ const fixturePath = join(dir, 'fixture.cjs')+ const sideEffect = (name: string) => join(dir, `pwned-${name}`)+ const argv = [+ 'plain',+ 'a b',+ '"double quoted"',+ "'single quoted'",+ `$(touch ${sideEffect('dollar')})`,+ '`touch ' + sideEffect('backtick') + '`',+ `; touch ${sideEffect('semicolon')}`,+ `&& touch ${sideEffect('and')}`,+ `| touch ${sideEffect('pipe')}`,+ '$HOME',+ '*',+ ]+ const fixture = [+ "const fs = require('node:fs')",+ 'const describeFd = fd => {',+ ' const stat = fs.fstatSync(fd)',+ ' return { isCharacterDevice: stat.isCharacterDevice(), rdev: stat.rdev }',+ '}',+ 'fs.writeFileSync(process.env.LAUNCHER_FIXTURE_REPORT, JSON.stringify({',+ ' argv: process.argv.slice(2),',+ ' fd1: describeFd(1),',+ ' fd2: describeFd(2),',+ " devNullRdev: fs.statSync('/dev/null').rdev,",+ '}))',+ "process.stdout.write('LAUNCHER_FIXTURE_STDOUT_SENTINEL')",+ "process.stderr.write('LAUNCHER_FIXTURE_STDERR_SENTINEL')",+ ].join('\n')+ writeFileSync(fixturePath, fixture)++ const job = buildHostExecutionJob(identity, { ...baseRequest, argv })+ const command = [...podSpec(job).containers![0].command!]+ const entrypointIndex = command.indexOf(EXECUTION_RUN_ENTRYPOINT)+ expect(entrypointIndex).toBeGreaterThanOrEqual(0)+ command[entrypointIndex] = fixturePath++ const result = spawnSync(command[0]!, command.slice(1), {+ encoding: 'utf8',+ timeout: 5_000,+ env: {+ ...process.env,+ PATH: `${dirname(process.execPath)}:${process.env.PATH ?? ''}`,+ LAUNCHER_FIXTURE_REPORT: reportPath,+ },+ })+ expect(result.error).toBeUndefined()+ expect(result.signal).toBeNull()+ expect(result.status).toBe(0)++ const report = JSON.parse(readFileSync(reportPath, 'utf8')) as {+ argv: string[]+ fd1: { isCharacterDevice: boolean; rdev: number }+ fd2: { isCharacterDevice: boolean; rdev: number }+ devNullRdev: number+ }+ expect(report.argv).toEqual([String(baseRequest.timeoutMs), ...argv])+ expect(report.fd1).toEqual({ isCharacterDevice: true, rdev: report.devNullRdev })+ expect(report.fd2).toEqual({ isCharacterDevice: true, rdev: report.devNullRdev })+ expect(result.stdout).not.toContain('LAUNCHER_FIXTURE_STDOUT_SENTINEL')+ expect(result.stderr).not.toContain('LAUNCHER_FIXTURE_STDERR_SENTINEL')+ for (const name of ['dollar', 'backtick', 'semicolon', 'and', 'pipe']) {+ expect(existsSync(sideEffect(name))).toBe(false)+ }+ } finally {+ rmSync(dir, { recursive: true, force: true })+ }+ })+})diff --git a/host-context-controller/src/hostExecution/jobFactory.test.ts b/host-context-controller/src/hostExecution/jobFactory.test.tsindex 0780c0fb3..ecb848fd2 100644--- a/host-context-controller/src/hostExecution/jobFactory.test.ts+++ b/host-context-controller/src/hostExecution/jobFactory.test.ts@@ -15,6 +15,7 @@ import {EXECUTION_ROLE_LABEL,EXECUTION_ROLE_VALUE,EXECUTION_RUN_ENTRYPOINT,+ EXECUTION_RUN_LAUNCHER_SCRIPT,EXECUTION_SCRATCH_MAX_BYTES,EXECUTION_SCRATCH_MOUNT_PATH,EXECUTION_TIMEOUT_MAX_MS,@@ -191,6 +192,9 @@ describe('bounded Host execution job factory', () => {const executor = podSpec(job).containers![0]expect(executor.command).toEqual([+ '/bin/sh',+ '-c',+ EXECUTION_RUN_LAUNCHER_SCRIPT,'node',EXECUTION_RUN_ENTRYPOINT,String(workspaceRequest.timeoutMs),@@ -378,19 +382,19 @@ describe('bounded Host execution job factory', () => {argv: ['/bin/sh', '-c', ''],}expect(- podSpec(buildHostExecutionJob(identity, emptyTail)).containers![0].command!.slice(3)+ podSpec(buildHostExecutionJob(identity, emptyTail)).containers![0].command!.slice(6)).toEqual(['/bin/sh', '-c', ''])expect(podSpec(buildHostExecutionJob(identity, { ...workspaceRequest, argv: ['node', '', ''] })- ).containers![0].command!.slice(3)+ ).containers![0].command!.slice(6)).toEqual(['node', '', ''])- // No wrapper shell is inserted and the caller's array is not aliased.+ // The fixed launcher keeps the caller's array literal and unaliased.const argv = ['/usr/bin/git', 'status']const job = buildHostExecutionJob(identity, { ...workspaceRequest, argv })argv.push('--porcelain')- expect(podSpec(job).containers![0].command!.slice(3)).toEqual(['/usr/bin/git', 'status'])+ expect(podSpec(job).containers![0].command!.slice(6)).toEqual(['/usr/bin/git', 'status'])expect(podSpec(job).containers![0].args).toBeUndefined()// Aggregate UTF-8 bound, measured in bytes rather than characters.@@ -398,7 +402,7 @@ describe('bounded Host execution job factory', () => {expect(podSpec(buildHostExecutionJob(identity, { ...workspaceRequest, argv: [halfBound] })- ).containers![0].command!.slice(3)+ ).containers![0].command!.slice(6)).toEqual([halfBound])for (const bad of [[''],diff --git a/host-context-controller/src/hostExecution/jobFactory.ts b/host-context-controller/src/hostExecution/jobFactory.tsindex 5e01d6312..0ea529565 100644--- a/host-context-controller/src/hostExecution/jobFactory.ts+++ b/host-context-controller/src/hostExecution/jobFactory.ts@@ -32,6 +32,13 @@ export const EXECUTION_RECEIVE_INPUT_ENTRYPOINT =export const EXECUTION_INPUT_PORT = 9301/** PID 1 retains captured results privately and serves only the scoped portal. */export const EXECUTION_RUN_ENTRYPOINT = '/app/mcp-host/dist/core/execution/runSession.js'+/**+ * Fixed launcher for the executor. The approved vector is passed only as+ * positional parameters, and the wrapper's stdout/stderr become /dev/null+ * before Node replaces the shell, so PID 1 exposes no container output+ * descriptors to a same-UID child. `/bin/sh` and Node ship in every image.+ */+export const EXECUTION_RUN_LAUNCHER_SCRIPT = 'exec "$0" "$@" >/dev/null 2>&1'export const EXECUTION_RESULT_PORT = 9300export const EXECUTION_POD_UID_ENV = 'EXECUTION_POD_UID'export const EXECUTION_WORKSPACE_MOUNT_PATH = '/workspace'@@ -474,10 +481,19 @@ export function buildHostExecutionJob(const executor: k8s.V1Container = {name: EXECUTION_EXECUTOR_CONTAINER_NAME,image: resolved.image,- // The fixed launcher passes the approved vector literally to spawn, with- // no added shell. It bounds stdout/stderr at the producer, not just at the- // eventual API response. Separate arguments avoid JSON escape inflation.- command: ['node', EXECUTION_RUN_ENTRYPOINT, String(approved.timeoutMs), ...approved.argv],+ // The fixed /bin/sh launcher execs Node with the approved vector as literal+ // positional parameters (never interpolated into shell source) and points+ // the wrapper's stdout/stderr at /dev/null before exec, so PID 1 exposes no+ // container output descriptors to a same-UID child.+ command: [+ '/bin/sh',+ '-c',+ EXECUTION_RUN_LAUNCHER_SCRIPT,+ 'node',+ EXECUTION_RUN_ENTRYPOINT,+ String(approved.timeoutMs),+ ...approved.argv,+ ],workingDir,// Fixed server-owned, non-secret values only; `serviceLinks` stays disabled// so the API server cannot inject service environment into this pod.