Add Redis backend for DCRCredentialStore#5195
Draft
tgrunnagle wants to merge 1 commit intodcr-3a_issue_5183from
Draft
Add Redis backend for DCRCredentialStore#5195tgrunnagle wants to merge 1 commit intodcr-3a_issue_5183from
tgrunnagle wants to merge 1 commit intodcr-3a_issue_5183from
Conversation
c0fed52 to
cc92472
Compare
4 tasks
cc92472 to
7aa7366
Compare
43ead51 to
b0bf320
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dcr-3a_issue_5183 #5195 +/- ##
=====================================================
+ Coverage 67.72% 67.80% +0.08%
=====================================================
Files 607 607
Lines 62090 62166 +76
=====================================================
+ Hits 42049 42151 +102
+ Misses 16878 16849 -29
- Partials 3163 3166 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
DRAFT - not ready for review
Summary
An authserver replica that registers itself as a DCR client against an upstream
authorization server currently keeps the resulting
(client_id, client_secret)in the in-process
MemoryStoragefrom sub-issue 1. Restarts and horizontalscale-outs lose the registration, forcing every replica to re-register on cold
start and breaking RFC 7592 management URLs. This PR adds the persistent half
of
DCRCredentialStoreso a Redis-Sentinel-backed authserver shares DCRcredentials across replicas and survives restarts.
KeyTypeDCRand a length-prefixedredisDCRKey(prefix, DCRKey)helperthat handles colons in
RedirectURIandIssuerwithout ambiguity, mirroringthe existing
redisProviderKeyshape.RedisStorage.StoreDCRCredentials/GetDCRCredentialswith JSONserialisation (acting as a defensive copy on read) and TTL semantics derived
from
client_secret_expires_at: zero means no Redis TTL (RFC 7591 "never"),a future expiry uses
time.Until(expiry), and an already-past expiry isbounded to a 1s eviction window so already-dead secrets do not linger.
_ DCRCredentialStore = (*RedisStorage)(nil)assertionalongside the existing interface checks at the bottom of
redis.go.round-trip, overwrite, validation, defensive copy via decode, all three TTL
branches,
ErrNotFoundsemantics, and concurrentStore/Get.//go:build integration)pinning the wire-level TTL contract against real Redis (
-1for never-expires)plus round-trip, distinct-keys, overwrite, and concurrent access — extending
redis_integration_test.gorather than introducing a second harness.Closes #5184
Type of change
Test plan
task test)task lint-fix)Ran the integration suite locally against a Docker-backed Redis Sentinel
cluster:
go test -tags=integration ./pkg/authserver/storage/...(TTL,round-trip, distinct-keys, overwrite, and concurrent-access cases all pass,
including the wire-level
TTL == -1assertion for never-expires rows).API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Changes
pkg/authserver/storage/redis_keys.goKeyTypeDCRconst andredisDCRKeylength-prefixed key helper.pkg/authserver/storage/redis.gostoredDCRCredentialswire type,StoreDCRCredentials/GetDCRCredentials,pastExpiryDCRTTLbound, andDCRCredentialStoreinterface assertion.pkg/authserver/storage/redis_test.goErrNotFound, concurrent access.pkg/authserver/storage/redis_integration_test.gowithIntegrationStorage: round-trip, distinct keys, overwrite, real-Redis TTL, concurrent access.Does this introduce a user-facing change?
No. This is internal storage plumbing behind the
DCRCredentialStoreinterfaceintroduced in sub-issue 1. Sub-issue 3 will wire
EmbeddedAuthServerto selectthe Redis backend via the existing
storage_type: redisconfig toggle.Special notes for reviewers
CRITICAL / HIGH / MEDIUM findings. One LOW finding remains: a stale docstring
on a unit-test helper in
redis_test.gothat still references thepre-
pastExpiryDCRTTLbehaviour. Happy to fix in this PR or as a follow-upif reviewers prefer to keep this PR focused on the storage primitive.
1srather than rejecting thewrite or storing long-lived. Rationale is in the
pastExpiryDCRTTLconstantdoc comment and the
StoreDCRCredentialsdocstring: caller's expirytimestamp still round-trips so a downstream reader can observe it and trigger
re-registration, while the row self-evicts almost immediately. Worth a look
during review to confirm the policy matches how sub-issue 3's resolver will
consume it.
miniredis(already ingo.modfrom the surroundingredis_test.gosuite). Integration tests use the existing testcontainersRedis Sentinel harness — both layers are required: the unit layer pins
in-process semantics for
task test, and the integration layer pins thewire contract (
TTLreturns-1for "no TTL") that miniredis cannotfaithfully reproduce.