HBase 权限控制


HBase的权限管理依赖协协处理器。所以我们需要配置hbase.security.authorization=true,以及hbase.coprocessor.master.classeshbase.coprocessor.master.classes使其包含org.apache.hadoop.hbase.security. access.AccessController来提供安全管控能力。所以需要设置下面参数:


HBase提供的五个权限标识符:RWXCA,分别对应着READ('R')WRITE('W')EXEC('X'),CREATE('C')ADMIN('A')
HBase提供的安全管控级别包括:
Superuser:拥有所有权限的超级管理员用户。通过hbase.superuser参数配置
Global:全局权限可以作用在集群所有的表上。
Namespace :命名空间级。
Table:表级。
ColumnFamily:列簇级权限。
Cell:单元级。
和关系数据库一样,权限的授予和回收都使用grant和revoke,但格式有所不同。grant语法格式:
grant user permissions table column_family column_qualifier
例如,给用户hive分配对表member有读写的权限, 在启用了hbase.security.authorization之后,默认每个用户只能访问当前的表。而之前创建的member表的属主是HBase,其他用户对其没有访问权限。此时我们通过hive来查找:

在HBase中赋值权限:

然后通过user_permission来查看权限

再在hive中进行查询,此时hive用户已经可以访问。

收回权限revoke的语法格式
revoke user table column family column qualifier
收回hive用户在表member上的权限

更多的信息请参见:
http://www.cloudera.com/content/cloudera/en/documentation/core/v5-2-x/topics/cdh_sg_hbase_authorization.html

Posted in  BigDataHBase|HiveNoSQL.


Configuring HBase Authorization

After you have configured HBase authentication as described in the previous section, you must establish authorization rules for the resources that a client is allowed to access. HBase currently allows you to establish authorization rules at the table, column and cell-level. for Cell-level authorization was added as an experimental feature in CDH 5.2 and is still considered experimental.

Understanding HBase Access Levels

HBase access levels are granted independently of each other and allow for different types of operations at a given scope.
  • Read (R) - can read data at the given scope
  • Write (W) - can write data at the given scope
  • Execute (X) - can execute coprocessor endpoints at the given scope
  • Create (C) - can create tables or drop tables (even those they did not create) at the given scope
  • Admin (A) - can perform cluster operations such as balancing the cluster or assigning regions at the given scope
The possible scopes are:
  • Superuser - superusers can perform any operation available in HBase, to any resource. The user who runs HBase on your cluster is a superuser, as are any principals assigned to the configuration propertyhbase.superuser in hbase-site.xml on the HMaster.
  • Global - permissions granted at global scope allow the admin to operate on all tables of the cluster.
  • Namespace - permissions granted at namespace scope apply to all tables within a given namespace.
  • Table - permissions granted at table scope apply to data or metadata within a given table.
  • ColumnFamily - permissions granted at ColumnFamily scope apply to cells within that ColumnFamily.
  • Cell - permissions granted at Cell scope apply to that exact cell coordinate. This allows for policy evolution along with data. To change an ACL on a specific cell, write an updated cell with new ACL to the precise coordinates of the original. If you have a multi-versioned schema and want to update ACLs on all visible versions, you'll need to write new cells for all visible versions. The application has complete control over policy evolution. The exception is append and increment processing. Appends and increments can carry an ACL in the operation. If one is included in the operation, then it will be applied to the result of the appendor increment. Otherwise, the ACL of the existing cell being appended to or incremented is preserved.
The combination of access levels and scopes creates a matrix of possible access levels that can be granted to a user. In a production environment, it is useful to think of access levels in terms of what is needed to do a specific job. The following list describes appropriate access levels for some common types of HBase users. It is important not to grant more access than is required for a given user to perform their required tasks.
  • Superusers - In a production system, only the HBase user should have superuser access. In a development environment, an administrator may need superuser access in order to quickly control and manage the cluster. However, this type of administrator should usually be a Global Admin rather than a superuser.
  • Global Admins - A global admin can perform tasks and access every table in HBase. In a typical production environment, an admin should not have Read or Write permissions to data within tables.

    • A global admin with Admin permissions can perform cluster-wide operations on the cluster, such as balancing, assigning or unassigning regions, or calling an explicit major compaction. This is an operations role.

    • A global admin with Create permissions can create or drop any table within HBase. This is more of a DBA-type role.

    In a production environment, it is likely that different users will have only one of Admin and Createpermissions.

    Warning:

    In the current implementation, a Global Admin with Admin permission can grant himself Read and Writepermissions on a table and gain access to that table's data. For this reason, only grant Global Adminpermissions to trusted user who actually need them.

    Also be aware that a Global Admin with Create permission can perform a Put operation on the ACL table, simulating a grant or revoke and circumventing the authorization check for Global Admin permissions. This issue (but not the first one) is fixed in CDH 5.2.1. It is not fixed in CDH 4.x or CDH 5.1.x.

    Due to these issues, be cautious with granting Global Admin privileges.

  • Namespace Admin - a namespace admin with Create permissions can create or drop tables within that namespace, and take and restore snapshots. A namespace admin with Admin permissions can perform operations such as splits or major compactions on tables within that namespace.
  • Table Admins - A table admin can perform administrative operations only on that table. A table admin with Create permissions can create snapshots from that table or restore that table from a snapshot. A table admin with Admin permissions can perform operations such as splits or major compactions on that table.
  • Users - Users can read or write data, or both. Users can also execute coprocessor endpoints, if givenExecutable permissions.

