Skip to content

fix(auth): Codex's sandbox can send events, with a token that can do nothing else - #303

Merged
blitzcrieg1 merged 1 commit into
masterfrom
fix/codex-sandbox-ingest-token
Oct 21, 2026
Merged

blitzcrieg1 merged 1 commit into
masterfrom
fix/codex-sandbox-ingest-token

Conversation

@blitzcrieg1

Copy link
Copy Markdown
Owner

Fixes #302.

What was wrong

Codex's default Windows sandbox ([windows] sandbox = "elevated") runs hooks as its own local accounts, CodexSandboxOffline and CodexSandboxOnline. Checked inside that sandbox with codex 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 to require_api_key. Used on POST /api/v1/audit/ingest only. Every other route keeps require_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: new codex_sandbox check. Fails when the accounts exist and there is no ingest token, or they cannot read it.
  • Hook selftest reads the trail back with the full token, since the ingest token is refused there by design.

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/all and POST /detections/disposition; a wrong token is still refused on ingest; the full token still works. Mutation-checked: switching /tail to 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: 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 for about three minutes. Those events were spooled, not lost, and the stray token was removed. conftest now isolates both token paths, and test_no_test_can_reach_the_real_token_files fails 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

  • Frozen files untouched; fingerprint 15846a0915769d4a. Ruff clean.
  • Full suite locally: 1863 passed; 3 known local-only failures (also on master). README count 1848 to 1870 (CI collects two fewer).

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

…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]>
@blitzcrieg1
blitzcrieg1 merged commit 2944440 into master Oct 21, 2026
11 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex on Windows records nothing: its sandbox user cannot read the API token or write the spool

1 participant