liuxiaocs7 commented on code in PR #8880:
URL: https://github.com/apache/hbase/pull/8880#discussion_r4585357480
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/PermissionStorage.java:
##########
@@ -442,279 +464,232 @@ static Map<byte[], ListMultimap<String,
UserPermission>> loadAll(Configuration c
Scan scan = new Scan();
scan.addFamily(ACL_LIST_FAMILY);
- ResultScanner scanner = null;
// TODO: Pass in a Connection rather than create one each time.
- try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table table = connection.getTable(ACL_TABLE_NAME)) {
- scanner = table.getScanner(scan);
- try {
- for (Result row : scanner) {
- ListMultimap<String, UserPermission> resultPerms =
- parsePermissions(row.getRow(), row, null, null, null, false);
- allPerms.put(row.getRow(), resultPerms);
- }
- } finally {
- if (scanner != null) {
- scanner.close();
- }
+ try (Table table = conn.getTable(ACL_TABLE_NAME);
+ ResultScanner scanner = table.getScanner(scan)) {
+ while (true) {
+ Result result = scanner.next();
+ if (result == null) {
+ break;
}
+ byte[] entryName = result.getRow();
+ ListMultimap<String, UserPermission> perms =
ArrayListMultimap.create();
+ result.getFamilyMap(ACL_LIST_FAMILY).forEach((qual, actionCodes) -> {
+ UserPermission userPerm = parseUserPermission(entryName, qual,
actionCodes);
+ if (userPerm != null) {
+ perms.put(userPerm.getUser(), userPerm);
+ } else {
+ // Malformed/empty ACL cell; skip to avoid NPE and continue
scanning.
+ LOG.warn("Skipping malformed ACL entry for row={} qualifier={}",
+ Bytes.toStringBinary(entryName), Bytes.toStringBinary(qual));
+ }
+ });
+ allPerms.put(entryName, perms);
}
}
return allPerms;
}
- public static ListMultimap<String, UserPermission>
getTablePermissions(Configuration conf,
- TableName tableName) throws IOException {
- return getTablePermissions(conf, tableName, null);
- }
-
- public static ListMultimap<String, UserPermission>
getTablePermissions(Configuration conf,
- TableName tableName, Table t) throws IOException {
- return getPermissions(conf, tableName != null ? tableName.getName() :
null, t, null, null, null,
- false);
- }
-
- public static ListMultimap<String, UserPermission>
getNamespacePermissions(Configuration conf,
- String namespace) throws IOException {
- return getPermissions(conf, Bytes.toBytes(toNamespaceEntry(namespace)),
null, null, null, null,
- false);
- }
-
- public static ListMultimap<String, UserPermission>
getGlobalPermissions(Configuration conf)
- throws IOException {
- return getPermissions(conf, null, null, null, null, null, false);
- }
-
/**
- * Reads user permission assignments stored in the <code>l:</code> column
family of the first
- * table row in <code>_acl_</code>.
- * <p>
- * See {@link PermissionStorage class documentation} for the key structure
used for storage.
- * </p>
+ * Get all the permission entries for this table.
*/
- static ListMultimap<String, UserPermission> getPermissions(Configuration
conf, byte[] entryName,
- Table t, byte[] cf, byte[] cq, String user, boolean hasFilterUser) throws
IOException {
- if (entryName == null) {
- entryName = ACL_GLOBAL_NAME;
- }
- // for normal user tables, we just read the table row from _acl_
- ListMultimap<String, UserPermission> perms = ArrayListMultimap.create();
- Get get = new Get(entryName);
- get.addFamily(ACL_LIST_FAMILY);
- Result row = null;
- if (t == null) {
- try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table table = connection.getTable(ACL_TABLE_NAME)) {
- row = table.get(get);
- }
+ public static List<UserPermission> getTablePermissions(Connection conn,
TableName tableName)
+ throws IOException {
+ byte[] entryName = toTableEntryName(tableName);
+ Get get = new Get(entryName).addFamily(ACL_LIST_FAMILY);
+ List<UserPermission> userPerms = new ArrayList<>();
+ try (Table aclTable = conn.getTable(ACL_TABLE_NAME)) {
+ Result result = aclTable.get(get);
+ if (!result.isEmpty()) {
+ result.getFamilyMap(ACL_LIST_FAMILY).forEach((qual, actionCodes) -> {
+ if (ArrayUtils.isEmpty(actionCodes)) {
+ // Malformed/empty ACL cell; skip to avoid NPE
+ LOG.warn("Skipping malformed ACL entry for row={} qualifier={}",
+ Bytes.toStringBinary(entryName), Bytes.toStringBinary(qual));
+ return;
+ }
+ Permission.Builder builder =
+ Permission.newBuilder(tableName).withActionCodes(actionCodes);
Review Comment:
The hbase:acl row stores global grants, but this constructs a
TablePermission, reporting the wrong scope in permission queries. Could we
reuse parseUserPermission to preserve the global-row handling?
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/SnapshotScannerHDFSAclController.java:
##########
@@ -493,24 +492,24 @@ private void removeUserTableHdfsAcl(Table aclTable,
String userName, TableName t
}
}
- private UserPermission getUserGlobalPermission(Configuration conf, String
userName)
+ private UserPermission getUserGlobalPermission(Connection conn, String
userName)
throws IOException {
- List<UserPermission> permissions =
PermissionStorage.getUserPermissions(conf,
- PermissionStorage.ACL_GLOBAL_NAME, null, null, userName, true);
+ List<UserPermission> permissions =
+ PermissionUtils.filter(PermissionStorage.getGlobalPermissions(conn),
userName);
return permissions.size() > 0 ? permissions.get(0) : null;
Review Comment:
If a user has direct READ and belongs to a group with only WRITE, the new
ordering puts the group grant first. Selecting that entry can incorrectly
remove the user’s HDFS ACL. Could we match the exact principal for grant/revoke
synchronization?
--
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]