From adb82b0f75a0860bbe628c7b4f6d5fc9376b7108 Mon Sep 17 00:00:00 2001 From: shiny-code-bot Date: Fri, 24 Jul 2026 12:02:43 -0400 Subject: [PATCH 1/2] fix(supervisor): require V8 JIT entitlement --- scripts/codex_lab_package/supervisor.py | 49 ++++++++ scripts/codex_lab_package/test_supervisor.py | 114 +++++++++++++++---- 2 files changed, 141 insertions(+), 22 deletions(-) diff --git a/scripts/codex_lab_package/supervisor.py b/scripts/codex_lab_package/supervisor.py index 1b424030024..bfe33b82a14 100644 --- a/scripts/codex_lab_package/supervisor.py +++ b/scripts/codex_lab_package/supervisor.py @@ -31,6 +31,8 @@ DEFAULT_LISTEN_HOST = APP_SERVER_LISTEN_HOST DEFAULT_LISTEN_PORT = APP_SERVER_LISTEN_PORT MANAGED_CLI_RELATIVE_PATH = Path("packages/standalone/current/codex") +ALLOW_JIT_ENTITLEMENT = "com.apple.security.cs.allow-jit" +ALLOW_JIT_ENTITLEMENT_PLUTIL_KEY_PATH = r"com\.apple\.security\.cs\.allow-jit" @dataclass(frozen=True) @@ -149,6 +151,14 @@ def inspect_engine( team_identifier = _signature_field(signature_output, "TeamIdentifier") if not signing_identifier or not team_identifier or team_identifier == "not set": raise ValueError("managed Codex Lab engine lacks a stable signing identity") + code_signing_entitlements = _code_signing_entitlements( + managed_cli, + codesign_path=codesign_path, + ) + if ALLOW_JIT_ENTITLEMENT not in code_signing_entitlements: + raise ValueError( + "managed Codex Lab engine lacks the required V8 JIT entitlement" + ) return EngineIdentity( build_channel=provenance["build_channel"], build_profile=provenance["build_profile"], @@ -182,6 +192,7 @@ def build_supervisor_runner( EXPECTED_VERSION={quote(identity.version)} EXPECTED_SIGNING_IDENTIFIER={quote(identity.signing_identifier)} EXPECTED_TEAM_IDENTIFIER={quote(identity.team_identifier)} +ALLOW_JIT_ENTITLEMENT_KEY_PATH={quote(ALLOW_JIT_ENTITLEMENT_PLUTIL_KEY_PATH)} CODESIGN={quote(tools.codesign)} PLUTIL={quote(tools.plutil)} SHASUM={quote(tools.shasum)} @@ -190,15 +201,21 @@ def build_supervisor_runner( UPDATER_PID_FILE="$LAB_HOME/app-server-daemon/app-server-updater.pid" DAEMON_PID_FILE="$LAB_HOME/app-server-daemon/app-server.pid" PROVENANCE_FILE= +ENTITLEMENTS_FILE= LAST_STATE= cleanup() {{ [ -z "$PROVENANCE_FILE" ] || /bin/rm -f "$PROVENANCE_FILE" + [ -z "$ENTITLEMENTS_FILE" ] || /bin/rm -f "$ENTITLEMENTS_FILE" }} discard_provenance() {{ cleanup PROVENANCE_FILE= }} +discard_entitlements() {{ + [ -z "$ENTITLEMENTS_FILE" ] || /bin/rm -f "$ENTITLEMENTS_FILE" + ENTITLEMENTS_FILE= +}} log_state() {{ [ "$1" = "$LAST_STATE" ] && return printf '%s %s\n' "$(/bin/date -u '+%Y-%m-%dT%H:%M:%SZ')" "$1" >&2 @@ -239,6 +256,14 @@ def build_supervisor_runner( team_identifier=$(printf '%s\n' "$signature" | /usr/bin/awk -F= '$1 == "TeamIdentifier" {{ print substr($0, index($0, "=") + 1); exit }}') [ "$signing_identifier" = "$EXPECTED_SIGNING_IDENTIFIER" ] || return 1 [ "$team_identifier" = "$EXPECTED_TEAM_IDENTIFIER" ] || return 1 + ENTITLEMENTS_FILE=$(/usr/bin/mktemp "${{TMPDIR:-/tmp}}/codex-lab-entitlements.XXXXXX") + if ! "$CODESIGN" -d --entitlements :- "$MANAGED_CLI" >"$ENTITLEMENTS_FILE" 2>/dev/null; then + discard_entitlements + return 1 + fi + allow_jit=$("$PLUTIL" -extract "$ALLOW_JIT_ENTITLEMENT_KEY_PATH" raw -o - "$ENTITLEMENTS_FILE" 2>/dev/null || true) + discard_entitlements + [ "$allow_jit" = true ] || return 1 PROVENANCE_FILE=$(/usr/bin/mktemp "${{TMPDIR:-/tmp}}/codex-lab-supervisor.XXXXXX") if ! "$MANAGED_CLI" debug provenance --json >"$PROVENANCE_FILE"; then discard_provenance @@ -453,6 +478,30 @@ def _signature_field(output: str, name: str) -> str: ) +def _code_signing_entitlements( + path: Path, + *, + codesign_path: Path, +) -> tuple[str, ...]: + completed = subprocess.run( + [str(codesign_path), "-d", "--entitlements", ":-", str(path)], + check=True, + capture_output=True, + text=True, + ) + if not completed.stdout.strip(): + return () + try: + entitlements = plistlib.loads(completed.stdout.encode()) + except plistlib.InvalidFileException as exc: + raise ValueError("managed Codex Lab engine has invalid entitlements") from exc + if not isinstance(entitlements, dict): + raise ValueError("managed Codex Lab engine has invalid entitlements") + return tuple( + sorted(key for key, value in entitlements.items() if value is True) + ) + + def _require_expected_identity( identity: EngineIdentity, *, diff --git a/scripts/codex_lab_package/test_supervisor.py b/scripts/codex_lab_package/test_supervisor.py index 5441de6f21b..01fe1702019 100644 --- a/scripts/codex_lab_package/test_supervisor.py +++ b/scripts/codex_lab_package/test_supervisor.py @@ -13,6 +13,7 @@ from codex_lab_package.supervisor import EngineIdentity from codex_lab_package.supervisor import SupervisorPaths +from codex_lab_package.supervisor import SupervisorTools from codex_lab_package.supervisor import build_launch_agent_plist from codex_lab_package.supervisor import build_supervisor_runner from codex_lab_package.supervisor import inspect_engine @@ -20,6 +21,50 @@ class SupervisorTest(unittest.TestCase): + def _write_engine(self, path: Path, *, source_commit: str = "c" * 40) -> None: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text( + """#!/bin/sh +if [ "${1:-}" = debug ] && [ "${2:-}" = provenance ]; then + printf '{"schema_version":1,"version":"1.2.3","source_commit":"%s","dirty_state":"clean","build_profile":"release","build_channel":"release","executable_path":"%s"}\\n' "__COMMIT__" "$0" + exit 0 +fi +exit 2 +""".replace("__COMMIT__", source_commit), + encoding="utf-8", + ) + os.chmod(path, 0o755) + + def _write_codesign( + self, + path: Path, + *, + entitlement_value: str | None, + ) -> None: + entitlement_output = "" + if entitlement_value is not None: + entitlement_output = f"""cat <<'EOF' + + +com.apple.security.cs.allow-jit<{entitlement_value}/> +EOF +""" + path.write_text( + """#!/bin/sh +if [ "${1:-}" = --verify ]; then + exit 0 +fi +if [ "${2:-}" = --entitlements ]; then +__ENTITLEMENT_OUTPUT__ + exit 0 +fi +echo 'Identifier=dev.example.codex-lab' >&2 +echo 'TeamIdentifier=TEAM123456' >&2 +""".replace("__ENTITLEMENT_OUTPUT__", entitlement_output), + encoding="utf-8", + ) + os.chmod(path, 0o755) + def _identity(self) -> EngineIdentity: return EngineIdentity( build_channel="release", @@ -45,6 +90,7 @@ def test_runner_and_plist_pin_direct_websocket_engine(self) -> None: subprocess.run(["/bin/sh", "-n", str(runner_path)], check=True) self.assertIn("EXPECTED_SHA256=" + "a" * 64, runner) self.assertIn("EXPECTED_SOURCE_COMMIT=" + "b" * 40, runner) + self.assertIn("com\\.apple\\.security\\.cs\\.allow-jit", runner) self.assertIn("LISTEN_URL=ws://127.0.0.1:4766", runner) self.assertIn("app-server --remote-control --listen", runner) self.assertEqual(runner.count("in ''|*[!0-9]*) return 0"), 2) @@ -61,29 +107,9 @@ def test_inspect_engine_records_signature_and_digest(self) -> None: root = Path(temp_dir) engine = root / "codex" source_commit = "c" * 40 - engine.write_text( - """#!/bin/sh -if [ "${1:-}" = debug ] && [ "${2:-}" = provenance ]; then - printf '{"schema_version":1,"version":"1.2.3","source_commit":"%s","dirty_state":"clean","build_profile":"release","build_channel":"release","executable_path":"%s"}\\n' "__COMMIT__" "$0" - exit 0 -fi -exit 2 -""".replace("__COMMIT__", source_commit), - encoding="utf-8", - ) - os.chmod(engine, 0o755) + self._write_engine(engine, source_commit=source_commit) codesign = root / "codesign" - codesign.write_text( - """#!/bin/sh -if [ "${1:-}" = --verify ]; then - exit 0 -fi -echo 'Identifier=dev.example.codex-lab' >&2 -echo 'TeamIdentifier=TEAM123456' >&2 -""", - encoding="utf-8", - ) - os.chmod(codesign, 0o755) + self._write_codesign(codesign, entitlement_value="true") identity = inspect_engine(engine, codesign_path=codesign) self.assertEqual(identity.source_commit, source_commit) @@ -91,6 +117,50 @@ def test_inspect_engine_records_signature_and_digest(self) -> None: identity.sha256, hashlib.sha256(engine.read_bytes()).hexdigest() ) + def test_inspect_engine_rejects_missing_v8_jit_entitlement(self) -> None: + for entitlement_value in (None, "false"): + with self.subTest(entitlement_value=entitlement_value): + with tempfile.TemporaryDirectory() as temp_dir: + root = Path(temp_dir) + engine = root / "codex" + self._write_engine(engine) + codesign = root / "codesign" + self._write_codesign( + codesign, + entitlement_value=entitlement_value, + ) + + with self.assertRaisesRegex(ValueError, "V8 JIT entitlement"): + inspect_engine(engine, codesign_path=codesign) + + @unittest.skipUnless(sys.platform == "darwin", "macOS supervisor runner") + def test_runner_check_requires_v8_jit_entitlement(self) -> None: + with tempfile.TemporaryDirectory() as temp_dir: + root = Path(temp_dir) + paths = SupervisorPaths( + lab_home=root / "lab", + launch_agents_dir=root / "LaunchAgents", + ) + self._write_engine(paths.managed_cli) + codesign = root / "codesign" + self._write_codesign(codesign, entitlement_value="true") + identity = inspect_engine(paths.managed_cli, codesign_path=codesign) + runner = build_supervisor_runner( + paths, + identity, + tools=SupervisorTools(codesign=codesign), + ) + paths.runner.parent.mkdir(parents=True, exist_ok=True) + paths.runner.write_text(runner, encoding="utf-8") + os.chmod(paths.runner, 0o755) + + self.assertEqual(subprocess.run([paths.runner, "check"]).returncode, 0) + self._write_codesign(codesign, entitlement_value="false") + self.assertNotEqual( + subprocess.run([paths.runner, "check"]).returncode, + 0, + ) + def test_install_writes_files_and_bootstraps_expected_service(self) -> None: with tempfile.TemporaryDirectory() as temp_dir: root = Path(temp_dir) From e949a9bb4ba792ade34f67f0fefb68d1cc9fea1f Mon Sep 17 00:00:00 2001 From: shiny-code-bot Date: Fri, 24 Jul 2026 12:09:59 -0400 Subject: [PATCH 2/2] style(supervisor): apply Python formatting --- scripts/codex_lab_package/supervisor.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/codex_lab_package/supervisor.py b/scripts/codex_lab_package/supervisor.py index bfe33b82a14..fc5fec82fb2 100644 --- a/scripts/codex_lab_package/supervisor.py +++ b/scripts/codex_lab_package/supervisor.py @@ -497,9 +497,7 @@ def _code_signing_entitlements( raise ValueError("managed Codex Lab engine has invalid entitlements") from exc if not isinstance(entitlements, dict): raise ValueError("managed Codex Lab engine has invalid entitlements") - return tuple( - sorted(key for key, value in entitlements.items() if value is True) - ) + return tuple(sorted(key for key, value in entitlements.items() if value is True)) def _require_expected_identity(