Hive的Security配置

《Programming Hive》的Security章節取出來,翻譯了一下。

Hive還是支持相當多的權限管理功能,滿足一般數據倉庫的使用。

 

Hive由一個默認的設置來配置新建文件的默認權限。

Xml代碼  收藏代碼
  1. <property>  
  2.   <name>hive.files.umask.value</name>  
  3.   <value>0002</value>  
  4.   <description>The dfs.umask value for the hive created folders</description>  
  5. </property>  

 當hive.metastore.authorization.storage.checks屬性被設置成true時,
Hive將會阻止沒有權限的用戶進行表刪除操作。
不過這個配置的默認值是false,應該設置成true

 

Xml代碼  收藏代碼
  1. <property>  
  2.   <name>hive.metastore.authorization.storage.checks</name>  
  3.   <value>true</value>  
  4.   <description>Should the metastore do authorization checks against  
  5.   the underlying storage for operations like drop-partition (disallow  
  6.   the drop-partition if the user in question doesn't have permissions  
  7.   to delete the corresponding directory on the storage).</description>  
  8. </property>  

 

 同時,Hive會儘可能地將hive.metastore.execute.setugi設置成true。

 

 開啓Hive的身份認證功能,默認是false

Xml代碼  收藏代碼
  1. <property>  
  2.   <name>hive.security.authorization.enabled</name>   
  3.   <value>true</value>  
  4.   <description>Enable or disable the hive client authorization</description>  
  5. </property>  

 另外還有一個是表格創建者用於的權限配置項:

Xml代碼  收藏代碼
  1. <property>  
  2.   <name>hive.security.authorization.createtable.owner.grants</name>  
  3.   <value>ALL</value>  
  4.   <description>The privileges automatically granted to the owner whenever  
  5.   a table gets created.An example like "select,drop" will grant select  
  6.   and drop privilege to the owner of the table</description>  
  7. </property>  

 這個配置默認是NULL,我們建議將其設置成ALL,讓用戶能夠訪問自己創建的表。

 

試驗,在命令行環境開啓用戶認證

Shell代碼  收藏代碼
  1. hive> set hive.security.authorization.enabled=true;  
  2. hive> CREATE TABLE authorization_test (key int, value string);  
  3. Authorization failed:No privilege 'Create' found for outputs { database:default}.  
  4. Use show grant to get more details.  

 

 我們可以看到,建表需要權限了。
權限可以授予給不同的主題,如用戶(USER),組(GROUP),角色(ROLES)

現在我們通過授權方式,將權限授予給當前用戶:

Shell代碼  收藏代碼
  1. hive> set system:user.name;  
  2. system:user.name=edward  
  3. hive> GRANT CREATE ON DATABASE default TO USER edward;  
  4. hive> CREATE TABLE authorization_test (key INT, value STRING);  

 這樣就可以創建表了。

 

我們可以通過SHOW GRANT命令確認我們擁有的權限:

Shell代碼  收藏代碼
  1. hive> SHOW GRANT USER edward ON DATABASE default;  
  2. database default  
  3. principalName edward  
  4. principalType USER  
  5. privilege Create  
  6. grantTime Mon Mar 19 09:18:10 EDT 2012  
  7. grantor edward  

 當Hive裏面用於N多用戶和N多張表的時候,管理員給每個用戶授權每張表會讓他崩潰的。
所以,這個時候就可以進行組(GROUP)授權。
Hive裏的用戶組的定義等價於POSIX裏面的用戶組。

Shell代碼  收藏代碼
  1. hive> CREATE TABLE authorization_test_group(a int,b int);  
  2. hive> SELECT * FROM authorization_test_group;  
  3. Authorization failed:No privilege 'Select' found for inputs  
  4. { database:default, table:authorization_test_group, columnName:a}.  
  5. Use show grant to get more details.  
  6. hive> GRANT SELECT on table authorization_test_group to group edward;  
  7. hive> SELECT * FROM authorization_test_group;  
  8. OK  
  9. Time taken: 0.119 seconds  

 當給用戶組授權變得不夠靈活的時候,角色(ROLES)就派上用途了。
用戶可以被放在某個角色之中,然後角色可以被授權。
角色不同於用戶組,是由Hadoop控制的,它是由Hive內部進行管理的。

Shell代碼  收藏代碼
  1. hive> CREATE TABLE authentication_test_role (a int , b int);  
  2. hive> SELECT * FROM authentication_test_role;  
  3. Authorization failed:No privilege 'Select' found for inputs  
  4. { database:default, table:authentication_test_role, columnName:a}.  
  5. Use show grant to get more details.  
  6. hive> CREATE ROLE users_who_can_select_authentication_test_role;  
  7. hive> GRANT ROLE users_who_can_select_authentication_test_role TO USER edward;  
  8. hive> GRANT SELECT ON TABLE authentication_test_role  
  9. > TO ROLE users_who_can_select_authentication_test_role;  
  10. hive> SELECT * FROM authentication_test_role;  
  11. OK  
  12. Time taken: 0.103 seconds  

 

介紹一下常用的授權關鍵字:

ALTER 更改表結構,創建分區
CREATE 創建表
DROP 刪除表,或分區
INDEX 創建和刪除索引
LOCK 鎖定表,保證併發
SELECT 查詢表權限
SHOW_DATABASE 查看數據庫權限
UPDATE

 爲表加載本地數據的權限

 

 

 分區表級別的授權
默認情況下,分區表的授權將會跟隨表的授權
當然,也可以給每一個分區建立一個授權機制,
只需要設置表的屬性PARTITION_LEVEL_PRIVILEGE設置成TRUE:

Shell代碼  收藏代碼
  1. hive> ALTER TABLE authorization_part  
  2. > SET TBLPROPERTIES ("PARTITION_LEVEL_PRIVILEGE"="TRUE");  
  3. Authorization failed:No privilege 'Alter' found for inputs  
  4. {database:default, table:authorization_part}.  
  5. Use show grant to get more details.  

 

 自動授權
屬性hive.security.authorization.createtable.owner.grants決定了
建表者對錶擁有的權限,一版情況下,有select和drop

Xml代碼  收藏代碼
  1. <property>  
  2.   <name>hive.security.authorization.createtable.owner.grants</name>  
  3.   <value>select,drop</value>  
  4. </property>  

 

類似的,特定的用戶可以被在表創建的時候自動授予其權限。

Xml代碼  收藏代碼
  1. <property>  
  2.   <name>hive.security.authorization.createtable.user.grants</name>  
  3.   <value>admin1,edward:select;user1:create</value>  
  4. </property>  

 當表建立的時候,管理員admin1和用戶edward授予讀所有表的權限。
而user1只能創建表。

 

同樣的配置也可以作用於組授權和角色授權
hive.security.authorization.createtable.group.grants
hive.security.authorization.createtable.role.grants



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章