Repository navigation
ak-agent: fix token exchange cache key and cached expiry - #1677
Merged
BeryJu merged 1 commit intoOct 12, 2026
Merged
Conversation
The exchange cache was written under ["token-cache", audience] but read under a key that also included scopes and an actor-token hash, so scoped or actor exchanges never hit the cache, and a plain request could be served a token minted with scopes or an actor. Read and write now share one key. Cache hits also returned the token's original expires_in rather than the time left, so callers computing now + expires_in (e.g. the kubectl ExecCredential) overstated expiry.
BeryJu
approved these changes
Oct 12, 2026
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.
Two bugs in the agent's
cached_token_exchange.The cache was read under a key that includes the requested scopes and a hash of the actor token, but always written under
["token-cache", audience]. So scoped and actor exchanges never got a cache hit, and a plain request for an audience could be handed a token that was minted for another caller's scopes or actor. Reads and writes now go through oneexchange_cache_keyhelper.A cache hit also returned the token's original
expires_ininstead of the time it has left. Anything that computesnow + expires_inoverstated the expiry; the kubectlExecCredentialfromak auth kubectldoes this, so kubectl could keep using a token past its real expiry. Hits now return the remaining seconds.Unit tests cover the cache key and the remaining-time calculation.