一:HBASE权限user
HBASE的user底层使用的还是hadoop的user;
构造connection类:
public static Connection createConnection(Configuration conf, User user) throws IOException {
return createConnection(conf, null, user);
}
其中可以user参数
进入HBASE的user类:有一个构造方法:
public static User create(UserGroupInformation ugi) {
if (ugi == null) {
return null;
}
return new SecureHadoopUser(ugi);
}
可以看到使用子类SecureHadoopUser
SecureHadoopUser的构造方法参数UserGroupInformation中看到:
public static UserGroupInformation createRemoteUser(String user, AuthMethod authMethod) {
if (user == null || user.isEmpty()) {
throw new IllegalArgumentException("Null user");
}
Subject subject = new Subject();
subject.getPrincipals().add(new User(user));
UserGroupInformation result = new UserGroupInformation(subject);
result.setAuthenticationMethod(authMethod);
return result;
其中封装user的则是hadoop.security的user类。
二:acl数据更新zookeeper及cache
(初始化的时候会执将所有表的权限信息写到对应table的node节点上)
在HBASE执行put以及delete操作触发updateAcl更新操作:
/**
* Writes all table ACLs for the tables in the given Map up into ZooKeeper
* znodes. This is called to synchronize ACL changes following {@code _acl_}
* table updates.
*/
void updateACL(RegionCoprocessorEnvironment e,final Map<byte[], List<Cell>> familyMap)
获取权限监控的znode
this.authManager.getZKPermissionWatcher();
读取acl表的所有权限:
AccessControlLists.getPermissions(conf, entry, t);
并且会解析数据成指定格式,写入zookeeper,并且转成字节;
解析核心代码:
int idx = username.indexOf(ACL_KEY_DELIMITER);
byte[] permFamily = null;
byte[] permQualifier = null;
//因为在acl表中,列名columname的组成是user+权限table的不为空family+不为空的列名,且以逗号分隔的形式。
if (idx > 0 && idx < username.length() - 1) {
String remainder = username.substring(idx + 1);
username = username.substring(0, idx);
idx = remainder.indexOf(ACL_KEY_DELIMITER);
if (idx > 0 && idx < remainder.length() - 1) {
permFamily = Bytes.toBytes(remainder.substring(0, idx));
permQualifier = Bytes.toBytes(remainder.substring(idx + 1));
} else {
permFamily = Bytes.toBytes(remainder);
}
}
return new Pair<String, TablePermission>(username, new TablePermission(TableName.valueOf(entryName), permFamily, permQualifier, value));
则是最终写入zookeeper的格式数据
序列化写入数据:
byte[] serialized = AccessControlLists.writePermissionsAsBytes(perms, conf);
zkw.writeToZookeeper(entry, serialized);
zookeeper上node子znode数据变更,会执行更新cache操作;
相应的执行refreshAuthManager操作,包括
authManager.refreshNamespaceCacheFromWritable(AccessControlLists.fromNamespaceEntry(entry), nodeData);
authManager.refreshTableCacheFromWritable(TableName.valueOf(entry), nodeData);
然后重新将新权限信息放进cache中,提供HBASE权限的检查check操作。
当然,再删除的时候,数据信息也会执行相应的delete操作。
三:cache
在TableAuthManager权限检查类中,三种cache,
1.PermissionCache<Permission> globalCache
2.ConcurrentSkipListMap<TableName, PermissionCache<TablePermission>> tableCache
3.private ConcurrentSkipListMap<String, PermissionCache<TablePermission>> nsCache
分别在处理超级用户superuser,namespace及table的用户权限信息