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


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/PermissionStorage.java:
##########
@@ -285,53 +284,37 @@ static void removeNamespacePermissions(Configuration 
conf, String namespace, Tab
     }
   }
 
-  static private void removeTablePermissions(TableName tableName, byte[] 
column, Table table,
-    boolean closeTable) throws IOException {
-    Scan scan = new Scan();
-    scan.addFamily(ACL_LIST_FAMILY);
-
-    String columnName = Bytes.toString(column);
-    scan.setFilter(new QualifierFilter(CompareOperator.EQUAL,
-      new RegexStringComparator(String.format("(%s%s%s)|(%s%s)$", 
ACL_KEY_DELIMITER, columnName,
-        ACL_KEY_DELIMITER, ACL_KEY_DELIMITER, columnName))));
-
-    Set<byte[]> qualifierSet = new TreeSet<>(Bytes.BYTES_COMPARATOR);
-    ResultScanner scanner = null;
+  /**
+   * Remove permissions of the specified column families of the given table 
from the acl table.
+   */
+  static void removeTableColumnFamiliesPermissions(Configuration conf, 
TableName tableName,
+    Collection<byte[]> columns, Table t) throws IOException {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Removing permissions of removed columns {} from table {}",
+        
columns.stream().map(Bytes::toStringBinary).collect(Collectors.joining(", ")), 
tableName);
+    }
     try {
-      scanner = table.getScanner(scan);
-      for (Result res : scanner) {
-        for (byte[] q : res.getFamilyMap(ACL_LIST_FAMILY).navigableKeySet()) {
-          qualifierSet.add(q);
+      Set<byte[]> families = new TreeSet<>(Bytes.BYTES_COMPARATOR);
+      families.addAll(columns);
+      ListMultimap<String, UserPermission> perms = getTablePermissions(conf, 
tableName, t);
+      Delete d = new Delete(tableName.getName());
+      boolean found = false;
+      for (UserPermission perm : perms.values()) {
+        Permission permission = perm.getPermission();
+        if (permission instanceof TablePermission) {
+          byte[] family = ((TablePermission) permission).getFamily();
+          if (family != null && families.contains(family)) {
+            d.addColumns(ACL_LIST_FAMILY, userPermissionKey(perm));
+            found = true;
+          }
         }
       }

Review Comment:
   Reconstructing the ACL key from a parsed permission leaves stale grants when 
a column qualifier contains invalid UTF-8 bytes: `parsePermissionRecord` 
decodes the key as text, so a stored `cf1,\xFF` suffix becomes 
`cf1,\xEF\xBF\xBD` and the delete targets a different cell. Read the original 
ACL cells and delete their exact qualifier bytes after matching the family, and 
add a regression case with a non-UTF-8 qualifier.



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java:
##########
@@ -924,6 +924,27 @@ public Void run() throws Exception {
         return null;
       }
     });
+    // Remove the permissions of the column families dropped from the table. 
Otherwise, if a
+    // column family with the same name is added back later, the stale 
permissions would be
+    // effective again.

Review Comment:
   If the master fails before this RPC-side `postModifyTable` cleanup, or the 
ACL operation throws an IOException, the schema change can finish with stale 
family permissions still stored. Move the cleanup to 
`postCompletedModifyTableAction`, where the persisted table procedure can 
replay and retry it using the old and new descriptors, so recreating the family 
does not restore those grants.



-- 
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