fix: use OIDC refresh tokens to renew expired sessions (#27041, #12189)#27777
Open
ris-tlp wants to merge 3 commits intoargoproj:masterfrom
Open
fix: use OIDC refresh tokens to renew expired sessions (#27041, #12189)#27777ris-tlp wants to merge 3 commits intoargoproj:masterfrom
ris-tlp wants to merge 3 commits intoargoproj:masterfrom
Conversation
✅ Preview Environment deployed on Bunnyshell
See: Environment Details | Pipeline Logs Available commands (reply to this comment):
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #27777 +/- ##
==========================================
+ Coverage 63.61% 63.98% +0.36%
==========================================
Files 417 421 +4
Lines 57125 57782 +657
==========================================
+ Hits 36338 36969 +631
+ Misses 17394 17333 -61
- Partials 3393 3480 +87 ☔ View full report in Codecov by Sentry. |
65c0602 to
9bffa5f
Compare
…ration Signed-off-by: ris-tlp <omarkhantlp@gmail.com>
…ired Signed-off-by: ris-tlp <omarkhantlp@gmail.com>
9bffa5f to
ffeae1b
Compare
Signed-off-by: ris-tlp <omarkhantlp@gmail.com>
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.
Issues Addressed
Bug Summary
Currently, the OIDC refresh flow in ArgoCD is not able to refresh sessions due to two separate bugs:
util/oidc/oidc.gois tied to the ID token's lifetime. When the ID token has expired, the refresh token is evicted at the exact moment the refresh flow would need it. The refresh token was not being given a chance to be used. This scenario happens even if the user is active in the UI.server/server.go getClaimsreturnsUnauthenticatedand exits before the OIDC refresh logic can run. This scenario happens when a user has successfully logged in but has not carried out any actions in the UI until after the token has expired. The session doesn't get refreshed because the refresh is on demand, i.e., whenever a user does something on the UI.Fix Summary
UserSessionDuration: The OAuth2 token wrapper containing the refresh token is now cached for theUserSessionDurationrather thanGetTokenExpiration(claims)/time.Until(token.Expiry)inutil/oidc/oidc.go.CheckAndRefreshTokenbefore returningUnauthenticatedand exiting out early inserver/server.go.Reproducing the bugs with Keycloak
~/keycloak-realm.json{ "realm": "argocd", "enabled": true, "accessTokenLifespan": 120, "ssoSessionIdleTimeout": 86400, "ssoSessionMaxLifespan": 86400, "clients": [{ "clientId": "argocd", "enabled": true, "publicClient": false, "secret": "argocd-client-secret", "redirectUris": ["http://localhost:8080/auth/callback", "http://localhost:4000/auth/callback"], "webOrigins": ["+"], "standardFlowEnabled": true, "directAccessGrantsEnabled": true, "protocol": "openid-connect" }], "users": [{ "username": "test", "enabled": true, "email": "test@example.com", "emailVerified": true, "credentials": [{"type": "password", "value": "password", "temporary": false}] }] }argocd-cmRun ArgoCD locally with
make start-local ARGOCD_GPG_ENABLED=false ARGOCD_E2E_DISABLE_AUTH=falseReproduce bugs
test / passwordserver/server.goapi-server | {"level":"info","msg":"Performing authorization_code flow login:...in ArgoCD andDEBUG [org.keycloak.events] ... type="LOGIN"in KeycloakOnce the fix has been made, refresh logs can been seen in both ArgoCD
api-server | {"level":"info","msg":"refreshed token for subject: ...and KeycloakDEBUG [org.keycloak.events] ... type="REFRESH_TOKEN"Checklist: