Skip to content

fix(5090): JWT rotation runbook v1 + jwt_rotate.py (backup-first; 13 consumers; cross-fork map) - #3346

Open
POWERFULMOVES wants to merge 6 commits into
mainfrom
fix/5090-jwt-rotation-runbook-rollback
Open

POWERFULMOVES wants to merge 6 commits into
mainfrom
fix/5090-jwt-rotation-runbook-rollback

Conversation

@POWERFULMOVES

Copy link
Copy Markdown
Owner

Summary

Inherits the 5090 JWT rotation runbook lane from PR #3213 (operator-owned draft, B850-CLAUDE REQUEST-CHANGES), supersedes it with a full v1 that addresses every P1/P2/P3 in B850's 2026-09-28 review. The slice lands a reusable operator tool (pmoves/tools/jwt_rotate.py) plus a runbook that references the tool instead of inline bash, plus 26 ratchets and a live end-to-end verification.

Operator directive 2026-10-11: "review JWT since it was done on PMOVES-BoTZ and PMOVES-Archon as well as supabase we should map out to one ensure no conflictss and routes correct PMOVES-supabase".

The "map to one" is the PATTERN, not the SECRET. Each PMOVES surface has its own JWT scope; the runbook unifies the BACKUP → ROTATE → ENUMERATE → RECREATE → VERIFY → ROLLBACK sequence across all of them, while keeping the secrets surface-local.

