轉載URL: http://www.cnblogs.com/zfyouxi/p/5341387.html
一、開啟許可權
眼下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的相應關係