The combination of access levels and scopes creates a matrix of possible access levels that can be granted to a user. In a production environment, it is useful to think of access levels in terms of what is needed to do a specific job. The following list describes appropriate access levels for some common types of HBase users. It is important not to grant more access than is required for a given user to perform their required tasks.

  • Superusers - In a production system, only the HBase user should have superuser access. In a development environment, an administrator may need superuser access in order to quickly control and manage the cluster. However, this type of administrator should usually be a Global Admin rather than a superuser.
  • Global Admins - A global admin can perform tasks and access every table in HBase. In a typical production environment, an admin should not have Read or Write permissions to data within tables.
    • A global admin with Admin permissions can perform cluster-wide operations on the cluster, such as balancing, assigning or unassigning regions, or calling an explicit major compaction. This is an operations role.

    • A global admin with Create permissions can create or drop any table within HBase. This is more of a DBA-type role.

    In a production environment, it is likely that different users will have only one of Admin and Createpermissions.

    Warning:

    In the current implementation, a Global Admin with Admin permission can grant himself Read and Writepermissions on a table and gain access to that table's data. For this reason, only grant Global Adminpermissions to trusted user who actually need them.

    Also be aware that a Global Admin with Create permission can perform a Put operation on the ACL table, simulating a grant or revoke and circumventing the authorization check for Global Admin permissions. This issue (but not the first one) is fixed in CDH 5.3 and newer, as well as CDH 5.2.1. It is not fixed in CDH 4.x or CDH 5.1.x.

    Due to these issues, be cautious with granting Global Admin privileges.

  • Namespace Admin - a namespace admin with Create permissions can create or drop tables within that namespace, and take and restore snapshots. A namespace admin with Admin permissions can perform operations such as splits or major compactions on tables within that namespace.
  • Table Admins - A table admin can perform administrative operations only on that table. A table admin with Create permissions can create snapshots from that table or restore that table from a snapshot. A table admin with Admin permissions can perform operations such as splits or major compactions on that table.
  • Users - Users can read or write data, or both. Users can also execute coprocessor endpoints, if givenExecutable permissions.
Important:

If you are using Kerberos principal names when setting ACLs for users, note that Hadoop uses only the first part (short) of the Kerberos principal when converting it to the user name. Hence, for the principalann/fully.qualified.domain.name@YOUR-REALM.COM, HBase ACLs should only be set for user ann.

Real-World Example of Access Levels.

This table shows some typical job descriptions at a hypothetical company and the permissions they might require in order to get their jobs done using HBase.

Job Title Scope Permissions Description
Senior Administrator Global Access, Create Manages the cluster and gives access to Junior Administrators.
Junior Administrator Global Create Creates tables and gives access to Table Administrators.
Table Administrator Table Access Maintains a table from an operations point of view.
Data Analyst Table Read Creates reports from HBase data.
Web Application Table Read, Write Puts data into HBase and uses HBase data to perform operations.

Enable HBase Authorization

HBase authorization is built on top of the Coprocessors framework, specifically AccessController Coprocessor.

To enable HBase authorization, add the following properties to the hbase-site.xml file on every HBase server host (Master or RegionServer):

<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>
Note: Once the Access Controller coprocessor is enabled, any user who uses the HBase shell will be subject to access control. Access control will also be in effect for native (Java API) client access to HBase.

Configure Access Control Lists for Authorization

Now that HBase has the security coprocessor enabled, you can set ACLs using the HBase shell. Start the HBase shell as usual.

Important:

The host running the shell must be configured with a keytab file as described in Configuring Kerberos Authentication for HBase.

The commands that control ACLs are of the form of:

grant <user> <permissions>[ <table>[ <column family>[ <column qualifier> ] ] ]    #grants permissions
revoke <user> <permissions> [ <table> [ <column family> [ <column qualifier> ] ] ]   # revokes permissions 
user_permission <table>  # displays existing permissions

In the above commands, fields encased in <> are variables, and fields in [] are optional. The permissionsvariable must consist of zero or more character from the set "RWCA".

  • R denotes read permissions, which is required to perform GetScan, or Exists calls in a given scope.
  • W denotes write permissions, which is required to perform PutDeleteLockRowUnlockRow,IncrementColumnValueCheckAndDeleteCheckAndPutFlush, or Compact in a given scope.
  • X denotes execute permissions, which is required to execute coprocessor endpoints.
  • C denotes create permissions, which is required to perform CreateAlter, or Drop in a given scope.
  • A denotes admin permissions, which is required to perform EnableDisableSnapshotRestoreCloneSplit,MajorCompactGrantRevoke, and Shutdown in a given scope.

For example:

grant 'user1', 'RWC'
grant 'user2', 'RW', 'tableA'

Be sure to review the information in Understanding HBase Access Levels to understand the implications of the different access levels.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mtj66

看心情

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值