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

Add cache specialized for access tokens #870

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

matheuscscp
Copy link
Member

Introduce a cache that is specialized for access tokens. This is a thin abstraction on top of the LRU cache adding requirements that are important for managing the lifetime of tokens:

  • We consider tokens expired after 80% of their lifetime. This is what kubelet does for rotating ServiceAccount tokens inside pods (ref).
  • We need a pessimistic approach for considering tokens expired. With this in mind we store two time points: the usual time.Now().Add(duration), which has a monotonic clock, and also a Unix time point wihtout a monotonic clock. If either report t.Before(time.Now()) == true, the token is considered expired. This is important because Flux may be running in local machines, which are often put to sleep. When they come back up, the monotonic clock will resume from where it stopped, i.e. for the monotonic clock the machine sleep time is considered a "pause". This would cause tokens to be kept beyond their actual expiration, so we use both clocks to ensure we don't return expired tokens on TokenCache.Get().

@matheuscscp matheuscscp force-pushed the token-cache branch 2 times, most recently from dc0e388 to 2089a72 Compare February 23, 2025 18:22
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