HBase shell权限管理

4,474 阅读2分钟

概述

在 hbase 中,为了增强数据的安全性,可以通过其权限管理功能进行权限约束。

权限控制类型

  • Read (R):读取数据权限
  • Write (W):写数据权限
  • Execute (X):执行协处理器的权限
  • Create (C):创建/删除表等操作
  • Admin (A):管理员权限

注意:以上权限均是有作用域的,具体的作用域粒度控制如下。

权限控制粒度

  • Superuser:超级管理员用户!!!拥有所有的权限! 可以通过在 hbase-site.xml 中配置 hbase.superuser 的值来添加超级账号(一般情况下保留默认的hbase即可)。
  • Global:拥有所有 table 的 admin 权限。
  • Namespace :控制命名空间级别相关权限。
  • Table:控制 table 级别相关权限。
  • ColumnFamily:控制 ColumnFamily 级别相关权限。
  • Cell:控制 Cell 级别相关权限。

注意:以上权限均是有作用实体的,具体的作用实体分类如下。

权限控制实体

  • User:对某用户授权
  • Group:对某用户组授权

权限控制

在 hbase 中,可以通过 hbase shell command 来实现权限的控制,主要涉及三部分:

  • grant:为 user / group 赋权
  • revoke:移除 user / group 的权限
  • user_permission:查看 user / group 的权限

grant / 赋权

grant 的使用方法参考:

Grant users specific rights.
Syntax : grant <user>, <permissions> [, <@namespace> [, <table> [, <column family> [, <column qualifier>]]]

permissions is either zero or more letters from the set "RWXCA".
READ('R'), WRITE('W'), EXEC('X'), CREATE('C'), ADMIN('A')

Note: Groups and users are granted access in the same way, but groups are prefixed with an '@' 
      character. In the same way, tables and namespaces are specified, but namespaces are 
      prefixed with an '@' character.

For example:

    hbase> grant 'bobsmith', 'RWXCA' // 为用户赋权
    hbase> grant '@admins', 'RWXCA' // 为用户组赋权
    hbase> grant 'bobsmith', 'RWXCA', '@ns1'
    hbase> grant 'bobsmith', 'RW', 't1', 'f1', 'col1'
    hbase> grant 'bobsmith', 'RW', 'ns1:t1', 'f1', 'col1' // 粒度可以控制到 ColumnFamily 和 Cell 级别

revoke / 移除权限

revoke 的使用方法参考:

Revoke a user's access rights.
Syntax : revoke <user> [, <@namespace> [, <table> [, <column family> [, <column qualifier>]]]]

Note: Groups and users access are revoked in the same way, but groups are prefixed with an '@' 
      character. In the same way, tables and namespaces are specified, but namespaces are 
      prefixed with an '@' character.

For example:

    hbase> revoke 'bobsmith' // 移除用户权限
    hbase> revoke '@admins' // 移除用户组权限
    hbase> revoke 'bobsmith', '@ns1'
    hbase> revoke 'bobsmith', 't1', 'f1', 'col1'
    hbase> revoke 'bobsmith', 'ns1:t1', 'f1', 'col1'

user_permission / 查看权限

Show all permissions for the particular user.
Syntax : user_permission <table>

Note: A namespace must always precede with '@' character.

For example:

    hbase> user_permission
    hbase> user_permission '@ns1' // 查看 namespace 权限
    hbase> user_permission '@.*' // 查看所有 namespace 权限
    hbase> user_permission '@^[a-c].*'
    hbase> user_permission 'table1' // 查看 table 权限
    hbase> user_permission 'namespace1:table1' // 查看 table 权限
    hbase> user_permission '.*'
    hbase> user_permission '^[A-C].*'

补充说明

为了使用 hbase 的权限管理功能,需要在 hbase-site.xml 文件中打开相应的安全认证功能。

<property>
     <name>hbase.security.authorization</name>
     <value>true</value>
</property>
<property>
     <name>hbase.coprocessor.master.classes</name>
     <value>org.apache.hadoop.hbase.security.access.AccessController</value>
</property>
<property>
     <name>hbase.coprocessor.region.classes</name>
 <value>org.apache.hadoop.hbase.security.token.TokenProvider,org.apache.hadoop.hbase.security.access.AccessController</value>
</property>
<property>
  <name>hbase.coprocessor.regionserver.classes</name>
  <value>org.apache.hadoop.hbase.security.access.AccessController,org.apache.hadoop.hbase.security.token.TokenProvider</value>
</property>