眼下hive支持簡單的權(quán)限管理,默認情況下是不開啟。這樣全部的用戶都具有同樣的權(quán)限。同一時候也是超級管理員。也就對hive中的全部表都有查看和修改的權(quán)利,這樣是不符合一般數(shù)據(jù)倉庫的安全原則的。Hive能夠是基于元數(shù)據(jù)的權(quán)限管理。也能夠基于文件存儲級別的權(quán)限管理。此次以介紹MetaData權(quán)限管理為主。通過下面配置開啟Hive身份認證功能進行權(quán)限檢查:
<PRoperty>
<name>hive.security.authorization.enabled</name>
<value>true</value>
<description>enable or disable the hive client authorization</description>
</property>
開啟身份認證后,不論什么用戶必須被grant privilege才干對實體進行操作。
有一個表創(chuàng)建者對所創(chuàng)建表的權(quán)限配置:
<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,設(shè)置成ALL,表示創(chuàng)建者對其創(chuàng)建的表擁有全部的權(quán)限,這樣也是比較合理的。同一時候也能夠通過配置在表創(chuàng)建時給某個role賦予權(quán)限:
<property>
<name>hive.security.authorization.createtable.role.grants</name>
<value>admin_role:ALL</value>
</property>
當然也能夠在創(chuàng)建時對user,group賦予權(quán)限
在hive命令行下能夠通過set system:user.name;查看當前hiveusername,也即OS的登錄用戶。
開啟權(quán)限認證,在命令行下創(chuàng)建表:
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.
此時會創(chuàng)建失敗。默認情況下用戶是沒有創(chuàng)建表權(quán)限的。運行
hive>Grant create on database defaut to user test
后又一次創(chuàng)建表則會成功。能夠通過 desc extended auth_test查看包含表全部者在內(nèi)的表具體信息
默認情況下其它的用戶也是是沒有權(quán)限讀取auth_test中不論什么列,以另外一個用戶登錄os在hive下運行:
hive>Select key from auth_test;
出現(xiàn)下面錯誤:
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;
此外Hive還支持基于role的授權(quán)認證,role是一組權(quán)限的集合,一個role能夠被grant給多個用戶。全部擁有role的用戶都具有與此role相匹配的權(quán)限,通過對role權(quán)限的管理能夠間接控制用戶的權(quán)限。因此在一個多用戶的大型系統(tǒng)中。role無疑更方便于權(quán)限管理。
創(chuàng)建/刪除角色:
Create/drop Role role_name
角色分配/回收:
Grant role role_name to user user_name
Revoke role role_name from user user_name
角色授權(quán):
Grant/revoke priv_type[col_List] on object_type object from/to role role_name
查看role定義:
show role grant role role_name
登錄hive元數(shù)據(jù)庫。能夠發(fā)現(xiàn)下面表:
Db_privs:記錄了User/Role在DB上的權(quán)限
Tbl_privs:記錄了User/Role在table上的權(quán)限
Tbl_col_privs:記錄了User/Role在table column上的權(quán)限
Roles:記錄了全部創(chuàng)建的role
Role_map:記錄了User與Role的相應(yīng)關(guān)系
新聞熱點
疑難解答