Skip to content

Refuse a token whose audit sync uses up the handover allowance - #3344

Open
jparker2006 wants to merge 2 commits into
mainfrom
cursor/token-audit-expiry-0935
Open

jparker2006 wants to merge 2 commits into
mainfrom
cursor/token-audit-expiry-0935

Conversation

@jparker2006

Copy link
Copy Markdown
Member

Summary

The token service checked the minted lifetime before the audit log write and sync, so a sync longer than the ten-second handover allowance could still return a token the helper must not use.

It checks again after that sync. If the allowance is gone, it revokes the token, records expiry in the mint log, and returns that refusal.

Fixes #1925

Tests

python3 -I tools/github-app/test_token_service.py RequestFixtureTests.test_a_slow_audit_sync_is_refused_when_it_uses_up_the_handover_allowance advances the clock by 12 seconds on each mint-log sync. A token with 311 seconds left is refused and revoked; one with 360 seconds left is still minted. The existing handover test still passes.

Open in Web Open in Cursor 

Co-authored-by: Jake Parker <jparker2006@users.noreply.github.com>
@jparker2006

Copy link
Copy Markdown
Member Author

Review #3344 at 9f18899

  • Blocking (Spec, audit data loss) tools/github-app/token-service.py:242 — If the sync after the append uses up the handover allowance, the service returns expiry and attempts to revoke the token. The log contains both a minted row and an expiry row for the same request. The refusal row also keeps the grant fields reserved for successful mints. The v1 contract gives the operator one outcome per request. In a controlled-clock fixture that delayed only the post-write sync by 12 seconds, the response was expiry, the audit outcomes were [minted, expiry], and the fake GitHub received one revocation attempt. A short write on the corrective append left invalid JSON in the audit log. Preserve one recoverable final outcome and test the sync after the actual append, including the complete audit record.
  • Blocking (Sweep, security) tools/github-app/token-service.py:237 — The added pre-write sync can fail after GitHub has minted a token. The outer handler returns unavailable without revoking it. In the fake-GitHub fixture, an I/O error on the empty log returned exit 1 with zero audit rows and zero revocation attempts. The same fixture on the base returned a usable answer. Attempt revocation on every audit failure that discards an already-minted token.
  • Nit (Standards) tools/github-app/test_token_service.py:281 — The clock hook relies on Linux's /proc/self/fd. On the supported macOS service host, the test silently skips the injected delay and fails its expiry assertion. Identify the log descriptor with os.fstat and the fixture log's device and inode.
  • Nit (Standards) changes/1925.md:1 — The changelog line is allowed by the standing supporting-edit rule. Record that use and the path in the PR description as required by docs/agents/fleet.md.

Checked the repository standards, #1925 and its parent spec, and the full diff. All 42 tests passed across the token-service, token contract, App selection and helper sealing tests. The PR's new test failed against the base for the expected reason.

VERDICT: CHANGES at 9f18899

…lowance.

The log is locked while a line is written and synced. If the sync after the append leaves too little time, that line is replaced in place with an expiry refusal that has no grant fields. Any audit failure leaves a valid unavailable line, or no line at all, and revokes a token GitHub already minted. The test finds the log by device and inode instead of /proc, so it runs the same way on macOS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check token expiry after the audit sync (follow-up for #1841, R1)

1 participant