[#11781] fix(idp-basic): Cache Basic auth group names by username#11788
Draft
lasdf1234 wants to merge 2 commits into
Draft
[#11781] fix(idp-basic): Cache Basic auth group names by username#11788lasdf1234 wants to merge 2 commits into
lasdf1234 wants to merge 2 commits into
Conversation
Add IdpUserGroupsCache to avoid loading group membership from the relational store on every authenticated request while still verifying passwords each time. Co-authored-by: Cursor <cursoragent@cursor.com>
…er removal Co-authored-by: Cursor <cursoragent@cursor.com>
Collaborator
Author
|
@yuqi1129 Could you help me to review this code?THX~ |
Code Coverage Report
Files
|
Contributor
|
We need to consider the cache consistency in a multiple-node deployment. |
Contributor
|
We should avoid using cache if possible. We should optimize the SQL query to select complete information once. |
Collaborator
Author
SQL has been optimized to handle data with the least amount of I/O operations. |
Collaborator
Author
|
After conducting tests, I found that the bottleneck was not in the database query. This PR has been temporarily converted to a draft PR. |
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.
What changes were proposed in this pull request?
Add
IdpUserGroupsCacheto cache built-in IdP group names keyed by username during Basic authentication, reducing relational store lookups on repeated requests. Password verification still usesgetIdpUserByUsernameon every request; only group membership is cached. Invalidate cached group names when users are removed, group membership changes, or a group is force-deleted. Add server configsgravitino.authenticator.basic.groupsCacheTtlSecs(default 3600) andgravitino.authenticator.basic.groupsCacheSize(default 10000), documented in the built-in IDP guide.Why are the changes needed?
Basic authentication previously loaded full user metadata (including group membership) from the relational store on every request. Group authorization adds extra DB work compared to user-only checks. This change caches group names per username while preserving per-request password verification, as discussed in #11781.
Fix: #11781
Does this PR introduce any user-facing change?
Yes, two new optional configuration keys:
gravitino.authenticator.basic.groupsCacheTtlSecs— TTL in seconds for the per-username group names cache (default 3600)gravitino.authenticator.basic.groupsCacheSize— maximum number of cached usernames (default 10000)No existing keys or default authentication behavior change.
How was this patch tested?
./gradlew :plugins:idp-basic:test -PskipITsTestIdpUserGroupsCache— cache hit/miss and invalidationTestIdpUserGroupManager— auth with groups, wrong/old password, cache invalidation on membership change and user removalTestBasicAuthenticatorandTestBasicAuthenticationIntegration