Skip to content

[#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer#11404

Open
yuqi1129 wants to merge 1 commit into
apache:mainfrom
yuqi1129:fix/11403-group-owner-check-cache
Open

[#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer#11404
yuqi1129 wants to merge 1 commit into
apache:mainfrom
yuqi1129:fix/11403-group-owner-check-cache

Conversation

@yuqi1129
Copy link
Copy Markdown
Contributor

@yuqi1129 yuqi1129 commented Jun 3, 2026

What changes were proposed in this pull request?

Replace resolveCurrentUserGroups(metalake, entityStore) in ownerMatchesUserOrGroups() with currentPrincipalGroupNames() + loadGroupInfo(). The new path routes through requestContext.groupInfoCache (per-request dedup) before falling back to a lightweight group_meta query via GroupMetaMapper#getGroupUpdatedAt, and removes the need to load full GroupEntity objects. The now-unused resolveCurrentUserGroups() method and its GroupEntity import are removed.

Why are the changes needed?

The old path bypassed all caches and issued an entityStore.batchGet(GROUP) DB call on every GROUP owner check. In hasSetOwnerPermission, which walks the full parent chain calling isOwner in a loop, this could fire multiple times per request when the owner is a group. The fix ensures group identity is resolved through the same version-validated cache path as all other identity lookups in the authorizer.

Fix: #11403

Does this PR introduce any user-facing change?

No.

How was this patch tested?

  • Updated testAuthorizeByGroupOwner to mock groupMetaMapper.getGroupUpdatedAt instead of entityStore.batchGet(GROUP), and added a verify assertion that entityStore.batchGet(GROUP) is never called.
  • Added testGroupOwnerCheckDeduplicatesGroupInfoWithinRequest which calls isOwner twice within the same AuthorizationRequestContext and asserts that groupMetaMapper.getGroupUpdatedAt is invoked exactly once (per-request cache dedup).

Copilot AI review requested due to automatic review settings June 3, 2026 08:25
@yuqi1129 yuqi1129 self-assigned this Jun 3, 2026
@yuqi1129 yuqi1129 added the branch-1.3 Automatically cherry-pick commit to branch-1.3 label Jun 3, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates JcasbinAuthorizer to resolve GROUP ownership checks through the per-request group info cache (via groupMetaMapper.getGroupUpdatedAt) rather than loading full GroupEntity objects from EntityStore, reducing redundant DB work during repeated owner checks within a request.

Changes:

  • Updated GROUP owner matching to use currentPrincipalGroupNames() + loadGroupInfo() (per-request dedup) instead of entityStore.batchGet(..., GROUP, GroupEntity.class).
  • Removed the now-unused resolveCurrentUserGroups() helper and its GroupEntity usage in the authorizer.
  • Updated and added unit tests to assert the new query path and per-request dedup behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java Switches GROUP owner resolution to use per-request cached group meta lookups instead of loading full group entities.
server-common/src/test/java/org/apache/gravitino/server/authorization/jcasbin/TestJcasbinAuthorizer.java Updates existing owner-by-group test expectations and adds a test ensuring group info lookups are deduplicated within a single request context.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

Code Coverage Report

Overall Project 66.75% +0.1% 🟢
Files changed 83.5% 🟢

Module Coverage
aliyun 1.72% 🔴
api 46.82% 🟢
authorization-common 85.96% 🟢
aws 3.66% 🔴
azure 2.47% 🔴
catalog-common 10.04% 🔴
catalog-fileset 80.33% 🟢
catalog-glue 66.08% 🟢
catalog-hive 79.33% 🟢
catalog-jdbc-clickhouse 80.02% 🟢
catalog-jdbc-common 45.31% 🟢
catalog-jdbc-doris 80.28% 🟢
catalog-jdbc-hologres 54.03% 🟢
catalog-jdbc-mysql 79.23% 🟢
catalog-jdbc-oceanbase 78.38% 🟢
catalog-jdbc-postgresql 82.29% 🟢
catalog-jdbc-starrocks 78.51% 🟢
catalog-kafka 77.01% 🟢
catalog-lakehouse-generic 44.89% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 85.74% 🟢
catalog-lakehouse-paimon 79.29% 🟢
catalog-model 77.72% 🟢
cli 44.51% 🟢
client-java 77.91% 🟢
common 49.99% 🟢
core 82.48% 🟢
filesystem-hadoop3 76.97% 🟢
flink 0.0% 🔴
flink-common 41.2% 🟢
flink-runtime 0.0% 🔴
gcp 14.12% 🔴
hadoop-common 10.39% 🔴
hive-metastore-common 53.26% 🟢
iceberg-common 56.54% 🟢
iceberg-rest-server 72.76% 🟢
idp-basic 85.99% 🟢
integration-test-common 0.0% 🔴
jobs 66.17% 🟢
lance-common 20.83% 🔴
lance-rest-server 60.27% 🟢
lineage 53.02% 🟢
optimizer 82.87% 🟢
optimizer-api 21.95% 🔴
server 85.73% 🟢
server-common 73.05% +2.71% 🟢
spark 32.79% 🔴
spark-common 37.99% 🔴
trino-connector 39.44% 🔴
Files
Module File Coverage
server-common JcasbinAuthorizer.java 83.5% 🟢

…ner check in JcasbinAuthorizer

Replace resolveCurrentUserGroups(entityStore) in ownerMatchesUserOrGroups() with
currentPrincipalGroupNames() + loadGroupInfo(), routing group-id lookups through
requestContext.groupInfoCache (per-request dedup) instead of issuing a direct
entityStore.batchGet(GROUP) on every GROUP owner check. Remove the now-unused
resolveCurrentUserGroups() method and its GroupEntity import.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@yuqi1129 yuqi1129 force-pushed the fix/11403-group-owner-check-cache branch from 520015f to e2bc035 Compare June 3, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch-1.3 Automatically cherry-pick commit to branch-1.3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement] JcasbinAuthorizer group owner check bypasses per-request cache causing redundant DB queries

2 participants