Hive權限介紹


一、開啟權限 

眼下hive支持簡單的權限管理,默認情況下是不開啟。這樣全部的用戶都具有同樣的權限。同一時候也是超級管理員。也就對hive中的全部表都有查看和修改的權利,這樣是不符合一般數據倉庫的安全原則的。Hive能夠是基於元數據的權限管理。也能夠基於文件存儲級別的權限管理。此次以介紹MetaData權限管理為主。通過下面配置開啟Hive身份認證功能進行權限檢查:    

<property>

  <name>hive.security.authorization.enabled</name>

  <value>true</value>

  <description>enable or disable the hive client authorization</description>

</property>

開啟身份認證后,不論什么用戶必須被grant privilege才干對實體進行操作。

有一個表創建者對所創建表的權限配置:

<property>

  <name>hive.security.authorization.createtable.owner.grants</name>

  <value>ALL</value>

  <description>the privileges automatically granted to the owner whenever a table gets created.

   An example like "select,drop" will grant select and drop privilege to the owner of the table</description>

</property>

默認配置是NULL,設置成ALL,表示創建者對其創建的表擁有全部的權限,這樣也是比較合理的。同一時候也能夠通過配置在表創建時給某個role賦予權限:

<property>

  <name>hive.security.authorization.createtable.role.grants</name>

  <value>admin_role:ALL</value>

</property>

當然也能夠在創建時對user,group賦予權限

二、權限操作

在hive命令行下能夠通過set system:user.name;查看當前hiveusername,也即OS的登錄用戶。

開啟權限認證,在命令行下創建表:

hive>CREATE TABLE auth_test (key int, value string); 

Authorization failed:No privilege 'Create' found for outputs { database:default}.Use show grant to get more details.  

此時會創建失敗。默認情況下用戶是沒有創建表權限的。運行

hive>Grant create on database defaut to user test

后又一次創建表則會成功。能夠通過 desc extended auth_test查看包含表全部者在內的表具體信息

默認情況下其它的用戶也是是沒有權限讀取auth_test中不論什么列,以另外一個用戶登錄os在hive下運行:

hive>Select key from auth_test;

出現下面錯誤:

Authorization failed:No privilege 'Select' found for inputs { database:default, table:auth_test, columnName:key}. Use show grant to get more details.

運行:

grant select(key) on table auth_test to user test1;

后查詢則能夠成功

Grant/revoke語法:

grant/revoke priv_type[column_list] on object_type object to/from principal_type principal_name

查看grant 定義:

show grant user user_name on table table_name;

三、Role:

此外Hive還支持基於role的授權認證,role是一組權限的集合,一個role能夠被grant給多個用戶。全部擁有role的用戶都具有與此role相匹配的權限,通過對role權限的管理能夠間接控制用戶的權限。因此在一個多用戶的大型系統中。role無疑更方便於權限管理。

創建/刪除角色:

Create/drop Role role_name

角色分配/回收:

Grant role role_name to user user_name

Revoke role role_name from user user_name

角色授權:

Grant/revoke priv_type[col_List] on object_type object from/to role role_name

查看role定義:

show role grant role role_name

四、權限MetaData:

登錄hive元數據庫。能夠發現下面表:

Db_privs:記錄了User/Role在DB上的權限

Tbl_privs:記錄了User/Role在table上的權限

Tbl_col_privs:記錄了User/Role在table column上的權限

Roles:記錄了全部創建的role

Role_map:記錄了User與Role的相應關系

 



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM