hbase simple权限二

本文涉及的产品
云原生网关 MSE Higress,422元/月
注册配置 MSE Nacos/ZooKeeper,118元/月
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
简介: 一:HBASE权限userHBASE的user底层使用的还是hadoop的user;构造connection类:public static Connection createConnection(Configuration conf, User u...

一: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的用户权限信息

相关实践学习
云数据库HBase版使用教程
&nbsp; 相关的阿里云产品:云数据库 HBase 版 面向大数据领域的一站式NoSQL服务,100%兼容开源HBase并深度扩展,支持海量数据下的实时存储、高并发吞吐、轻SQL分析、全文检索、时序时空查询等能力,是风控、推荐、广告、物联网、车联网、Feeds流、数据大屏等场景首选数据库,是为淘宝、支付宝、菜鸟等众多阿里核心业务提供关键支撑的数据库。 了解产品详情:&nbsp;https://cn.aliyun.com/product/hbase &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
分布式数据库 Hbase 网络架构
hbase simple权限一
一:shell执行: grant授权: 查看commands目录下grant.rb文件: security_admin.grant(user, permissions, table_name, family, qualifier) 进入security.
1660 0
|
2月前
|
Java Shell 分布式数据库
【大数据技术Hadoop+Spark】HBase数据模型、Shell操作、Java API示例程序讲解(附源码 超详细)
【大数据技术Hadoop+Spark】HBase数据模型、Shell操作、Java API示例程序讲解(附源码 超详细)
111 0
|
11月前
|
SQL 分布式计算 Hadoop
Hadoop集群hbase的安装
Hadoop集群hbase的安装
163 0
|
28天前
|
存储 分布式计算 Hadoop
Hadoop节点文件存储HBase设计目的
【6月更文挑战第2天】
27 6
|
28天前
|
存储 分布式计算 Hadoop
Hadoop节点文件存储Hbase高可靠性
【6月更文挑战第2天】
30 2
|
28天前
|
存储 分布式计算 Hadoop
Hadoop节点文件存储Hbase面向列
【6月更文挑战第2天】
20 2
|
2月前
|
分布式计算 安全 Hadoop
HBase Shell-org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet 已解决
在HBase Shell遇到错误时,检查Hadoop非安全模式:`hdfs dfsadmin -safemode get`。问题解决在于`hbase-site.xml`中添加配置:Zookeeper客户端端口设为2181和预写日志提供者设为filesystem。
|
2月前
|
分布式计算 Hadoop Java
Hbase2.2.2在线安装配置(对应Hadoop 3.1.3)
Hbase2.2.2在线安装配置(对应Hadoop 3.1.3)
67 2
|
2月前
|
分布式计算 监控 Hadoop
Ganglia监控Hadoop与HBase集群
Ganglia监控Hadoop与HBase集群
|
2月前
|
分布式计算 Hadoop 关系型数据库
Hadoop任务scan Hbase 导出数据量变小分析
Hadoop任务scan Hbase 导出数据量变小分析
67 0