Hive安全

使用Hive進行權限驗證
如果文件和文件夾是多個用戶共同擁有的話,那麼文件的權限設置就變的相當重要。HDFS中的文件目錄權限和Unix中的模式非常相似,都包含3層:用戶、組和其他,同時具有3種權限:可讀、可寫和可執行。
Hive中hive.files.unmask.value來定義對於新創建的文件設置默認的權限的unmask值,也就是掩碼字節數。
同時,當屬性hive.metaastore.authorization.storage.checks的值爲true時,如果用戶沒有刪除表底層文件的權限,Hive就會阻止其對於該表的刪除操作。該參數默認的數值爲false。
當在安全模式下執行時,Hive元數據存儲要儘可能的將hive.metastore.excute.setugi屬性設置爲true

Hive中的權限管理
Hive v0.7.0版本中增加了通過HiveQL進行授權設置的功能。默認情況下,該功能是不開啓的。只有將其數值設置爲true時纔會開啓,該屬性爲hive.security.authorization.enabled,默認情況下,hive.security.authorization.createtable.owner.grants的值爲null,這使得用戶無法訪問自己的表,因此我們也需要給表創建者對應的權限才行。

可以對用戶、組和角色授予權限或者回收權限
給用戶授權(創建表的權限):
set hive.security.authorization.enabled = true ;
set system:user.name ;//edward
grant create on database default to user edward ;

show grant user edward on database default ;

在用戶很多的情況下,對於用戶級別的權限授予將會給運維帶來很高的成本,選擇基於組級別的權限的授予:
授予查詢權限:
grant select on table mytab to group edward ;

以上兩種方法還不行的話,可以選擇使用角色:
create role users_role ;
grant role users_role to user edward ;
grant select on table mytab to role users_role ;

grant 和 revoke 權限
all            所有權限
alter        修改表結構的權限
create     創建表的權限
drop       刪除表或者表中的分區的權限
index     創建索引的權限
lock       開啓併發以後,鎖定和解鎖表的權限
select    查詢表或者分區中數據的權限
update  向表、分區中插入或者加載數據的權限
show_database 查看所有數據庫的權限

分區級別的權限
默認情況下,Hive是在表級別的授予權限的,不過,同樣可以在分區級別進行權限的授予,只需要將表的屬性PARTITION_LEVEL_PRIVILEGE設置爲true即可:
授予:
grant alter on table mytab to user edward ;
alter table mytab set tblproperties("PARTITION_LEVEL_PRIVILEGE"="true");
grant select on table mytab to user edward ;
執行:
alter table mytab add partition(ds="3");
alter table mytab add partition(ds="4");
select * from mytab where ds="3"; 
回收:
revoke select on table mytab partition(ds="3") from user edward ;
存在異常:
select * from mytab where ds="3"; 
正常訪問:
select * from mytab where ds="4"; 

自動授權:
屬性hive.security.authorization.createtable.owner.grants中可以定義未創建表的用戶自動授予對這張表的指定權限:
<property>
<name>hive.security.authorization.createtable.owner.grants</name>
<value>select,drop</value>
</property>

類似地,可以創建表的時候自動授予自定用戶指定權限,屬性hive.security.authorization.createtable.user.grants就控制着這個行爲:
<property>
<name>hive.security.authorization.createtable.user.grants</name>
<value>admin1,edward:select,user1:create</value>
</property>

對於組和角色同樣也存在屬性來控制自動授予的權限
對於組:hive.security.authorization.createtable.group.grants
角色:hive.security.authorization.createtable.role.grants

發佈了43 篇原創文章 · 獲贊 1 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章