Repository navigation
feat(auth): token registry 4/4 — refuse unregistered tokens and unknown subjects - #1406
Draft
manas-narra wants to merge 1 commit into
Draft
manas-narra wants to merge 1 commit into
manas-narra wants to merge 1 commit into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. Comment |
manas-narra
force-pushed
the
feat/token-registry-4-enforce
branch
from
October 29, 2026 02:58
e6078da to
ba75fdc
Compare
…wn subjects Builds on 3/4. Ends the observe period of 2/4: - a long-lived RBAC token the registry doesn't hold is refused (401) instead of being registered as 'backfilled' and let through; the find-or-register path is deleted. A not-found answer isn't cached, so a token minted or rotated on another pod is found on its next use - a token whose user or merchant no longer exists is refused (401) instead of logged and allowed - unchanged: revoke, rotate, deactivation, the login cut-off, last_seen, 503 when the registry can't be read; short-lived tokens need no row Merge only after 2/4 has run in prod and no new 'backfilled' rows have appeared for 7+ days.
manas-narra
force-pushed
the
feat/token-registry-4-enforce
branch
from
October 29, 2026 13:55
ba75fdc to
9ba1d4e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1405 (3/4) → #1404 (2/4) → #1403 (1/4). Base:
feat/token-registry-3-rotate.Why
2/4 runs the registry in observe mode. A valid long-lived token the registry has never seen is registered as
backfilledand let through, which is how the tokens actually in use get found. 3/4 does the same for a token whose user or merchant no longer exists: logged, but allowed.Once the observe period has found every token in use, letting unknown tokens through is the gap itself. This PR closes it.
The stack
What this PR does
1. An unregistered long-lived token is refused (401).
authenticatelooks the token up by hash. No row means 401, logged with the subject, username and jti, and nothing is written.find_or_register_seen_tokenand the insert'sON CONFLICT DO NOTHINGoption) is deleted.2. A token whose subject no longer exists is refused (401). This applies to a deleted user, or
merchant:<id>for a deleted merchant. Before this PR it was logged and allowed.What doesn't change
source = backfilled). The vocabulary keeps the word.Why "the log backfill" doesn't create rows
The
RBAC token verified for user: … jti: …log line holds the username and scopes, not the token, so no hash can be computed from it. Rows come only from the mint (1/4), from observe mode (2/4) and from rotation (3/4).The 30 days of logs, joined to the load-balancer logs for IP and path, are the inventory for the reconcile. They tell us who uses tokens, so that a token used less often than the observe window (a monthly job, say) is found and rotated before this merges. Otherwise this PR would refuse it.
Rollback
There's no runtime switch. A switch to stop refusing unknown tokens is the kind of bypass the repo's "fail closed, no bypass flags" rule forbids. Rollback is reverting this commit and redeploying. 2/4's observe mode comes back as it was.
Tests
Updated in
tests/breeze_buddy/test_token_registry_observe.pyandtest_token_registry_rotate.py. The 142 token tests across the 5 files pass.ON CONFLICTis left anywhere.Mutation check: 7/7 killed.
On a throwaway Postgres 17 with the network blocked, through the real routes: 9/9, 0 rows left.
backfilledrow written.Gates
pyteston the 5 token test filespytest tests/crmpytest tests(full)pyrefly checkscripts/check_migrations.pyscripts/check_crm_boundaries.pyCI runs only
tests/crm, so the token tests above are run by hand.