Class PermissionStorage
AccessController.
Access control lists are stored in an "internal" metadata table named _acl_. Each table's
permission grants are stored as a separate row, keyed by the table name. KeyValues for
permissions assignments are stored in one of the formats:
Key Desc -------- -------- user table level permissions for a user [R=read, W=write] group table level permissions for a group user,family column family level permissions for a user group,family column family level permissions for a group user,family,qualifier column qualifier level permissions for a user group,family,qualifier column qualifier level permissions for a group
All values are encoded as byte arrays containing the codes from the org.apache.hadoop.hbase.security.access.TablePermission.Action enum.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte[]static final charDelimiter to separate user, column family, and qualifier in _acl_ table info: column keysstatic final byte[]static final StringColumn family used to store ACL grantsstatic final TableNameInternal storage table for access control listsstatic final byteKV tag to store per cell access control listsprivate static final intprivate static final org.slf4j.Loggerstatic final charprivate static final intprivate static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddUserPermission(Connection conn, UserPermission userPerm, boolean mergeExistingPermissions) Stores a new user permission grant in the access control lists table.private static voiddelete(UserPermission userPerm, Table aclTable) static byte[]fromNamespaceEntry(byte[] namespace) static StringfromNamespaceEntry(String namespace) private static byte[]getActionCodes(Permission perm) static List<Permission>getCellPermissionsForUser(User user, ExtendedCell cell) static List<UserPermission>private static StringgetNamespaceFromEntryName(byte[] entryName) static List<UserPermission>getNamespacePermissions(Connection conn, String namespace) (package private) static org.apache.hbase.thirdparty.com.google.common.collect.ListMultimap<String,UserPermission> getPermissions(Connection conn, byte[] entryName) Reads user permission assignments stored in thel:column family of the first table row in_acl_.static List<UserPermission>getTablePermissions(Connection conn, TableName tableName) Get all the permission entries for this table.private static UserPermissiongetUserPermission(Table aclTable, UserPermission userPerm) (package private) static booleanisAclRegion(Region region) Returnstrueif the given region is part of the_acl_metadata table.(package private) static booleanisAclTable(TableDescriptor desc) Returnstrueif the given table is_acl_metadata table.static booleanisGlobalEntry(byte[] entryName) static booleanisNamespaceEntry(byte[] entryName) static booleanisNamespaceEntry(String entryName) static booleanisTableEntry(byte[] entryName) (package private) static Map<byte[],org.apache.hbase.thirdparty.com.google.common.collect.ListMultimap<String, UserPermission>> loadAll(Connection conn) Load all permissions from the region server holding_acl_, primarily intended for testing purposes.(package private) static Map<byte[],org.apache.hbase.thirdparty.com.google.common.collect.ListMultimap<String, UserPermission>> Loads all of the permission grants stored in a region of the_acl_table.private static StringparseTableEntry(Permission.Builder builder, byte[] qual) Return the username for this table entry, and add family/qualifier to the givenbuilderif available.private static UserPermissionparseUserPermission(byte[] entryName, byte[] qual, byte[] actionCodes) private static voidput(Table aclTable, UserPermission userPerm) static org.apache.hbase.thirdparty.com.google.common.collect.ListMultimap<String,Permission> readPermissions(byte[] data, org.apache.hadoop.conf.Configuration conf) static org.apache.hbase.thirdparty.com.google.common.collect.ListMultimap<String,UserPermission> readUserPermission(byte[] data, org.apache.hadoop.conf.Configuration conf) private static List<Permission>readWritableUserPermission(DataInput in, org.apache.hadoop.conf.Configuration conf) (package private) static voidremoveNamespacePermissions(Connection conn, String namespace) Remove specified namespace from the acl table.(package private) static voidremoveTableColumnFamiliesPermissions(Connection conn, TableName tableName, Collection<byte[]> columns) Remove permissions of the specified column families of the given table from the acl table.(package private) static voidremoveTablePermissions(Connection conn, TableName tableName) Remove specified table from the _acl_ table.static voidremoveUserPermission(Connection conn, UserPermission userPerm) Removes a previously granted permission from the stored access control lists.static byte[]toNamespaceEntry(byte[] namespace) static byte[]toNamespaceEntry(String namespace) private static byte[]toTableEntryName(TableName tableName) private static byte[]userPermissionKey(UserPermission permission) Build qualifier key from user permission: username username,family username,family,qualifierprivate static byte[]userPermissionRowKey(Permission permission) private static voidvalidateUser(String user) private static voidvalidateUserOrGroupName(String name, Function<String, String> formatter) private static IOExceptionwarnAndThrow(String msg) static byte[]writePermissionsAsBytes(org.apache.hbase.thirdparty.com.google.common.collect.ListMultimap<String, UserPermission> perms, org.apache.hadoop.conf.Configuration conf) Writes a set of permissions asWritableinstances and returns the resulting byte array.
-
Field Details
-
ACL_TABLE_NAME
Internal storage table for access control lists -
ACL_GLOBAL_NAME
-
ACL_LIST_FAMILY_STR
Column family used to store ACL grants- See Also:
-
ACL_LIST_FAMILY
-
ACL_TAG_TYPE
KV tag to store per cell access control lists- See Also:
-
NAMESPACE_PREFIX
- See Also:
-
ACL_KEY_DELIMITER
Delimiter to separate user, column family, and qualifier in _acl_ table info: column keys- See Also:
-
LOG
-
LIST_CODE
- See Also:
-
WRITABLE_CODE
- See Also:
-
WRITABLE_NOT_ENCODED
- See Also:
-
-
Constructor Details
-
PermissionStorage
private PermissionStorage()
-
-
Method Details
-
toTableEntryName
-
getNamespaceFromEntryName
-
parseTableEntry
Return the username for this table entry, and add family/qualifier to the givenbuilderif available. -
parseUserPermission
private static UserPermission parseUserPermission(byte[] entryName, byte[] qual, byte[] actionCodes) -
getUserPermission
private static UserPermission getUserPermission(Table aclTable, UserPermission userPerm) throws IOException - Throws:
IOException
-
getActionCodes
-
put
- Throws:
IOException
-
delete
- Throws:
IOException
-
warnAndThrow
- Throws:
IOException
-
validateUserOrGroupName
private static void validateUserOrGroupName(String name, Function<String, String> formatter) throws IOException- Throws:
IOException
-
validateUser
- Throws:
IOException
-
addUserPermission
public static void addUserPermission(Connection conn, UserPermission userPerm, boolean mergeExistingPermissions) throws IOException Stores a new user permission grant in the access control lists table.- Parameters:
conn- connection to hbase clusteruserPerm- the details of the permission to be grantedaclTable- acl table instance. It is closed upon method return.- Throws:
IOException- in the case of an error accessing the metadata table, or theuserPermis invalid, i.e, has an invalid user/group name or an empty actions.
-
removeUserPermission
public static void removeUserPermission(Connection conn, UserPermission userPerm) throws IOException Removes a previously granted permission from the stored access control lists.The
TablePermissionbeing removed must exactly match what is stored -- no wildcard matching is attempted. Ie, if user "bob" has been granted "READ" access to the "data" table, but only to column family plus qualifier "info:colA", then trying to call this method with only user "bob" and the table name "data" (but without specifying the column qualifier "info:colA") will have no effect.Passing an
userPermwith empty actions means revoke all the permissions.- Parameters:
conn- connection to hbase clusteruserPerm- the details of the permission to be revoked- Throws:
IOException- in the case of an error accessing the metadata table, or theuserPermis invalid, i.e, has an invalid user/group name.
-
removeTablePermissions
Remove specified table from the _acl_ table.- Throws:
IOException
-
removeNamespacePermissions
Remove specified namespace from the acl table.- Throws:
IOException
-
removeTableColumnFamiliesPermissions
static void removeTableColumnFamiliesPermissions(Connection conn, TableName tableName, Collection<byte[]> columns) throws IOException Remove permissions of the specified column families of the given table from the acl table.- Throws:
IOException
-
userPermissionRowKey
-
userPermissionKey
Build qualifier key from user permission: username username,family username,family,qualifier -
isAclRegion
Returnstrueif the given region is part of the_acl_metadata table. -
isAclTable
Returnstrueif the given table is_acl_metadata table. -
loadAll
static Map<byte[],org.apache.hbase.thirdparty.com.google.common.collect.ListMultimap<String, loadAllUserPermission>> (Region aclRegion) throws IOException Loads all of the permission grants stored in a region of the_acl_table.- Parameters:
aclRegion- the acl region- Returns:
- a map of the permissions for this table.
- Throws:
IOException- if an error occurs
-
loadAll
static Map<byte[],org.apache.hbase.thirdparty.com.google.common.collect.ListMultimap<String, loadAllUserPermission>> (Connection conn) throws IOException Load all permissions from the region server holding_acl_, primarily intended for testing purposes.- Throws:
IOException
-
getTablePermissions
public static List<UserPermission> getTablePermissions(Connection conn, TableName tableName) throws IOException Get all the permission entries for this table.- Throws:
IOException
-
getNamespacePermissions
public static List<UserPermission> getNamespacePermissions(Connection conn, String namespace) throws IOException - Throws:
IOException
-
getGlobalPermissions
- Throws:
IOException
-
isGlobalEntry
-
isNamespaceEntry
-
isNamespaceEntry
-
isTableEntry
-
toNamespaceEntry
-
fromNamespaceEntry
-
toNamespaceEntry
-
fromNamespaceEntry
-
getCellPermissionsForUser
public static List<Permission> getCellPermissionsForUser(User user, ExtendedCell cell) throws IOException - Throws:
IOException
-
getPermissions
static org.apache.hbase.thirdparty.com.google.common.collect.ListMultimap<String,UserPermission> getPermissions(Connection conn, byte[] entryName) throws IOException Reads user permission assignments stored in thel:column family of the first table row in_acl_.See
class documentationfor the key structure used for storage.- Throws:
IOException
-
writePermissionsAsBytes
public static byte[] writePermissionsAsBytes(org.apache.hbase.thirdparty.com.google.common.collect.ListMultimap<String, UserPermission> perms, org.apache.hadoop.conf.Configuration conf) Writes a set of permissions asWritableinstances and returns the resulting byte array. Writes a set of permission [user: table permission] -
readWritableUserPermission
private static List<Permission> readWritableUserPermission(DataInput in, org.apache.hadoop.conf.Configuration conf) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
readUserPermission
public static org.apache.hbase.thirdparty.com.google.common.collect.ListMultimap<String,UserPermission> readUserPermission(byte[] data, org.apache.hadoop.conf.Configuration conf) throws DeserializationException - Throws:
DeserializationException
-
readPermissions
public static org.apache.hbase.thirdparty.com.google.common.collect.ListMultimap<String,Permission> readPermissions(byte[] data, org.apache.hadoop.conf.Configuration conf) throws DeserializationException - Throws:
DeserializationException
-