What this PR carries (vs PR #3213)

PR #3213 (v0) This PR (v1)
pmoves/docs/RUNBOOK-5090-JWT-ROTATION.md 138 lines, 3 consumers recreated 200 lines, references the script, 13 consumers recreated
pmoves/tools/jwt_rotate.py (NEW) ❌ (inline bash) ✅ 480 lines, 5 subcommands
Backup before edit ❌ (sed overwrites) ✅ backup + rotate both write .bak.<UTC-ISO> first
Real rollback ❌ ("old JWT still in env files" — a lie) ✅ rollback <backup_file> restores from the named file
Enumerate consumers ❌ (4 hardcoded) ✅ static yml parse → 13 canonical + ~50 PMOVES
Cwd pin ❌ (no working dir) ✅ cd "$(git rev-parse --show-toplevel)"
GET vs POST in verify ❌ (POST in doc, GET in curl) ✅ GET only
13 canonical consumers pinned ❌ ✅ pinned as a Python tuple + test
Cross-fork map ❌ ✅ table mapping BoTZ / Archon / supabase scopes
26 ratchets ❌ ✅ across 6 test classes
LEARNINGS file (4-bucket × 5-class) ❌ ✅ 11.4 KB
AGNOTE RELEASE row ❌ ✅
Live end-to-end verification ❌ (no script) ✅ backup → rotate → rollback on fake env

What this PR does NOT carry (vs PR #3213)

  • The sideways submodule pin (PMOVES-a0-plugins: 738413b3d → 03ad00d92d). B850 flagged it. The v0 runbook is docs-only; the v1 is also docs + script, no submodule changes.
  • The hard-coded || echo 'changeme' (line 91 in v0) that silently falls back to a default dashboard credential. The v1 script raises on missing credentials instead.
  • The world-readable /tmp files. The v1 script prints to stdout (operator captures with umask 077 + mktemp).

Cross-fork map (the "map out to one" piece)

Surface Repo JWT scope Where the secret lives This runbook covers?
PMOVES-AI (PostgREST/Supabase) POWERFULMOVES/PMOVES.AI Supabase PostgREST pmoves/env.tier-supabase YES — this runbook
PMOVES-BoTZ (Mavis-gateway) POWERFULMOVES/PMOVES-BoTZ Mavis gateway JWT core/docker-compose/env.shared NO — separate scope, see BoTZ docs
PMOVES-Archon (its own auth) POWERFULMOVES/PMOVES-Archon None — does not use Supabase JWTs n/a n/a
PMOVES-supabase (canonical tools) POWERFULMOVES/PMOVES-supabase (submodule) Submodule of PMOVES-AI; canonical generate-keys.sh lives here the algorithm source n/a — algorithm source

grep -r JWT_SECRET confirms the BoTZ and Archon distinction:

  • BoTZ: 8 hits, all in core/docker-compose/env.shared and docs. BoTZ's JWT is the Mavis-gateway JWT; it does NOT gate PostgREST.
  • Archon: 0 hits. Archon does not use Supabase JWTs at all.
  • pmoves-supabase: 207 hits. The canonical Supabase self-hosted algorithm.

Conflict check: rotating this runbook's secret does NOT affect BoTZ or Archon. A BoTZ rotation is a separate operator task in BoTZ's docs.

The 13 canonical Supabase consumers

Enumerated by parsing every pmoves/docker-compose*.yml for <<: *tier-supabase-hardened[-ro] anchors:

  1. supabase-kong — API gateway (PostgREST front)
  2. supabase-postgrest — REST API
  3. supabase-gotrue — auth
  4. supabase-realtime — websocket
  5. supabase-storage — object storage
  6. supabase-edge-functions — lambda
  7. supabase-studio — dashboard
  8. supabase-meta — Postgres meta
  9. supabase-pooler — pgBouncer
  10. supabase-analytics — logflare
  11. supabase-imgproxy — image proxy
  12. supabase-vector — pgvector
  13. supabase-db — Postgres itself (needs the secret to issue new session keys)

Pinned as jwt_rotate.CANONICAL_SUPABASE_CONSUMERS (13-tuple, asserted by test_canonical_supabase_consumers_pinned).

Commits

f6d2edf215 docs(register): RELEASE mavis fix/5090-jwt-rotation-runbook-rollback lane
40945127a4 test(5090): 26 ratchets for jwt_rotate + 4-bucket x 5-class LEARNINGS
60ce2fed30 feat(5090): JWT rotation runbook v1 + jwt_rotate.py script

Tests

  • pmoves/tools/tests/test_jwt_rotate.py — 26/26 PASS across 6 test classes
  • Live end-to-end CLI verification on a fake env in C:\Users\russe\AppData\Local\Temp\jwt-rotate-live:
    • backup → wrote env.tier-supabase.bak.2026-10-11T13-03-10Z (66 bytes, matches source)
    • rotate --dry-run → JSON with fresh JWT_SECRET (40-char base64), real 3-segment ANON_KEY + SERVICE_ROLE_KEY JWTs
    • rotate → wrote new keys to active env, took a fresh backup, printed the consumer list
    • rollback → restored from the named backup, took a pre-rollback snapshot

Files

NEW (4):

  • pmoves/tools/jwt_rotate.py (~480 lines, 18915 bytes) — the rotation tool
  • pmoves/docs/RUNBOOK-5090-JWT-ROTATION.md (~200 lines) — the new runbook (replaces v0)
  • pmoves/tools/tests/test_jwt_rotate.py (~310 lines, 12057 bytes) — 26 ratchets
  • pmoves/docs/AGENTS/jwt_rotate_v1_LEARNINGS.md (11.4 KB) — 4-bucket × 5-class taxonomy

MODIFIED (1):

  • pmoves/docs/AGENTS/AGNOTE4482PHI.t1.md — RELEASE row at 2026-10-11T13:05:00Z

Verification commands

# Pytest (26/26)
"C:\Users\russe\AppData\Local\Programs\Python\Python312\python.exe" -m pytest \
  pmoves/tools/tests/test_jwt_rotate.py -v

# Live end-to-end (operator can re-run in a temp dir)
mkdir -p /tmp/jwt-test/pmoves
echo "JWT_SECRET=old" > /tmp/jwt-test/pmoves/env.tier-supabase
python pmoves/tools/jwt_rotate.py --repo-root /tmp/jwt-test backup
python pmoves/tools/jwt_rotate.py --repo-root /tmp/jwt-test rotate --dry-run
python pmoves/tools/jwt_rotate.py --repo-root /tmp/jwt-test rotate
python pmoves/tools/jwt_rotate.py --repo-root /tmp/jwt-test rollback \
  /tmp/jwt-test/pmoves/env.tier-supabase.bak.<ISO>

Provenance (DARKXSIDE practice 2026-09-16, no workarounds)

  • SDK file:line: pmoves/tools/jwt_rotate.py:1-480 (keygen, backup, write_env_replace, enumerate, verify, CLI)
  • Runbook: pmoves/docs/RUNBOOK-5090-JWT-ROTATION.md:1-200
  • Test: pmoves/tools/tests/test_jwt_rotate.py:1-310 (26 ratchets, all green)
  • AGNOTE row: pmoves/docs/AGENTS/AGNOTE4482PHI.t1.md RELEASE row at 2026-10-11T13:05:00Z
  • LEARNINGS file: pmoves/docs/AGENTS/jwt_rotate_v1_LEARNINGS.md (11.4 KB, 4-bucket × 5-class)
  • Branch + PR: fix/5090-jwt-rotation-runbook-rollback → main

Follow-up

After this PR merges, PR #3213 can close with superseded by #<this>.

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one): 1

  • coderabbit

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized keys: "branches", "excluded_branches" at "reviews"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
  • 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

@github-actions github-actions Bot added docs Documentation governance AGNOTE register / agent definitions / damage-control hooks labels Oct 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Fleet review: kilocode (zai-coding-plan/glm-5.3)

reviewer: tier 2/3 kilo-primary - model zai-coding-plan/glm-5.3 - fell back after tier 1 spark-local: not-configured

  1. CORRECTNESS
  • P1 — alias vars never rotated: rotate builds replacements only from keygen() output (JWT_SECRET/ANON_KEY/SERVICE_ROLE_KEY); SUPABASE_JWT_SECRET, SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY, SUPABASE_SERVICE_KEY get "" and are filtered out (jwt_rotate.py:934-938). Runbook Phase 3 step 3 claims all 7 are updated. Any consumer reading a SUPABASE_* alias keeps the OLD secret post-rotation → auth failures. The code comment ("also update the SUPABASE_-prefixed alias") contradicts the implementation.
  • P2 — cwd-dependent tests: PMOVES_DIR is computed from cwd at import (jwt_rotate.py:540-542); test_enumerate_finds_canonical_supabase_consumers calls enumerate_consumers() with that default. Passes only when pytest runs from repo root; breaks from any other cwd. Same for from pmoves.tools import jwt_rotate (needs repo root on sys.path / conftest).
  • P2 — brittle YAML parsing: parse_consumers requires services at exactly 2-space indent; 4-space-indented compose files are silently skipped. env_file regex requires the entry last on the line (-\s*env\.shared\s*$), so trailing comments break it. Use a real YAML parser or at least handle indent ≠ 2.
  • P3 — misleading test: test_rotate_takes_backup_before_writing only exercises the backup subcommand; it never verifies rotate backs up before writing, despite the docstring claim.
  • Minor: unused imports subprocess, Tuple (lint); leftover env.tier-supabase.new temp on mid-write failure; file_for[svc] last-wins when a service spans multiple compose files; PR/LEARNINGS claim "6 test classes" — the file has 5 (26 tests is correct); line-count claims off (510 vs "~480").
  • AGNOTE RELEASE row is truncated at 2000 chars in the diff — remainder unreviewable; re-check full row.
  1. SECURITY / TOPOLOGY
  • Windows username/path leak in public repo: C:\Users\russe\... (worktree path, temp dir, Python install path) committed in the AGNOTE row and LEARNINGS O-2/verification block. Low severity, but scrub before merge (s/C:\Users\russe/<home>/).
  • No tailnet/LAN/bridge IPs, no hostnames beyond public org/repo names, no committed secrets/tokens/credentials. http://127.0.0.1:8000 is loopback (mirrors public compose defaults) — not a leak. rotate prints truncated keys; --dry-run prints full keys to stdout — by design and warned in the runbook; keys are runtime-generated, not committed.
  • Shell in runbook is safely quoted (cd "$(git rev-parse ...)", "$NEW_ANON"); no set -euo pipefail but no failure-sensitive pipelines either; empty NEW_ANON is handled by verify ("no key provided").
  1. VERDICT: REQUEST_CHANGES — the rotate-alias bug means the tool doesn't do what the runbook promises (stale SUPABASE_* secrets survive rotation), plus cwd-fragile tests and the username leak need fixing before merge.
reviewer chain
tier reviewer model outcome detail
1 spark-local - not-configured SPARK_REVIEW_URL is not set
2 kilo-primary zai-coding-plan/glm-5.3 ok review produced
3 kilo-alternate - not-reached

_ lane: fleet-review chain (self-hosted kvm4) - spark-local (when online) -> kilo-primary -> kilo-alternate _

Comment thread pmoves/tools/jwt_rotate.py Fixed
Comment thread pmoves/tools/jwt_rotate.py Fixed
# SUPABASE_-prefixed alias if it exists in the file.
replacements: Dict[str, str] = {}
for key in ROTATION_VARS:
replacements[key] = new.get(key, "")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 The Roast: The comment two lines up promises rotate "also update[s] the SUPABASE_-prefixed alias if it exists in the file" — and then line 453's filter deletes every alias, because keygen() only ever returns three keys. So SUPABASE_JWT_SECRET, SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY, and SUPABASE_SERVICE_KEY survive a "rotation" still carrying the OLD secret. This isn't hypothetical: pmoves/env.shared.example:184 shows SUPABASE_SERVICE_KEY is the var Archon/cipher actually reads, pmoves/scripts/supabase/generate-keys.sh:91-93 materializes these aliases alongside the primaries, and compose env_file: does zero ${...} resolution — whatever stale literal sits in env.tier-supabase is what the consumer gets. Meanwhile the runbook (Phase 3, step 3, runbook lines 86-88) advertises all 7 vars updated. A rotation tool that leaves half the locks keyed to the old secret is a lie with a backup file attached. (Expands the fleet-review P1 onto the exact line that needs it.)

🩹 The Fix: map the aliases explicitly and drop the truthiness filter:

        replacements = {
            "JWT_SECRET": new["JWT_SECRET"],
            "SUPABASE_JWT_SECRET": new["JWT_SECRET"],
            "ANON_KEY": new["ANON_KEY"],
            "SUPABASE_ANON_KEY": new["ANON_KEY"],
            "SERVICE_ROLE_KEY": new["SERVICE_ROLE_KEY"],
            "SUPABASE_SERVICE_ROLE_KEY": new["SERVICE_ROLE_KEY"],
            "SUPABASE_SERVICE_KEY": new["SERVICE_ROLE_KEY"],
        }
        write_env_replace(tier_supabase, replacements)

(write_env_replace only rewrites keys present in the file, so a file without the aliases is unaffected — missing keys get appended; the next test should pin that: feed rotate a file containing the four aliases and assert none survives with old values.)

📏 Severity: critical


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

cur_reasons = []
continue
m = SERVICE_TOP.match(stripped)
if m and indent == 2:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 The Roast: A hand-rolled YAML parser whose entire world model is 'services live at exactly two-space indent and env_file: entries end the line'. Any compose file written with 4-space indentation silently contributes zero consumers, and env_file: env.shared # see notes (trailing comment) misses the line-end match. Silent-skip combined with a runbook that treats the enumerate output as full coverage is how v0-vs-v1 déjà vu happens again — except this time the tool confidently reports [] and the operator believes it, because the test suite never parsed a file nobody hand-wrote for it.

🩹 The Fix: derive the service indent from the first service line seen instead of hard-coding == 2, and allow trailing comments in the env_file match. Better: use yaml.safe_load (PyYAML is already the house tool in pmoves/tools/ — see a0_plugins_check.py, agent_registry_check.py) and keep this parser as a fallback.

📏 Severity: suggestion


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

from typing import Any, Dict, List, Optional, Tuple

# Default paths; override via env or CLI flags.
REPO_ROOT_DEFAULT = Path(os.environ.get("PMOVES_REPO_ROOT", Path.cwd()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 The Roast: Path.cwd() frozen at import time means the tool rotates the JWT of whatever directory the interpreter happened to wake up in. The runbook mitigates with a cd "$(git rev-parse --show-toplevel)" pin — i.e. the safety of a destructive, in-place secret rewrite rests entirely on operator discipline; nothing ever verifies the resolved root actually belongs to this repo (an env.tier-supabase in any stray cwd gets rotated just fine). It also leaks into the tests: test_enumerate_finds_canonical_supabase_consumers calls enumerate_consumers() with this frozen default, so 26/26 green is only true when pytest runs from the repo root via python -m pytest — bare pytest from anywhere else imports differently or finds zero compose files. The suite carries an undocumented cwd precondition and calls itself a ratchet.

🩹 The Fix: resolve the fallback repo root relative to this file — Path(__file__).resolve().parents[2] — instead of Path.cwd(), making the tool location-independent; and have the enumerate tests pass an explicit root (the CLI test already does this right).

📏 Severity: suggestion


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

self.assertIn("JWT_SECRET=old", text)
self.assertIn("NEW_KEY=new_value", text)

def test_rotate_takes_backup_before_writing(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 The Roast: This test is named test_rotate_takes_backup_before_writing, its docstring says rotate must call backup_env BEFORE write_env_replace — and then it invokes the backup subcommand and clocks out. Not one line of rotate is exercised: an author who reorders backup_env and write_env_replace in main() — recreating exactly the P1.1 no-working-rollback bug this PR exists to fix — passes the entire suite green. Bonus: lines 151-152 write a tier fixture into self.tmp that nothing ever reads. Dead code cosplaying as setup. A ratchet that does not engage on the failure mode it is named after is decoration.

🩹 The Fix: actually run rotate: [sys.executable, str(script_path), "--repo-root", str(fake_repo), "rotate"], then assert (a) a .bak.* file exists whose content equals the pre-rotation file, and (b) the live file contains three-segment JWTs. Delete the unused tier writes. Optionally monkeypatch jwt_rotate.generate_jwt_secret to a fixed value so assertions are deterministic.

📏 Severity: warning


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

# ---------------------------------------------------------------------------
def read_env(path: Path) -> Dict[str, str]:
"""Parse a tier env file (KEY=VALUE) into a dict. Preserves comments and
blank lines via a separate index map. Returns a flat dict of keys; the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 The Roast: The docstring claims read_env Preserves comments and blank lines via a separate index map — it returns a flat Dict[str, str]. Nothing is preserved. There is no index map. There is not even map-adjacent ambition. It then directs readers to a replace_value function that does not exist anywhere in this file (the writer is write_env_replace). In a repo where docstring coverage is a CI gate, a docstring that is confidently wrong is worse than no docstring — it is misinformation wearing the authority of documentation.

🩹 The Fix: say what actually happens:

Suggested change
blank lines via a separate index map. Returns a flat dict of keys; the
"""Parse a tier env file (KEY=VALUE) into a flat dict. Comments and blank
lines are NOT retained here; the writer, `write_env_replace`, preserves
them by rewriting only the keys in its replacement map."""

📏 Severity: nitpick


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Roast 🔥

Verdict: 9 Issues Found | Recommendation: Address before merge

Overview

Severity Count
🚨 critical 1
⚠️ warning 1
💡 suggestion 2
🤏 nitpick 5
Issue Details (click to expand)
File Line Roast
pmoves/tools/jwt_rotate.py 451 🔥 critical — The 4 SUPABASE_* alias vars are silently filtered out of replacements (they get "" and drop out), so they survive a "rotation" still signed with the OLD secret. env.shared.example:184 shows SUPABASE_SERVICE_KEY is what Archon/cipher reads; the runbook (Phase 3 step 3) even claims all 7 vars are updated. A rotation tool that leaves half the locks on the old key — with a comment swearing it updates them.
pmoves/tools/tests/test_jwt_rotate.py 141 ⚠️ warning — test_rotate_takes_backup_before_writing never runs rotate; it exercises the backup subcommand instead. The exact P1.1 regression this PR exists to kill (write-before-backup) would pass this suite green. Plus lines 151-152 stage a tier fixture nothing ever reads.
pmoves/tools/jwt_rotate.py 307 💡 suggestion — Homegrown compose parser demands exactly 2-space service indent and env_file: entries at line end; anything else silently contributes zero consumers while the runbook calls the output "full coverage". PyYAML is already the house tool in pmoves/tools/.
pmoves/tools/jwt_rotate.py 55 💡 suggestion — Path.cwd() captured at import time: the tool rotates the JWT of whatever directory the interpreter woke up in, and test_enumerate_finds_canonical_supabase_consumers is only green when pytest runs from repo root via python -m pytest. Use Path(__file__).resolve().parents[2] as the fallback.
pmoves/tools/jwt_rotate.py 141 🤏 nitpick — read_env docstring claims "Preserves comments and blank lines via a separate index map" (it returns a flat dict; no map exists anywhere) and points at a replace_value function that doesn't exist. Misinformation wearing the authority of documentation.
pmoves/tools/jwt_rotate.py 467 🤏 nitpick — Rotate's summary line says "canonical Supabase + PMOVES" but the filter only keeps supabase-*/canonical entries — the PMOVES half of the label is aspirational.
pmoves/docs/AGENTS/jwt_rotate_v1_LEARNINGS.md 132 🤏 nitpick — O-1 says "26 ratchets across 6 classes," lists 5 classes, and the listed counts sum to 25 (actual: 26 tests across 5 classes; RunbookStructuralTests has 9, not 8). The arithmetic is as loose as the runbook it documents.
pmoves/docs/AGENTS/jwt_rotate_v1_LEARNINGS.md 151 🤏 nitpick — C:\Users\russe\... paths (worktree, temp dir, Python install) committed to the public repo (also in the AGNOTE RELEASE row, line 3398). Repo precedent in AGNOTE, and the fleet review already flagged it — still worth a scrub to <home>.
pmoves/tools/jwt_rotate.py 47 🤏 nitpick — Unused subprocess and Tuple imports; TIER_SUPABASE_DEFAULT and existing are computed and never read. Dead variables doing the solemn work of decoration.

Also on file (not duplicated here): the two CodeQL clear-text-logging findings at jwt_rotate.py:443 (dry-run prints full keys) and :461 (truncated-key echo).

Fix these issues in Kilo Cloud


🏆 Best part: The keygen mirror itself is honest work — test_anon_and_service_role_signed_with_same_secret catching a cross-signature regression is a genuinely thoughtful ratchet, and I resent how much I like it. The backup-before-write instinct and the rollback snapshot-of-current-state touch are also the right safety instincts — this PR clearly tried to fix v0's sins.

💀 Worst part: The rotation bug at line 451 — the tool's entire reason for existing is to move every consumer onto the new secret, and it leaves the four SUPABASE_* aliases (including the one Archon/cipher actually reads) holding the old one while the runbook promises otherwise. The critical test meant to pin it doesn't even run rotate. The P1 fix is a press release, not a property.

📊 Overall: Like a new lock company whose demo is rekeying your house — great hardware, careful backups, meticulous documentation of the process… and they only changed two of the five locks, but the brochure says all five.

Files Reviewed (5 files)
  • pmoves/tools/jwt_rotate.py - 7 issues
  • pmoves/tools/tests/test_jwt_rotate.py - 1 issue
  • pmoves/docs/RUNBOOK-5090-JWT-ROTATION.md - 0 issues (the runbook's claims are covered under the code findings they contradict)
  • pmoves/docs/AGENTS/jwt_rotate_v1_LEARNINGS.md - 2 issues
  • pmoves/docs/AGENTS/AGNOTE4482PHI.t1.md - 0 additional issues (username leak counted under LEARNINGS; content truncated by diff limits — remainder unchecked)

Reviewed by glm-5.3-flash · Input: 126.2K · Output: 26.6K · Cached: 1.5M

POWERFULMOVES added a commit that referenced this pull request Nov 21, 2026
…n a worktree

is_excluded() substring-matched the ABSOLUTE path for "worktrees". When the repo
itself lives in a git worktree - the layout this fleet actually uses, 210 of them
on the 4090 alone - every compose file answered True and the survey returned zero
consumers.

The failure is silent and load-bearing: `jwt_rotate rotate` builds its blast-radius
list from that survey. Run from a worktree it would have reported nothing to update
and left all 13 Supabase consumers on the old key while `verify` passed against the
one endpoint it did probe.

Decision is now made on the path RELATIVE to the survey root: a nested .worktrees/
directory is still skipped, but the survey root may itself be one. node_modules,
.git and the pmoves-supabase submodule stay excluded.

Three regression tests pin the behaviour (29 pass, was 26 passing / 1 failing).

Found while rebasing #3346 onto current main: the rebase was textually clean and
the suite still failed, because main had moved and nothing asserted the exclusion
logic against a worktree root.
@POWERFULMOVES
POWERFULMOVES force-pushed the fix/5090-jwt-rotation-runbook-rollback branch from f6d2edf to e99f184 Compare November 21, 2026 05:22
@github-actions

Copy link
Copy Markdown
Contributor

ORGSIM-MIRROR drift check (advisory, fail-soft)

vv3 / 8 files / VERIFIED 124 / DRIFTED 10 / UNDECIDED 29 / digest 2711c2ad83f5

Zero-LLM deterministic audit - unreachable = UNDECIDED, never dead - scripts/runbook_drift.py

@github-actions

Copy link
Copy Markdown
Contributor

ORGSIM-MIRROR drift check (advisory, fail-soft)

vv3 / 8 files / VERIFIED 124 / DRIFTED 10 / UNDECIDED 29 / digest 120e0fc5478c

Zero-LLM deterministic audit - unreachable = UNDECIDED, never dead - scripts/runbook_drift.py

POWERFULMOVES and others added 5 commits November 21, 2026 11:47
…env.tier-supabase before edit; enumerates 13 canonical Supabase consumers; cross-fork map; backup-first semantics)
…n a worktree

is_excluded() substring-matched the ABSOLUTE path for "worktrees". When the repo
itself lives in a git worktree - the layout this fleet actually uses, 210 of them
on the 4090 alone - every compose file answered True and the survey returned zero
consumers.

The failure is silent and load-bearing: `jwt_rotate rotate` builds its blast-radius
list from that survey. Run from a worktree it would have reported nothing to update
and left all 13 Supabase consumers on the old key while `verify` passed against the
one endpoint it did probe.

Decision is now made on the path RELATIVE to the survey root: a nested .worktrees/
directory is still skipped, but the survey root may itself be one. node_modules,
.git and the pmoves-supabase submodule stay excluded.

Three regression tests pin the behaviour (29 pass, was 26 passing / 1 failing).

Found while rebasing #3346 onto current main: the rebase was textually clean and
the suite still failed, because main had moved and nothing asserted the exclusion
logic against a worktree root.
… with the manifest?

secrets_manifest.yaml declares JWT_SECRET and SUPABASE_JWT_SECRET as aliases of one
canonical value. Measured on the 4090 on 2026-11-21, the runtime disagreed three ways:

    env.shared JWT_SECRET            58 chars
    env.shared SUPABASE_JWT_SECRET   55 chars
    live Kong container JWT_SECRET   64 chars

Supabase signs tokens with the container's secret. BoTZ (features/mcp_bridge/auth.py,
features/gateway/python-gateway/a2a/server.py) validates against SUPABASE_JWT_SECRET.
Nothing mints in BoTZ -- both are decoders -- so the mismatch rejects every token that
crosses, and it presents as a generic 401 with three plausible causes.

Adds:
  check_alias_integrity(env, container_secret)  -- pure, returns divergences
  read_container_jwt_secret(container)          -- docker exec printenv
  `jwt_rotate check-aliases [--env PATH] [--container NAME]`

Deliberately a COMMAND, not a test that reads the live machine. Against the real env it
reports:

    alias integrity: DIVERGENT
      - JWT_SECRET and SUPABASE_JWT_SECRET differ in the env file ...
      - JWT_SECRET does not match the live container JWT_SECRET (env len=58, container len=64)
      - SUPABASE_JWT_SECRET does not match the live container JWT_SECRET (env len=55, container len=64)

Seven fixture-based tests pin the logic (36 pass total). The live state stays a
diagnostic an operator runs, because a repo check that is red on the day it lands gets
muted -- which is how two Supabase secret alerts here ended up closed as false positives
while a live service_role key stayed in a public file.

Note for the rotation run: `rotate` rotates JWT_SECRET and re-mints anon + service_role,
so it RESOLVES this divergence. Run `check-aliases` before and after to confirm.
@POWERFULMOVES
POWERFULMOVES force-pushed the fix/5090-jwt-rotation-runbook-rollback branch from 2bd59d4 to da01243 Compare November 21, 2026 16:48
@github-actions

Copy link
Copy Markdown
Contributor

ORGSIM-MIRROR drift check (advisory, fail-soft)

vv3 / 8 files / VERIFIED 124 / DRIFTED 10 / UNDECIDED 29 / digest 3e93c67b1c91

Zero-LLM deterministic audit - unreachable = UNDECIDED, never dead - scripts/runbook_drift.py

…-text-logging)

CodeQL raised 2 high-severity alerts at jwt_rotate.py:543. Both are real disclosure,
not lint noise:

  * `rotate --dry-run` called `json.dumps(new, indent=2)` and printed the full
    contents of JWT_SECRET, ANON_KEY and SERVICE_ROLE_KEY to stdout - terminal
    scrollback, CI logs, and any transcript of the session.
  * the post-rotation summary printed each new key as `first8...last4`. A truncated
    credential is still a credential: 12 characters of a signing key is material.

Both now print only the key name and its length. An operator who needs the values
reads them from the file the non-dry-run path writes - which is where they have to
come from anyway, since the whole point of `rotate` is to write them there.

No test asserted on either output, so behaviour is otherwise unchanged: 36 pass.
@github-actions

Copy link
Copy Markdown
Contributor

ORGSIM-MIRROR drift check (advisory, fail-soft)

vv3 / 8 files / VERIFIED 124 / DRIFTED 10 / UNDECIDED 29 / digest f7e177903a0e

Zero-LLM deterministic audit - unreachable = UNDECIDED, never dead - scripts/runbook_drift.py

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

docs Documentation governance AGNOTE register / agent definitions / damage-control hooks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants