hbase simple权限一

本文涉及的产品
云原生网关 MSE Higress,422元/月
注册配置 MSE Nacos/ZooKeeper,118元/月
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
简介: 一:shell执行:grant授权:查看commands目录下grant.rb文件:security_admin.grant(user, permissions, table_name, family, qualifier)进入security.

一:shell执行:

grant授权:

查看commands目录下grant.rb文件:

security_admin.grant(user, permissions, table_name, family, qualifier)

进入security.rb文件执行:

org.apache.hadoop.hbase.security.access.AccessControlClient.grant( @connection, tableName, user, fambytes, qualbytes, perm.getActions())

revoke解除权限:

commands目录下revoke.rb文件:

security_admin.revoke(user, table_name, family, qualifier)

紧接着进入security.rb文件执行:

org.apache.hadoop.hbase.security.access.AccessControlClient.revoke(@connection, tableName, user, fambytes, qualbytes)

二:hbase授权:

进入AccessController服务端处理请求类,(客户端类为AccessControllerClient类;)这个类执行hbase权限操作;找到授权代码:

public void grant(RpcController controller,
AccessControlProtos.GrantRequest request,
RpcCallback<AccessControlProtos.GrantResponse> done)

核心代码块:

User.runAsLoginUser(new PrivilegedExceptionAction<Void>() {
  @Override
  public Void run() throws Exception {
AccessControlLists.addUserPermission(regionEnv.getConfiguration(), perm,
  regionEnv.getTable(AccessControlLists.ACL_TABLE_NAME), request.getMergeExistingPermissions());
return null;
  }
});

执行添加用户权限到acl表一步,进入到addUserPermission方法,存储用户权限到表中:

看代码:

//获取权限行为

Permission.Action[] actions = userPerm.getActions();

//声明rowkey
//1.namespace存在,为namespace;2.表table与namespace不存在,为默认acl;3.否则为tableName

byte[] rowKey = userPermissionRowKey(userPerm);

//初始化put对象,为后面插入数据表准备

Put p = new Put(rowKey);

//插入权限行为对象的key

byte[] key = userPermissionKey(userPerm);

//action的判断

if ((actions == null) || (actions.length == 0)) {

...................中间处理,包含数据转byte等

p.addImmutable(ACL_LIST_FAMILY, key, value);

最后将权限数据插入acl表中:

t.put(p);

hbase授权结束。

三:hbase解除权限:

hbase解除权限与hbase授权一样;核心代码:

//扎到之前存储的匹配的权限移除
static void removeUserPermission(Configuration conf, UserPermission userPerm, Table t)
  throws IOException {
Delete d = new Delete(userPermissionRowKey(userPerm));
byte[] key = userPermissionKey(userPerm);

if (LOG.isDebugEnabled()) {
  LOG.debug("Removing permission "+ userPerm.toString());
}
d.addColumns(ACL_LIST_FAMILY, key);
try {
  t.delete(d);
} finally {
  t.close();
}
  }

四:hbase权限判断:

回头看AccessController类,

public class AccessController implements MasterObserver, RegionObserver, RegionServerObserver,
  AccessControlService.Interface, CoprocessorService, EndpointObserver, BulkLoadObserver

实现了CoprocessorService、AccessControlService.Interface等,会在scan,delete,merger,balance等操作前后触发操作:
例如:preScannerOpen,其他操作类似
内部调用permissionGranted(opType, user, env, families, Action.READ);检查当前user是否有privilege执行操作;
接着:

//meta表读权限所有用户都将允许
if (hri.isMetaRegion()) {
  if (permRequest == Action.READ) {
return AuthResult.allow(request, "All users allowed", user,
  permRequest, tableName, families);
  }
}
/**如果获取不到用户,权限拒绝;
其中用户没指定情况下三种情况获取:
    1.keberos中获取;
    2.hadoop用户;
    3.操作系统中的用户;
    **/
if (user == null) {
  return AuthResult.deny(request, "No user associated with request!", null,
permRequest, tableName, families);
}

检查是否有权限请求的表及列族;
如果列族存在且所有列族检查通过,则:

// all family checks passed
  return AuthResult.allow(request, "All family checks passed", user, permRequest,
  tableName, families);

否则:

// 4. no families to check and table level access failed
return AuthResult.deny(request, "No families to check and table permission failed",
user, permRequest, tableName, families);

中间权限检查通过TableAuthManager的authorize执行:
接着验证用户与验证用户组:

 if (authorizeUser(user, table, family, qualifier, action)) {
  return true;
}

String[] groups = user.getGroupNames();
if (groups != null) {
  for (String group : groups) {
if (authorizeGroup(group, table, family, qualifier, action)) {
  return true;
}
  }
}

查看验证用户:
核心代码:

// Global and namespace authorizations supercede table level
if (authorize(user, table.getNamespaceAsString(), action)) {
  return true;
}
// Check table permissions
return authorize(getTablePermissions(table).getUser(user.getShortName()), table, family,
qualifier, action);

其中检查namespace(namespace的来源就是zookeeper上注册监听的节点名nodename):权限:
从globalCache获取用户:
globalCache.getUser(user.getShortName()), action)
获取用户组:
globalCache.getGroup(group), action)
接着从nsCache获取namespace权限;
其中注册在ZooKeeperWatcher中节点数据变化(会将数据写到zookeeper中acl节点下,当然会解析acl表的数据成指定格式)的时候会refreshAuthManager,及会执行updateNsCache(namespace, perms);

    /**
    * Updates the internal permissions cache for a single table, splitting
    * the permissions listed into separate caches for users and groups to optimize
     * group lookups.
   */
private void updateNsCache(String namespace,
 ListMultimap<String, TablePermission> tablePerms) {
PermissionCache<TablePermission> newTablePerms = new PermissionCache<>();

for (Map.Entry<String, TablePermission> entry : tablePerms.entries()) {
  if (AuthUtil.isGroupPrincipal(entry.getKey())) {
newTablePerms.putGroup(AuthUtil.getGroupName(entry.getKey()), entry.getValue());
  } else {
newTablePerms.putUser(entry.getKey(), entry.getValue());
  }
}

nsCache.put(namespace, newTablePerms);
mtime.incrementAndGet();
  }

上面是cache的基本流程;
接着会用从cache中获取的权限逐个检查:

 for (Permission p : perms) {
if (p.implies(action)) {
  return true;
}
  }

结束;其中用户组的获取也是一样的道理。
这样就完成了用户操作钱权限的判断,具体请看源码。

五:hbase权限改进思路:

基于更严谨的hbase权限管理,可考虑:

1.HBASE中RWECA可以改善成更细粒度的权限,如增删改查权限;

2.连接hbase权限,用户名user+密码pwd认证;

3.grant授权与revoke解除权限,改进为user+pwd识别用户;

4.严谨的superuser用户定义及权限。

等等权限。

六:hbase权限其他方面:

1:Using Secure HTTP (HTTPS) for the Web UI

2:Using SPNEGO for Kerberos authentication with Web UIs

3:Thrift Gateway

4:REST Gateway

5:HDFS and ZooKeeper

6:Securing Access To Your Data

  • Role-based Access Control (RBAC) controls
  • Visibility Labels
  • Transparent encryption of data at rest
  • Secure Bulk Load
  • Secure Enable

七:参考:

http://hbase.apache.org/book.html#security

相关实践学习
云数据库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权限二
一:HBASE权限user HBASE的user底层使用的还是hadoop的user;构造connection类: public static Connection createConnection(Configuration conf, User u...
1450 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