jenkinsci / oic-auth-plugin

A Jenkins plugin which lets you login to Jenkins using your own, self-hosted or public openid connect server.
https://plugins.jenkins.io/oic-auth
MIT License
71 stars 88 forks source link

Fix redirect loop when oic credentials have expired but jenkins session is still valid #357

Closed mikecirioli closed 1 month ago

mikecirioli commented 1 month ago

to reproduce:

  1. configure a jenkins instance to auth using the plugin, do not enable refresh tokens
  2. assume your oic crentials lifetime is 120s (at least that is the case for my test provider)
  3. assume default skew allowance of 60s
  4. login to your jenkins instance
  5. notice that after only 60s, your OIC credentials have now expired!
  6. any subsequent attempt to access the instance results in a redirect loop between the provider and jenkins

Although the proposed PR fixes the issue AFAICT, I am not 100% confident it is the correct fix. This issue first appears in release 4.297.vcddb_d8a_e4694, but i have not been able to identify exactly what i believe changed to cause this behavior. My theory is that because the jenkins web session is still valid, it allows the request, which is then flagged as invalid because the OIC credentials have expired, kicking the whole loop off again. Hopefully you can confirm or deny this @krezovic

I also believe that the clock skew was mistakenly being subtracted from the credentials "expires in X seconds" calculation - my understanding was the clock skew should add an additional "buffer" to the lifetime of the credentials in order to accommodate slight variances in different clocks.

Testing done

Lots of manual testing.... I've also fixed 2 tests that i believe cover the changes made in this PR:

Submitter checklist

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 71.44%. Comparing base (b7205f1) to head (ad6b064). Report is 3 commits behind head on master.

Files Patch % Lines
...va/org/jenkinsci/plugins/oic/OicSecurityRealm.java 0.00% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #357 +/- ## ============================================ - Coverage 72.02% 71.44% -0.58% + Complexity 234 232 -2 ============================================ Files 11 11 Lines 990 991 +1 Branches 142 142 ============================================ - Hits 713 708 -5 - Misses 199 205 +6 Partials 78 78 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mikecirioli commented 1 month ago

@michael-doubez i realize that i did not add a label to this PR before it was merged, and i don't have permissions to trigger a release - is that something you can do?

michael-doubez commented 1 month ago

@mikecirioli my mistake - it didn't check