Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cache behavior with TTL #968

Merged
merged 3 commits into from
May 23, 2022
Merged

Conversation

flusflas
Copy link
Contributor

This pull requests fixes a possible issue in the behavior of the oauth2 introspection authenticator cache with TTL.

The problem is any token successfully authenticated is pushed to the cache, even if it the token was already cached. When using cache TTL, this makes possible to keep a token in the cache by forcing the token authentication with a period less than the TTL.

This fix doesn't introduce breaking changes.

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security. vulnerability, I
    confirm that I got green light (please contact
    [email protected]) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

Further Comments

Although this PR fixes the problem above, maybe I'm missing details of the cache implementation or whether stopping re-caching already cached tokens is a desired behavior (e.g. my fix would probably break a LRU cache), so please check that this does not adversely affect the behavior of the cache.

@flusflas flusflas requested a review from aeneasr as a code owner May 22, 2022 10:02
@aeneasr aeneasr force-pushed the feature/fix-cache-ttl branch from fb3539c to fee70df Compare May 23, 2022 13:47
flusflas added 3 commits May 23, 2022 22:13
This test will fail since everytime Authenticate() succeeds the token
is cached, even if it was already cached. This behavior makes it
possible to keep a token in cache if it is authenticated in a period
less than the TTL.

Signed-off-by: flusflas <[email protected]>
When configuring an AuthenticatorOAuth2Introspection, the token cache
is cleared if a cache TTL is set.

Signed-off-by: flusflas <[email protected]>
This will prevent keeping a cached token alive if it is authenticated
with a period less than tha cache TTL.

Signed-off-by: flusflas <[email protected]>
@aeneasr aeneasr force-pushed the feature/fix-cache-ttl branch from fee70df to 95f0cb2 Compare May 23, 2022 20:13
@codecov
Copy link

codecov bot commented May 23, 2022

Codecov Report

Merging #968 (d2cee29) into master (988c3b7) will increase coverage by 0.03%.
The diff coverage is 100.00%.

❗ Current head d2cee29 differs from pull request most recent head 95f0cb2. Consider uploading reports for the commit 95f0cb2 to get more accurate results

@@            Coverage Diff             @@
##           master     #968      +/-   ##
==========================================
+ Coverage   65.98%   66.01%   +0.03%     
==========================================
  Files         106      106              
  Lines        4718     4723       +5     
==========================================
+ Hits         3113     3118       +5     
  Misses       1324     1324              
  Partials      281      281              
Impacted Files Coverage Δ
...peline/authn/authenticator_oauth2_introspection.go 82.58% <100.00%> (+0.50%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 988c3b7...95f0cb2. Read the comment docs.

@aeneasr aeneasr merged commit c4836f5 into ory:master May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants