Copilot commented on code in PR #8928:
URL: https://github.com/apache/hbase/pull/8928#discussion_r4717690851


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/SnapshotScannerHDFSAclController.java:
##########
@@ -427,7 +430,8 @@ public void 
postRevoke(ObserverContext<MasterCoprocessorEnvironment> c,
             TablePermission tPerm = (TablePermission) 
userPermission.getPermission();
             if (needHandleTableHdfsAcl(tPerm)) {
               TableName tableName = tPerm.getTableName();
-              UserPermission userTablePerm = getUserTablePermission(conn, 
userName, tableName);
+              UserPermission userTablePerm =
+                PermissionStorage.getUserTablePermission(conn, tableName, 
userName);

Review Comment:
   These exact lookups make snapshot access depend on a group ACL that 
`SnapshotScannerHDFSAclHelper.aclEntry` records as `@team`, rather than the 
actual HDFS group `team`. Revoking a member's direct READ, or granting them 
only WRITE, then leaves them without snapshot access despite the group's READ. 
Use `AuthUtil.getGroupName(name)` for HDFS ACL names and repair existing group 
ACLs; the global and namespace callbacks are also affected.



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/SnapshotScannerHDFSAclController.java:
##########
@@ -333,7 +333,7 @@ public void 
postGrant(ObserverContext<MasterCoprocessorEnvironment> c,
       String userName = userPermission.getUser();
       switch (userPermission.getAccessScope()) {
         case GLOBAL:
-          UserPermission perm = getUserGlobalPermission(conn, userName);
+          UserPermission perm = 
PermissionStorage.getUserGlobalPermission(conn, userName);

Review Comment:
   Add controller regression tests for mixed user/group grants with a real 
group member. Cover a group WRITE/member READ grant and a group READ/member 
READ revoke at global, namespace, and table scopes, asserting that the member's 
named HDFS ACL and sync marker follow the direct permission. After revoking 
only the member's READ, also verify that the group's ACL and the member's 
group-based snapshot access remain intact.



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/PermissionStorage.java:
##########
@@ -610,6 +611,53 @@ public static List<UserPermission> 
getGlobalPermissions(Connection conn) throws
     return userPerms;
   }
 
+  private static UserPermission getUserPermission(Connection conn, byte[] 
entryName, String user,
+    Supplier<Permission.Builder> builder) throws IOException {
+    Get get = new Get(entryName);
+    byte[] qual = Bytes.toBytes(user);
+    get.addColumn(ACL_LIST_FAMILY, qual);
+    try (Table aclTable = conn.getTable(ACL_TABLE_NAME)) {
+      Result result = aclTable.get(get);
+      if (result.isEmpty()) {
+        return null;
+      }
+      byte[] actionCodes = result.getValue(ACL_LIST_FAMILY, qual);
+      return new UserPermission(user, 
builder.get().withActionCodes(actionCodes).build());
+    }
+  }
+
+  /**
+   * Get the permission for this {@code user} on the given {@code tableName}.
+   * @param user a user name or a group name
+   * @return the user permission or null if not exists
+   */
+  public static UserPermission getUserTablePermission(Connection conn, 
TableName tableName,
+    String user) throws IOException {
+    return getUserPermission(conn, toTableEntryName(tableName), user,
+      () -> Permission.newBuilder(tableName));

Review Comment:
   Passing `ACL_TABLE_NAME` reads the global-permission row but returns a 
`TablePermission`, mislabeling a stored global grant as a table grant. Match 
`getTablePermissions` by delegating this reserved table name to 
`getUserGlobalPermission`, preserving the stored scope.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to