Repository navigation
Add Redis storage for exchange grants - #6981
Merged
Merged
Conversation
Implement ExchangeGrantStorage on RedisStorage so exchange grants survive restarts and are shared by replicas. Each grant is a HASH at <prefix>xgrant:<signature>; a top-level grant also writes a replay marker for its subject token's (issuer, jti). Creation is one Lua script that runs every check before any write, so concurrent creates for one jti admit exactly one and a failure leaves nothing behind. Revoke is a single HSETNX of rev_ms that keeps the first revocation time and leaves the TTLs alone. All time decisions and TTLs come from the store clock. Co-authored-by: Mecatl <[email protected]>
jhrozek
requested review from
ChrisJBurns,
JAORMX,
amirejaz,
rdimitrov and
tgrunnagle
as code owners
October 28, 2026 20:41
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6981 +/- ##
==========================================
+ Coverage 80.24% 80.25% +0.01%
==========================================
Files 847 848 +1
Lines 86097 86232 +135
==========================================
+ Hits 69085 69203 +118
- Misses 17007 17024 +17
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ChrisJBurns
reviewed
Oct 29, 2026
ChrisJBurns
left a comment
Collaborator
There was a problem hiding this comment.
See the inline comments.
ChrisJBurns
previously approved these changes
Oct 29, 2026
ChrisJBurns
left a comment
Collaborator
There was a problem hiding this comment.
Small nit. approving
The shared contract now requires a create whose ExpiresAt is already past to fail without writing anything. Redis accepted such a grant with a 1 ms record TTL and still wrote the replay marker, so a corrected retry with the same subject token got ErrJTIKnown. Check ExpiresAt against the store clock before the script runs, as the memory backend does, and drop the TTL floor that only existed for this case. Also correct the CreateExchangeGrant contract. It said a failed call writes nothing, which a networked backend cannot promise: if the connection drops after Redis ran the script, the record and marker exist while the caller sees an error. Document that, and that the replay marker is only as durable as the Redis replication setup. Co-authored-by: Mecatl <[email protected]>
jhrozek
force-pushed
the
exchange-storage-redis
branch
from
October 29, 2026 14:01
b84f273 to
b70f3a8
Compare
ChrisJBurns
approved these changes
Oct 29, 2026
This was referenced Oct 29, 2026
3 of 10 tasks
1 task
3 of 10 tasks
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.
Summary
Token-exchange refresh tokens need a server-side grant record, and the Redis backend had no implementation of
ExchangeGrantStorage. Without it, a deployment that runs the auth server on Redis cannot keep exchange grants across restarts or share them between replicas. This adds the Redis backend, so the memory backend is no longer the only one.{prefix}xgrant:{signature}. The immutable record is JSON indata; revocation time is a separaterev_msfield, so a revoke is one write.jti) before any write, so a failed create leaves nothing behind and concurrent creates for onejtiadmit exactly one. A top-level grant also writes a replay marker for the subject access token's(issuer, jti).rev_mswithHSETNXinside a small script. It keeps the first revocation time and leaves both TTLs alone.ExpiresAthas already passed is refused before the script runs, as the memory backend does, so it cannot burn the subject token'sjti.docs/arch/11-auth-server-storage.mdanddocs/redis-storage.mddocument the keys, TTLs and persistence expectations.Part of #6895
Type of change
Test plan
go test -race ./pkg/authserver/storage/passes. This covers the newredis_exchange_grant_test.go(against miniredis) and the shared storage contract tests. I ran the package directly, not the wholetask testsuite.task test-e2e)task lint-fix)TestIntegration_ExchangeGrantConcurrentCreateOneJTIstarts 20 concurrent creates for onejtiand requires exactly one to win. It is inredis_integration_test.goand I did not run it against a real Redis in this PR.Changes
pkg/authserver/storage/redis_exchange_grant.goExchangeGrantStorageonRedisStorage: create and revoke scripts, get, TTL helperpkg/authserver/storage/redis_keys.goKeyTypeExchangeGrantpkg/authserver/storage/redis.gopkg/authserver/storage/redis_exchange_grant_test.gopkg/authserver/storage/redis_integration_test.godocs/arch/11-auth-server-storage.md,docs/redis-storage.mdDoes this introduce a user-facing change?
No behavior changes until a caller starts using
ExchangeGrantStorage. Operators who later run exchange refresh tokens on Redis should enable AOF: without it, or after a failover to a replica that missed the latest writes, a lost replay marker allows a second exchange of the same access token, and a lost revocation makes a grant usable again until it expires. This is documented indocs/redis-storage.md.Special notes for reviewers
EXISTS); Go only skips the marker once its window has already passed.ExchangeGrantMarkerMargin(1 minute) absorbs clock skew, which can only lengthen the window.ExpiresAt. The gap is about 1 ms plus network latency around expiry, and either outcome is safe.