HIVE權限控制
資料分析小夥伴需要通過hue用戶端對hive的資料進行查詢,主要建立三個使用者,Hue賬号,linux賬号,hive中角色。
Hue添加使用者
通過Hue通路hive,首先要在Hue建立登入使用者并授予權限。
Linux添加使用者
useradd allsel #添加使用者
passwd allsel #設定使用者密碼
gpasswd -a allsel allsel #給使用者分組
hive添加使用者并授權
SQL Standards Based Authorization的授權方式
1.設定hive-site.xml配置檔案
<property>
<name>hive.security.authorization.enabled</name>
<value>true</value>
</property>
<property>
<name>hive.security.authorization.createtable.owner.grants</name>
<value>ALL</value>
</property>
<property>
<name>hive.security.authorization.task.factory</name>
<value>org.apache.hadoop.hive.ql.parse.authorization.HiveAuthorizationTaskFactoryImpl</value>
</property>
<property>
<name>hive.users.in.admin.role</name>
<value>hive</value>
<description>定義超級管理者 啟動的時候會自動建立Comma separated list of users who are in admin role for bootstrapping.
More users can be added in ADMIN role later.</description>
</property>
2.建立hive角色
登入hive執行一下指令
CREATE ROLE allsel;
可能會有以下報錯,報錯原因為建立hive的角色需要用admin權限的賬号,如步驟1中設定的hive.users.in.admin.role=hive,是以需要切換linux hive賬戶來執行指令
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Current user : root is not allowed to add roles. User has to belong to ADMIN role and have it as current role, for this action.
正确的執行動作
[root@emr-header-1 ~]# su - hive
[hive@emr-header-1 ~]$ hive
Logging initialized using configuration in file:/etc/ecm/hive-conf-2.3.3-1.0.0/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive> show current roles;
OK
public
Time taken: 0.956 seconds, Fetched: 1 row(s)
hive> set role admin;
OK
Time taken: 0.013 seconds
hive> show current roles;
OK
admin
Time taken: 0.007 seconds, Fetched: 1 row(s)
hive> CREATE ROLE allsel;
OK
建立好allsel賬戶後,對賬戶進行授權,操作如下
grant role allsel to user allsel; --将資料庫hive 角色allsel賦予linux使用者allsel
grant select on test to user allsel; --授予使用者select權限,這樣使用者下的角色擁有同樣權限
--權限收回
revoke all from user allsel;
--權限檢視
show roles; --檢視已經有的角色
show grant role allsel; --檢視角色已有權限)
show grant role allsel on database test; --檢視角色在test資料庫的已有權限
設定hdfs權限
# 切換hadoop使用者設定
# 設定使用者hdfs權限
hadoop fs -setfacl -m user:allsel:rwx /user/hive/warehouse
# 設定使用者組hdfs權限
hadoop fs -setfacl -m group:allsel:rwx /user/hive/warehouse
HDFS權限控制
1.設定hive-site.xml配置檔案
<property>
<name>hive.metastore.pre.event.listeners</name>
<value>org.apache.hadoop.hive.ql.security.authorization.AuthorizationPreEventListener</value>
</property>
<property>
<name>hive.security.metastore.authorization.manager</name>
<value>org.apache.hadoop.hive.ql.security.authorization.StorageBasedAuthorizationProvider</value>
</property>
<property>
<name>hive.security.metastore.authenticator.manager</name>
<value>org.apache.hadoop.hive.ql.security.HadoopDefaultMetastoreAuthenticator</value>
</property>
EMR的Kerberos安全叢集已經設定了Hive的warehouse的HDFS相關權限;
hadoop fs -chmod 1771 /user/hive/warehouse
也可以設定成,1表示stick bit(不能删除别人建立的檔案/檔案夾)
hadoop fs -chmod 1777 /user/hive/warehouse
sudo su has
#授予test對warehouse檔案夾rwx權限
hadoop fs -setfacl -m user:test:rwx /user/hive/warehouse
#授予hivegrp對warehouse檔案夾rwx權限
hadoo fs -setfacl -m group:hivegrp:rwx /user/hive/warehouse
問題記錄
hive> grant create on database ods to role allsel;
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Unsupported privilege type CREATE