簡介:
用例:
(1) hive做為table的存儲層洒闸,spark sql,mapreduce, Presto 等等通過 Hive's HCatalog API 訪問元數(shù)據(jù)信息破镰, 進而訪問hdfs數(shù)據(jù), 此時要對hdfs訪問做權限控制(hdfs 默認已經(jīng)處理)纳击,元數(shù)據(jù)訪問需要做權限控制。
(2) hive sql 執(zhí)行引擎, hive的一個非常普遍的用法,主要針對sql的用戶和BI工具
hive 客戶端用戶 (官方建議拋棄)
ODBC/JDBC 和 HiveServer2 Api(Beeline CLI)
針對上面的用例hive官方提供三種權限控制: 基于元數(shù)據(jù)存儲、 基于sql標準、 默認的hive授權绒净。
本文主要講解基于元數(shù)據(jù)存儲(hive cli)和基于sql標準(hiveserver)的結合使用。
基于元數(shù)據(jù)存儲的授權:
hivemetaserver 的引進: 具體參考hive基礎架構
此功能在hive 0.10 加入, hive 客戶端執(zhí)行時訪問 hivemetaserver 服務來獲取元數(shù)據(jù)闪金, 此時可以根據(jù)數(shù)據(jù)庫和表和分區(qū)等文件夾的權限在metaserver端來控制用戶權限疯溺。
基于sql標準的授權:
此功能在hive 0.13.0加入, 直接通過mysql 訪問metadata,通過標準的sql權限來進行訪問控制哎垦, 目前不支持show databases和 show tables的權限控制
通過配置hive.server2.enable.doAs 為false 來控制訪問hdfs的文件權限囱嫩, 當sql標準權限通過時,可以直接操作hdfs漏设,不受hdfs權限影響
通過設置
hive.security.metastore.authorization.managerorg.apache.hadoop.hive.ql.security.authorization.MetaStoreAuthzAPIAuthorizerEmbedOnly來禁止客戶端進行sql 授權操作墨闲。
配置信息:hive-site.xml
<property>
<name>hive.users.in.admin.role</name>
<value>bfd_hz</value>
</property>
<property>
<name>hive.security.metastore.authorization.manager</name>
<value>org.apache.hadoop.hive.ql.security.authorization.StorageBasedAuthorizationProvider,org.apache.hadoop.hive.ql.security.authorization.MetaStoreAuthzAPIAuthorizerEmbedOnly</value>
</property>
<property>
<name>hive.security.metastore.authenticator.manager</name>
<value>org.apache.hadoop.hive.ql.security.HadoopDefaultMetastoreAuthenticator</value>
</property>
<property>
<name>hive.security.authorization.enabled</name>
<value>true</value>
</property>
<property>
<name>hive.security.authorization.manager</name>
<value>org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdConfOnlyAuthorizerFactory</value>
</property>
<property>
<name>hive.warehouse.subdir.inherit.perms</name>
<value>false</value>
</property>
配置信息:hiveserver2-site.xml
<property>
<name>hive.metastore.pre.event.listeners</name>
<value>org.apache.hadoop.hive.ql.security.authorization.AuthorizationPreEventListener</value>
<description>List of comma separated listeners for metastore events.</description>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://172.24.3.57:9083</value>
</property>
配置信息:hivemetastore-site.xml
<property>
<name>hive.security.authorization.manager</name>
<value>org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory</value>
</property>
<property>
<name>hive.security.authenticator.manager</name>
<value>org.apache.hadoop.hive.ql.security.SessionStateUserAuthenticator</value>
</property>
<property>
<name>hive.server2.enable.doAs</name>
<value>false</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value/>
</property>
基于元數(shù)據(jù)存儲的授權測試:
(1) 不能進行授權
org.apache.hadoop.hive.ql.security.authorization.MetaStoreAuthzAPIAuthorizerEmbedOnly
(2) 客戶端創(chuàng)建表的時候,自動加入自己創(chuàng)建表的授權郑口。(client 端 hive-site.xml org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdConfOnlyAuthorizerFactory)
(3) 不同組用戶訪問bfd_hz 創(chuàng)建的test1表
基于sql標準的授權測試:
bfd_hz 為管理員鸳碧, wenting 和 baseline 為普通用戶
(1) 管理員可以切換成admin,進行授權犬性, 普通用戶不能瞻离。
(2) bfd_hz 用戶創(chuàng)建bfd_hz 庫 bfd_hz1 表
create database bfd_hz; use bfd_hz;create table bfd_hz1(id int);
(3) wenting 用戶創(chuàng)建wenting庫 wenting1 表
create database wenting; use wenting; create table wenting1(id int);
(4) wenting 用戶對bfd_hz 的表進行操作(沒有權限)
(5) bfd_hz 授權表bfd_hz1 權限給用戶wenting
set role admin; grant select on bfd_hz1 to user wenting;
(6) 創(chuàng)建角色,并授權給baseline 用戶乒裆,讓其能夠訪問bfd_hz1 表
set role admin; create role team_baseline;
grant select on bfd_hz.bfd_hz1 to role team_baseline;
grant team_baseline to user baseline;
baseline 用戶訪問
(7)給baseline insert權限套利, 不受hdfs 文件權限影響
set role admin;
grant insert on bfd_hz.bfd_hz1 to role team_baseline;
參考網(wǎng)站
https://cwiki.apache.org/confluence/display/Hive/SQL+Standard+Based+Hive+Authorization
http://www.cnblogs.com/yurunmiao/p/4449439.html
總結:
阻止了客戶端hive 的授權操作