Skip to content

feat(security): add a token-rotation drill that proves revocation (#1236) - #1250

Open
HugoXK wants to merge 1 commit into
mainfrom
feat/1236-rotation-drill
Open

HugoXK wants to merge 1 commit into
mainfrom
feat/1236-rotation-drill

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Written-by: HugoXK

Fixes #1236

What changed

  • scripts/lib/rotationDrill.ts — the drill core. It mints a job token and an instance token, proves both resolve through the same authenticateApiToken the gateway and the credential endpoint call, revokes and replaces them, re-seals a bridge token with a throwaway key, and returns a failure unless both old values are refused and both replacements work. Each step writes one rotation.drill.* audit row naming the job and repository; no token value is printed or stored.
  • scripts/rotation-drill.ts — the CLI. The default is a dry run that prints the steps and writes nothing; --apply creates a throwaway database under os.tmpdir() and runs the drill. --db <path> is allowed only inside the temporary root; NODE_ENV=production, the configured DB_PATH and DATA_DIR, and any path outside the temporary root are refused before the file is opened. --keep keeps the default temporary directory for inspection.
  • package.json — npm run rotate:drill (tsx, so the drill runs from source without a build).
  • docs/security.md — a Rotation drill section, beside the production instance-token rotation.
  • changelog.d/1236.security.md — one paragraph.
  • test/rotationDrill.test.ts — the happy path and audit rows, a rotation that leaves an old token live (the drill must fail and record rotation.drill.failed), and the production/live/outside-temp refusals.

Ran:

  • npx tsx --test test/rotationDrill.test.ts — 3 pass, 0 fail
  • npm run rotate:drill — dry run, nothing written
  • npm run rotate:drill -- --apply — rotation: drill passed
  • npm run lint — 11 baseline warnings, unchanged
  • npm run typecheck — pass
  • npm run build — pass
  • npm test — 3321 pass / 9 fail. The same 9 fail on the untouched v0.5.0 tree in a second worktree: deployAutomation (5), gateBaseTree (1), nginxCheck (2), securityHeaders (1). They are macOS host/tool failures, not this diff.

Not run:

  • Docker image and the Playwright visual matrix; this change has no runtime route, page or asset change.
  • A real FlyBot container restart. The drill proves the API-token/credential rule and the bridge-token re-seal; it does not replace scripts/rotate-instance-tokens.mjs, which remains the production rotation.

Risks

  • The drill only writes to a throwaway database: without --db it creates and removes a temporary directory, and --db is refused outside the temporary root or on the configured live path.
  • T3 (package.json, scripts/). The tip needs a PASS from HugoXK-bot; the author of the tip may not PASS it. I have not posted one.

Docs updated: docs/security.md — Rotation drill.

This branch has not been deployed

No deployments
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.

feat(security): add a token-rotation drill that proves old tokens are refused

1 participant