fix: implement thread-safe token caching for self-managed oidc - #677
Conversation
Introduce a synchronized TokenCache to prevent concurrent OIDC login requests from colliding and overloading the Pinniped Supervisor or upstream LDAP server.
🛑 Legal Compliance Check FailedHi @steven-zou, thank you for your contribution! To merge this Pull Request, you must sign our CLA. Note: Even if you signed off your commits locally (using 1. Read the Document: Click here to read the CLA ⏳ Processing Schedule: |
|
I have read the CLA Document and I hereby sign the CLA for this and all future contributions. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #677 +/- ##
==========================================
- Coverage 25.23% 17.50% -7.74%
==========================================
Files 195 264 +69
Lines 16908 17698 +790
==========================================
- Hits 4267 3098 -1169
- Misses 12423 14402 +1979
+ Partials 218 198 -20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
tenthirtyam
left a comment
There was a problem hiding this comment.
LGTM, @steven-zou! TY!
Description:
TokenCachestruct withsync.Mutexininternal/authctx/client.goto manage the lifecycle of self-managed OIDC tokens.TanzuContextto hold a pointer toTokenCache(smTokenCache), ensuring thread-safe access across multiple concurrent goroutines.getUserAuthCtxHeadersto retrieve and refresh tokens through the cache, preventing duplicate authentication requests and race conditions when creating clusters in parallel.getSMUserAuthCtxininternal/authctx/selfmanaged.goto return the token's expiration time (expiry time.Time).refreshSMUserAuthCtxto explicitly update the cached token headers and expiry.Testing Done:
Run
terraform apply -auto-approve -parallelism=4to create 4 clusters in parallel.Race conditions error is reported:
Run the same command with fixed version, no error reported.
Metadata:
Jira: TMC-69727
Made with AI.