Apache9 commented on code in PR #8880:
URL: https://github.com/apache/hbase/pull/8880#discussion_r4586142667
##########
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:
We can add a check in the beginning, if the table name is hbase:acl, we just
delegate the request to getGlobalPermissions, or we can throw an exception that
you should not call this method with hbase:acl table, just call
getGlobalPermission directly...
For hbase:acl table, I think its permission should be hard coded as only
superuser can READ/WRITE.
--
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]