HBase shell許可權管理
在 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> 複製程式碼