You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "yuqi1129 (via GitHub)" <gi...@apache.org> on 2026/06/03 08:25:09 UTC
[PR] [#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer [gravitino]
yuqi1129 opened a new pull request, #11404:
URL: https://github.com/apache/gravitino/pull/11404
### 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).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11404:
URL: https://github.com/apache/gravitino/pull/11404#discussion_r3353254197
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java:
##########
@@ -1033,36 +1034,18 @@ private List<Long> loadGroupRoles(
* or has no groups.
*/
private List<String> currentPrincipalGroupNames() {
- Principal principal = PrincipalUtils.getCurrentPrincipal();
- if (!(principal instanceof UserPrincipal)) {
- return new ArrayList<>();
- }
- List<UserGroup> groups = ((UserPrincipal) principal).getGroups();
- if (groups.isEmpty()) {
- return new ArrayList<>();
- }
- return groups.stream().map(UserGroup::getGroupname).collect(Collectors.toList());
+ return principalGroupNames(PrincipalUtils.getCurrentPrincipal());
}
- /**
- * Resolves GroupEntity objects for the current principal's groups, skipping any that are stale or
- * not found in the store. Used by owner checks that need full group entities instead of only
- * group names.
- */
- private List<GroupEntity> resolveCurrentUserGroups(String metalake, EntityStore entityStore) {
- Principal principal = PrincipalUtils.getCurrentPrincipal();
+ private List<String> principalGroupNames(Principal principal) {
if (!(principal instanceof UserPrincipal)) {
return new ArrayList<>();
}
List<UserGroup> groups = ((UserPrincipal) principal).getGroups();
if (groups.isEmpty()) {
return new ArrayList<>();
}
- List<NameIdentifier> groupIdents =
- groups.stream()
- .map(g -> NameIdentifierUtil.ofGroup(metalake, g.getGroupname()))
- .collect(Collectors.toList());
- return entityStore.batchGet(groupIdents, Entity.EntityType.GROUP, GroupEntity.class);
+ return groups.stream().map(UserGroup::getGroupname).collect(Collectors.toList());
Review Comment:
Shall we change to `getGroupName`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11404:
URL: https://github.com/apache/gravitino/pull/11404#discussion_r3353865851
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java:
##########
@@ -889,9 +890,9 @@ private boolean ownerMatchesUserOrGroups(
if (!Entity.EntityType.GROUP.name().equalsIgnoreCase(ownerInfo.getOwnerType())) {
return false;
}
- EntityStore entityStore = GravitinoEnv.getInstance().entityStore();
- for (GroupEntity groupEntity : resolveCurrentUserGroups(metalake, entityStore)) {
- if (Objects.equals(groupEntity.id(), ownerInfo.getOwnerId())) {
+ for (String groupName : principalGroupNames(principal)) {
+ Optional<GroupUpdatedAt> groupInfo = loadGroupInfo(metalake, groupName, requestContext);
Review Comment:
Do we need to batch get groups for the first operation?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #11404:
URL: https://github.com/apache/gravitino/pull/11404#discussion_r3353242878
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java:
##########
@@ -889,9 +890,9 @@ private boolean ownerMatchesUserOrGroups(
if (!Entity.EntityType.GROUP.name().equalsIgnoreCase(ownerInfo.getOwnerType())) {
return false;
}
- EntityStore entityStore = GravitinoEnv.getInstance().entityStore();
- for (GroupEntity groupEntity : resolveCurrentUserGroups(metalake, entityStore)) {
- if (Objects.equals(groupEntity.id(), ownerInfo.getOwnerId())) {
+ for (String groupname : principalGroupNames(principal)) {
Review Comment:
`groupName`,
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 merged PR #11404:
URL: https://github.com/apache/gravitino/pull/11404
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11404:
URL: https://github.com/apache/gravitino/pull/11404#issuecomment-4618166885
@roryqi
Can you help to review this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11404:
URL: https://github.com/apache/gravitino/pull/11404#discussion_r3353276085
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java:
##########
@@ -1033,36 +1034,18 @@ private List<Long> loadGroupRoles(
* or has no groups.
*/
private List<String> currentPrincipalGroupNames() {
- Principal principal = PrincipalUtils.getCurrentPrincipal();
- if (!(principal instanceof UserPrincipal)) {
- return new ArrayList<>();
- }
- List<UserGroup> groups = ((UserPrincipal) principal).getGroups();
- if (groups.isEmpty()) {
- return new ArrayList<>();
- }
- return groups.stream().map(UserGroup::getGroupname).collect(Collectors.toList());
+ return principalGroupNames(PrincipalUtils.getCurrentPrincipal());
}
- /**
- * Resolves GroupEntity objects for the current principal's groups, skipping any that are stale or
- * not found in the store. Used by owner checks that need full group entities instead of only
- * group names.
- */
- private List<GroupEntity> resolveCurrentUserGroups(String metalake, EntityStore entityStore) {
- Principal principal = PrincipalUtils.getCurrentPrincipal();
+ private List<String> principalGroupNames(Principal principal) {
if (!(principal instanceof UserPrincipal)) {
return new ArrayList<>();
}
List<UserGroup> groups = ((UserPrincipal) principal).getGroups();
if (groups.isEmpty()) {
return new ArrayList<>();
}
- List<NameIdentifier> groupIdents =
- groups.stream()
- .map(g -> NameIdentifierUtil.ofGroup(metalake, g.getGroupname()))
- .collect(Collectors.toList());
- return entityStore.batchGet(groupIdents, Entity.EntityType.GROUP, GroupEntity.class);
+ return groups.stream().map(UserGroup::getGroupname).collect(Collectors.toList());
Review Comment:
This is a previous naming problem introduced by others, and I will change it, by the way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11404:
URL: https://github.com/apache/gravitino/pull/11404#discussion_r3354148285
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java:
##########
@@ -889,9 +890,9 @@ private boolean ownerMatchesUserOrGroups(
if (!Entity.EntityType.GROUP.name().equalsIgnoreCase(ownerInfo.getOwnerType())) {
return false;
}
- EntityStore entityStore = GravitinoEnv.getInstance().entityStore();
- for (GroupEntity groupEntity : resolveCurrentUserGroups(metalake, entityStore)) {
- if (Objects.equals(groupEntity.id(), ownerInfo.getOwnerId())) {
+ for (String groupName : principalGroupNames(principal)) {
+ Optional<GroupUpdatedAt> groupInfo = loadGroupInfo(metalake, groupName, requestContext);
Review Comment:
We have used the method `prefetchUserAndGroupInfo` to batch fetch groups, so we can get the information from cache.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11404:
URL: https://github.com/apache/gravitino/pull/11404#discussion_r3348099651
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java:
##########
@@ -889,9 +890,9 @@ private boolean ownerMatchesUserOrGroups(
if (!Entity.EntityType.GROUP.name().equalsIgnoreCase(ownerInfo.getOwnerType())) {
return false;
}
- EntityStore entityStore = GravitinoEnv.getInstance().entityStore();
- for (GroupEntity groupEntity : resolveCurrentUserGroups(metalake, entityStore)) {
- if (Objects.equals(groupEntity.id(), ownerInfo.getOwnerId())) {
+ for (String groupname : currentPrincipalGroupNames()) {
+ Optional<GroupUpdatedAt> groupInfo = loadGroupInfo(metalake, groupname, requestContext);
+ if (groupInfo.isPresent() && groupInfo.get().getGroupId() == ownerInfo.getOwnerId()) {
return true;
}
Review Comment:
Fixed. GROUP owner checks now derive group names from the provided `principal` via `principalGroupNames(principal)`, while the existing current-principal helper remains for the normal authorization flow. Added `testGroupOwnerCheckUsesProvidedPrincipalGroups` to cover the explicit-principal case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer [gravitino]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11404:
URL: https://github.com/apache/gravitino/pull/11404#issuecomment-4611217515
<!-- coverage-report -->
### Code Coverage Report
|Overall Project|66.82% **`+0.1%`**|:green_circle:|
|:-|:-|:-:|
|Files changed|83.5%|:green_circle:|
<br>
|Module|Coverage||
|:-|:-|:-:|
|aliyun|1.72%|:red_circle:|
|api|46.82%|:green_circle:|
|authorization-common|85.96%|:green_circle:|
|aws|3.66%|:red_circle:|
|azure|2.47%|:red_circle:|
|catalog-common|10.04%|:red_circle:|
|catalog-fileset|80.33%|:green_circle:|
|catalog-glue|66.08%|:green_circle:|
|catalog-hive|79.55%|:green_circle:|
|catalog-jdbc-clickhouse|80.02%|:green_circle:|
|catalog-jdbc-common|45.31%|:green_circle:|
|catalog-jdbc-doris|80.28%|:green_circle:|
|catalog-jdbc-hologres|54.03%|:green_circle:|
|catalog-jdbc-mysql|79.23%|:green_circle:|
|catalog-jdbc-oceanbase|78.38%|:green_circle:|
|catalog-jdbc-postgresql|82.29%|:green_circle:|
|catalog-jdbc-starrocks|78.51%|:green_circle:|
|catalog-kafka|77.01%|:green_circle:|
|catalog-lakehouse-generic|44.89%|:green_circle:|
|catalog-lakehouse-hudi|79.1%|:green_circle:|
|catalog-lakehouse-iceberg|85.66%|:green_circle:|
|catalog-lakehouse-paimon|79.29%|:green_circle:|
|catalog-model|77.72%|:green_circle:|
|cli|44.51%|:green_circle:|
|client-java|77.91%|:green_circle:|
|common|49.99%|:green_circle:|
|core|82.49%|:green_circle:|
|filesystem-hadoop3|76.97%|:green_circle:|
|flink|0.0%|:red_circle:|
|flink-common|41.2%|:green_circle:|
|flink-runtime|0.0%|:red_circle:|
|gcp|14.12%|:red_circle:|
|hadoop-common|10.39%|:red_circle:|
|hive-metastore-common|53.26%|:green_circle:|
|iceberg-common|56.54%|:green_circle:|
|iceberg-rest-server|72.84%|:green_circle:|
|idp-basic|85.99%|:green_circle:|
|integration-test-common|0.0%|:red_circle:|
|jobs|66.17%|:green_circle:|
|lance-common|20.83%|:red_circle:|
|lance-rest-server|60.27%|:green_circle:|
|lineage|53.02%|:green_circle:|
|optimizer|82.95%|:green_circle:|
|optimizer-api|21.95%|:red_circle:|
|server|85.73%|:green_circle:|
|server-common|73.05% **`+2.71%`**|:green_circle:|
|spark|32.79%|:red_circle:|
|spark-common|39.75%|:red_circle:|
|trino-connector|39.44%|:red_circle:|
<details>
<summary>Files</summary>
|Module|File|Coverage||
|:-|:-|:-|:-:|
|server-common|[JcasbinAuthorizer.java](https://github.com/yuqi1129/gravitino/blob/520015fe2bb62b33f1149908073f5cf85fbcbfff/server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java)|83.5%|:green_circle:|
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer [gravitino]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #11404:
URL: https://github.com/apache/gravitino/pull/11404#discussion_r3347025592
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java:
##########
@@ -889,9 +890,9 @@ private boolean ownerMatchesUserOrGroups(
if (!Entity.EntityType.GROUP.name().equalsIgnoreCase(ownerInfo.getOwnerType())) {
return false;
}
- EntityStore entityStore = GravitinoEnv.getInstance().entityStore();
- for (GroupEntity groupEntity : resolveCurrentUserGroups(metalake, entityStore)) {
- if (Objects.equals(groupEntity.id(), ownerInfo.getOwnerId())) {
+ for (String groupname : currentPrincipalGroupNames()) {
+ Optional<GroupUpdatedAt> groupInfo = loadGroupInfo(metalake, groupname, requestContext);
+ if (groupInfo.isPresent() && groupInfo.get().getGroupId() == ownerInfo.getOwnerId()) {
return true;
}
Review Comment:
ownerMatchesUserOrGroups() uses the passed-in Principal for USER owner checks, but for GROUP owner checks it ignores that parameter and instead reads PrincipalUtils.getCurrentPrincipal() via currentPrincipalGroupNames(). If isOwner/authorize is ever invoked with an explicit principal that differs from the thread-local current principal, GROUP ownership checks can return incorrect results. Use the provided `principal` parameter to derive group names instead of consulting global state.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer [gravitino]
Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11404:
URL: https://github.com/apache/gravitino/pull/11404#discussion_r3355539430
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java:
##########
@@ -889,9 +890,9 @@ private boolean ownerMatchesUserOrGroups(
if (!Entity.EntityType.GROUP.name().equalsIgnoreCase(ownerInfo.getOwnerType())) {
return false;
}
- EntityStore entityStore = GravitinoEnv.getInstance().entityStore();
- for (GroupEntity groupEntity : resolveCurrentUserGroups(metalake, entityStore)) {
- if (Objects.equals(groupEntity.id(), ownerInfo.getOwnerId())) {
+ for (String groupName : principalGroupNames(principal)) {
+ Optional<GroupUpdatedAt> groupInfo = loadGroupInfo(metalake, groupName, requestContext);
Review Comment:
Ok for me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org