Repository navigation
fix(auth): Codex's sandbox can send events, with a token that can do nothing else - #303
Merged
Merged
Conversation
…nothing else Codex's default Windows sandbox runs hooks as its own local accounts. They could run the hook and reach the recorder, but could not read the API token, restricted to the developer, or write the spool. Every Codex event was posted without a key, refused and lost, while coverage said Codex was hooked. A week of Codex use on the dogfood machine produced zero Codex events. (#302) The recorder now mints an ingest-only token at startup, which hooks already preferred, and the ingest route is the only one that accepts it. Trail reads, evidence export and triage still need the full key; a test holds each refusing it, and fails if a route is switched. `hooks install` grants Codex's sandbox accounts read on that token where they exist, so a sandboxed agent can add events and cannot read or close them. `doctor` fails when they cannot read one. The first run of this change wrote an ingest token into the real data directory: conftest isolated the trail and databases but not the token files, which resolve through data_dir. The live hooks switched to it and the running older recorder refused them until it was removed (spooled, not lost). Both token paths are now isolated, with a test that fails if either escapes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #302.
What was wrong
Codex's default Windows sandbox (
[windows] sandbox = "elevated") runs hooks as its own local accounts,CodexSandboxOfflineandCodexSandboxOnline. Checked inside that sandbox withcodex sandbox -- ...: the hook script runs, the recorder answers on loopback, but the API token cannot be read (owner-only) and the data directory cannot be written. Every Codex event went out without a key, was refused with 401, could not be spooled, and was lost. Coverage still said Codex was hooked. On the dogfood machine: a week of Codex use, zero Codex events.What changed
api_token.ensure_ingest_token(): the recorder mints an ingest-only token at startup (<data dir>/ingest-token, owner-only). An existing one (Enterprise's) is kept. The hook already preferred this file.auth.require_ingest_key: accepts the ingest-only token, then falls through torequire_api_key. Used onPOST /api/v1/audit/ingestonly. Every other route keepsrequire_api_key, which never reads that file.hook_bootstrap.grant_codex_sandbox_ingest(), called from the Codex installer: if Codex's sandbox accounts exist, grants them read on the ingest-only token (icacls /grant <account>:R). Nothing else is widened.doctor: newcodex_sandboxcheck. Fails when the accounts exist and there is no ingest token, or they cannot read it.The security property, tested
tests/test_ingest_token.py(22 tests): the ingest token posts an event (header and bearer forms); it is refused on/tail,/status,/export/evidence,/detections/dispositions/allandPOST /detections/disposition; a wrong token is still refused on ingest; the full token still works. Mutation-checked: switching/tailto the ingest dependency fails the "reaches nothing else" test, and reverting the ingest route fails the "posts an event" test.Found on the way: the suite could touch the real data directory
The first run wrote an ingest token into the maintainer's real data directory:
conftestisolated the trail and databases but not the token files, which resolve throughdata_dir(). The live hooks switched to it and the running (older) recorder refused them for about three minutes. Those events were spooled, not lost, and the stray token was removed.conftestnow isolates both token paths, andtest_no_test_can_reach_the_real_token_filesfails if either escapes pytest's temp directory. One long-standing local-only failure (test_disposition_posts_the_closing_decision) was the same leak and now passes.Checks
15846a0915769d4a. Ruff clean.Not in this PR
A spool location the sandbox accounts can write, so Codex events survive a recorder restart. Listed in #302.
Rollout note
Upgrade the recorder before (or with) running
hooks install: once an ingest token exists, hooks prefer it, and an older recorder refuses it. Hooks then spool rather than lose events, but capture is delayed until the recorder is upgraded.🤖 Generated with Claude Code