Skip to content

feat(pm-stack): break-glass owner token — local CLI, audit-first issuance (#9608) - #12941

Merged
dezren39 merged 1 commit into
mainfrom
lane-fp/9608-break-glass-owner-token
Nov 23, 2026
Merged

dezren39 merged 1 commit into
mainfrom
lane-fp/9608-break-glass-owner-token

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Part of #9608 — the first slice of the #1253 split-6 break-glass work (design record doc/2026-11-10T23-58-00Z_design_pm_stack_identity, section 6): the owner break-glass token.

When Access or the IdP is down, asserted authorship must not return as a fallback. The one recovery path the design allows is local: the owner, from the laptop directly, issues a single-use admin stack token via the aggregator's local CLI. This PR lands that path:

  • src/break-glass.ts — BreakGlassTokenStore (file-backed, fresh disk reads on every operation, serialized check-and-consume so a second presentation can never also win), issueBreakGlassToken, consumeBreakGlassToken, and the issuance audit-event builder. Invariants: TTL capped at one hour (longer requests refused, never silently honoured); the audit event is recorded before the token record is persisted — an audit-write failure means no token exists; only the token's sha256 hash is ever persisted; unknown, expired, already-consumed, and empty tokens all fail closed.
  • scripts/issue-break-glass-token.ts — the local CLI (--ttl-minutes, --tokens, --events). It resolves the state paths directly rather than through loadConfig: it is a local operator tool, not the server, so the server's Source gate (Aggregator: fail loud instead of defaulting to fixtures outside dev #1195) must not stand between the owner and the recovery path during an outage.
  • src/config.ts — breakGlassFile (PM_AGG_BREAK_GLASS_FILE, default ~/.local/state/pm-aggregator/break-glass-tokens.json, mirroring the identity-registry precedent from impl(pm-stack): aggregator identity registry table + owner admin actions + audit events (#1253 split 2) #9604) so the path has one canonical home for the follow-on server wiring.

The Q4 gate on #1253 covers only the comment surface; this slice touches no comment code. Remaining slices for #9608, named on the issue: outage queueing for eligible non-comment writes, and server-side acceptance of the break-glass token on admin routes (the consume half is implemented and tested here; the route wiring is the next slice).

Evidence

Ran on the laptop in a worktree off origin/main:

  • Failing-first: bun test test/break-glass.test.ts on origin/main fails (module ../src/break-glass.ts not found); after this change: 7 pass / 0 fail — audit-before-persist ordering (a sink that inspects the token file mid-issuance sees zero tokens), audit-failure fails closed, one-hour cap, single-use, expiry, hash-only persistence, audit-event shape. Oracle: design section 6.
  • Neighbouring suites: bun test test/identity-registry.test.ts test/config.test.ts plus events/access-identity — 22 pass / 0 fail in the final combined run (58 pass across identity-registry + events + access-identity earlier in the run).
  • Typecheck: bunx tsc --noEmit reports no errors in the touched files.
  • CLI smoke (temp state files, no env): issue at --ttl-minutes 45 prints the token once, writes exactly one break-glass-token-issued audit event and one hash-only token record; --ttl-minutes 61 exits 1.
  • Pre-existing failure, not from this change: test/boot.test.ts fails identically on a pristine origin/main worktree (0 pass / 1 fail) and in this branch.

Merge Danger

Low. New module + new script + one additive config field with a default; no server route changes, no changes to existing stores or file formats. The token store file is created only when the CLI is run. Reverting removes the slice cleanly.


Show it working
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…ance (#9608)

First slice of #1253 split 6 (design section 6): the owner can issue a
single-use, at-most-one-hour admin stack token from the laptop via the
aggregator's local CLI. Issuance is written as an audit event before
the token record is persisted — if the audit write fails, no token
exists. Only the token's sha256 hash is persisted; consume is
single-use and fails closed on unknown, expired, or reused tokens.

- src/break-glass.ts: token store (fresh disk reads, serialized
  check-and-consume), issue/consume, issuance audit event
- scripts/issue-break-glass-token.ts: the local CLI
- src/config.ts: breakGlassFile path (PM_AGG_BREAK_GLASS_FILE)
- test/break-glass.test.ts: 7 tests against the section-6 oracle
@dezren39
dezren39 requested a review from a team as a code owner November 23, 2026 05:30
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 38 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 25e93379-5e2f-43ca-9c5c-afcf66f5f490
Commits

Reviewing files that changed from the base of the PR and between 0f311ae and e23f522.

Files selected for processing: 4

  • pm-stack/aggregator/scripts/issue-break-glass-token.ts
  • pm-stack/aggregator/src/break-glass.ts
  • pm-stack/aggregator/src/config.ts
  • pm-stack/aggregator/test/break-glass.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T05:32:18.505720Z e23f522 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39
dezren39 merged commit 02dc9d7 into main Nov 23, 2026
2 checks passed
@dezren39
dezren39 deleted the lane-fp/9608-break-glass-owner-token branch November 23, 2026 05:31
dezren39 added a commit that referenced this pull request Nov 23, 2026
Conflict resolution: pm-stack/aggregator/src/config.ts — keep both
additive fields (stackTokenSecret from this branch, breakGlassFile
from main, PR #12941).

Shepherd fixes (no re-implementation):
- stack-token.ts: verification now requires explicit iat/exp claims.
  normalizeClaims substitutes minting defaults for absent timestamps,
  which let a correctly signed timestamp-less token verify
  indefinitely (Codex P2 finding on this PR). Minting unchanged.
  Regression test added to test/stack-token.test.ts.
- server.ts: the stack-token exchange route treated only "" as
  unconfigured; cfg.stackTokenSecret is string | null, so an
  unconfigured secret slipped through to mintStackToken (TS2345,
  tsc --noEmit failed; runtime returned a misleading 400 instead of
  503). Guard is now !secret.

Verification: stack-token + config + break-glass suites 23 pass /
0 fail; tsc --noEmit clean; full aggregator suite 3042 pass / 20
fail with a failure set identical to a pristine-main baseline run
(all 20 pre-existing under load, incl. boot.test.ts).
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.

1 participant