Add live Redis-backed admin key propagation across replicas#527
Add live Redis-backed admin key propagation across replicas#527Iweisc wants to merge 7 commits intolabring:mainfrom
Conversation
|
I have some cool safety features in my mind that requires the ADMIN_KEY to hot-reload WITHOUT the deployments restarting. |
|
One of those features could be like a fail-safe that triggers when certain actions are invoked, and you can rotate the ADMIN_KEY on the fly without any disruptions. The feature opens up a door to wide range of features. Oh and it has some nice performance boosts too. |
|
You can even count admin/internal key matches with near-zero hot-path cost because the match logic is precomputed. |
|
Here are some cool use cases and features this opens up the door to, while i may not open follow up PRs with these features, i plan to follow up on some:
I believe, since we are pre-computing tokenVariants, adminKeyState, internalTokenState, etc etc. I believe with the speed enhancements, it'll allow for EVEN more features, that were previously impractical before because of the speed. |
|
Thank you for your contribution; please sign the CLA. |
|
@zijiren233 doesn't seem to be working for me, but i'll try again. |
|
A commit has two contributors; sertdev has not signed the CLA, preventing CI execution. |
No. So, the thing is that "sertdev" is actually me, i am assuming the bot is detecting two contributors because i set my git config to the name sertdev instead of it matching the github name.....i can't really sign as sertdev. |
|
You may have used an incorrect commit email/username. Please sign the CLA correctly and resolve the conflicts. |
|
@zijiren233 yup, umm how do i sign the CLA as sertdev? |
|
you can use |
|
@zijiren233 Ow, then i'd have to force push but i am assuming that is allowed. |
a3088a6 to
34692b0
Compare
|
fixed the issue. |
|
Great! You’ve succeeded. Next, you need to resolve the conflicts. |
|
@zijiren233 on it. |
|
@zijiren233 fixed |
c1e6993 to
b74a8f0
Compare
|
@zijiren233 fixed in 35c872b. Moved the admin-key cache sync/watch out of Redis initialization and into the task lifecycle. Startup now runs the first admin-key cache init synchronously after Redis init, before the background task starts; Redis init itself only sets up the client. I kept the Redis client setup in common and scoped the task change to admin-key cache state. |
|
@zijiren233 fixed |
There was a problem hiding this comment.
Pull request overview
Adds a Redis-backed, live-updating admin key cache so running instances can pick up admin key rotations without restart while keeping request auth fully in-memory.
Changes:
- Introduces
task.AdminKeyCacheTask+InitAdminKeyCacheto bootstrap/load the effective admin key from Redis (SETNX + polling). - Updates auth middleware and config to support dynamic “effective” admin key matching (including Bearer/sk- variants) without Redis reads per request.
- Adds unit tests for admin key cache behavior and token normalization helpers; adds
miniredistest dependency.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| core/task/admin_key_cache.go | Implements Redis-backed admin key bootstrap + periodic sync into in-memory config state. |
| core/task/admin_key_cache_test.go | Adds tests using miniredis to validate bootstrap/load/update behavior and key stability. |
| core/common/config/env.go | Adds atomic-backed admin/internal token state, effective admin key selection, and variant matching helpers. |
| core/middleware/auth.go | Switches auth checks to MatchEffectiveAdminKey/MatchInternalToken and centralizes token extraction/normalization. |
| core/middleware/mcp.go | Aligns MCP auth to new matching + normalization helpers. |
| core/middleware/auth_test.go | Tests request token precedence, normalization, and effective admin key behavior. |
| core/startup.go | Initializes admin key cache during service initialization and updates admin key generation to use getters/setters. |
| core/main.go | Starts the admin key cache polling task when Redis is enabled. |
| core/go.mod / core/go.sum | Adds github.com/alicebob/miniredis/v2 (and indirect deps) for Redis-backed tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@zijiren233 fixed. |
ADMIN_KEYis bootstrapped into a scoped Redis slot withSETNX500ms/apiauth continues using in-memory state, so request handling does not hit Redis