Conversation
Signed-off-by: Manish Kumar <manish.kumar1@india.nec.com>
|
Hi @qiwzhang PTAL, I am not sure where to call addTokenResult and findTokenResult. |
| // The pubkey expiration time. | ||
| MonotonicTime expiration_time_; | ||
| // Jwt object for verified token. | ||
| std::unique_ptr<::google::jwt_verify::Jwt> jwt_; |
There was a problem hiding this comment.
The cache should be:
// Map a token to its result in the cache
absl::flat_hash_map<string, TokenResult> token_cache_;
Struct TokenResult {
// cache expire time, default cache for 5 minutes
MonotonicTime expiration_time_;
// verification status
Status status_;
}
In the jwt_authn config, in the JwtProvider config, add
// enable cache
bool enable_token_cache ;
// specify token cache during, default to 5 minutes
Duration token_cache_duration;
There was a problem hiding this comment.
should the cache have a (optionally) limited size to cap the amount of memory it can use?
There was a problem hiding this comment.
ahh nvm, i saw you commented on that.
There was a problem hiding this comment.
My proposed change only skip jwt::verify part with cache. We still need to parse jwt. I am not sure how fast the jwt parsing which is base64url_decode() of 3 sections.
Maybe we should.
Some other issuers we need to work on:
-
should a cache item be expired? Maybe not. But we need to handle "exp" and "nbf" correctly. Since we cache parsed jwt result, even for cache hit, we should always check its time constraint. For a "nbf" failed token, once time comes, it is valid again, we should verify it and cache the verify result.
-
cache size should not keep growing, otherwise we will have OOO. How, and when do we purge cache? Should we use LRU?
Signed-off-by: Manish Kumar <manish.kumar1@india.nec.com>
Signed-off-by: Manish Kumar <manish.kumar1@india.nec.com>
Signed-off-by: Manish Kumar <manish.kumar1@india.nec.com>
|
I think it is quite slow to parsing JWT token (split sections and base64_decode). I like jwt_cache to cache the parsing result too. So here is how it should work: We don't need "cache_duration" config. Usually, a token has "exp" field for 1 hour, it is removed from the cache when it is expired. For parsing failed token, it doesn't have expiration time, it will be purged by LRU. If a token doesn't have "exp", it never expire, it is OK to keep it in the cache until purged by LRU. So the data follow is: Hi @mk46 what do you think? |
|
SGTM, We should keep cache_duration in the config and will be evaluated like min(exp, cache_duration) if given otherwise exp. |
|
SG for "cache_duration" config. If specified, it can apply to parsing failed token too. |
|
I think we should leave it for a failed token while parsing. Since the probability of hitting the same failed token will be very less. Please LMK if you still want to keep it. |
|
OK, if we don't cache parsing failed tokens, the data flow could be much simpler. Thanks |
Signed-off-by: Manish Kumar <manish.kumar1@india.nec.com>
Signed-off-by: Manish Kumar <manish.kumar1@india.nec.com>
|
@htuch please reconfirm for api and your asks, and I'm happy to merge. |
|
@lizan Please take a look. Thanks! |
Signed-off-by: Manish Kumar <manish.kumar1@india.nec.com>
wrowe
left a comment
There was a problem hiding this comment.
Lizan's changes seem to be addressed, /lgtm deps
|
/lgtm deps @wrowe for repokitteh to pick up the deps approval it needs to be on it's own line |
All threads resolved, dismissing per @htuch on slack
* Add Jwt cache. * Added release docs. * Added unit test. Signed-off-by: Manish Kumar <manish.kumar1@india.nec.com> Co-authored-by: Wayne Zhang <qiwzhang@google.com>
Signed-off-by: Manish Kumar manish.kumar1@india.nec.com
Commit Message: Add Jwt cache.
Additional Description: Added Jwt cache, which makes Jwt verification faster.
Risk Level:
Testing: Format and unit
Docs Changes: done
Release Notes: done
Fixes #12644