Hive(九) Hive 权限

Hive 权限

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Authorization

Introduction

Note that this documentation is referring to Authorization which is verifying if a user has permission to perform a certain action, and not about Authentication (verifying the identity of the user). Strong authentication for tools like the Hive command line is provided through the use of Kerberos. There are additional authentication options for users of HiveServer2.

导言

请注意,此文档是指正在验证用户是否有权执行某一操作的授权,而不是关于身份验证(验证用户的身份)。通过使用 Kerberos 为 Hive 命令行等工具提供强大的身份验证。为 HiveServer2 的用户提供了额外的身份验证选项。

Transform 功能见 https://www.cnblogs.com/aquastone/p/hive-transform.html

普通用户不能登录的问题演示:

1. 先将启动的所有 hive 服务器以及客户端都关闭。

2. 启动:

Node3:hive --service metastore
Node4:hiveserver2

3. Node2:beeline 连接:

beeline -u jdbc:hive2://node4:10000/default -n gtjin -p 123

[root@node2 ~]# beeline -u jdbc:hive2://node4:10000/default -n gtjin -p 123
Connecting to jdbc:hive2://node4:10000/default
Error: Failed to open new session: java.lang.RuntimeException:
java.lang.RuntimeException:
org.apache.hadoop.security.AccessControlException: Permission
denied: user=gtjin, access=EXECUTE,
inode="/tmp":root:supergroup:drwx------

beeline -u jdbc:hive2://node4:10000/default -n root -p 123

root 可以正常访问。

原因:这是由于 hadoop 的安全验证导致的。

解决不同用户不能登录的问题:

1. 修改四台虚拟机上 hdfs-site.xml,添加如下配置:

<property>
    <name>dfs.permissions.enabled</name>
    <value>false</value>
</property>

2. 修改 node3 上的 hive-site.xml

在 hive 服务端(node3)修改配置文件 hive-site.xml 添加以下配置内容(建议 hwi的相关配置删除):

<property>
    <name>hive.security.authorization.enabled</name>
    <value>true</value>
</property>
<property>
    <name>hive.server2.enable.doAs</name>
    <value>false</value>
</property>
<property>
    <name>hive.users.in.admin.role</name>
    <value>root</value>
</property>
<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>

关闭 hive 服务器和客户端,重启 hadoop 集群。

[root@node2 ~]# beeline -u jdbc:hive2://node4:10000/default -n gtjin -p 123 便可以正常访问了。

但是该方式普通用户登录之后,也可以创建角色。

CREATE ROLE role_name; -- 创建角色

DROP ROLE role_name; -- 删除角色

SET ROLE (role_name|ALL|NONE); -- 设置角色

SHOW CURRENT ROLES; -- 查看当前具有的角色

SHOW ROLES; -- 查看所有存在的角色

切换如下方式:

关闭 hive 服务器端和客户端。重新在 node3 上执行 hiveserver2 命令,node2 上通过beeline 访问即可。

普通用户只能看自己具有的角色了。

root 用户登录后,创建角色失败,需要通过命令:set role admin,切换角色。

create role sxt;

对比 MYSQL 授权:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH
GRANT OPTION;

授角色:grant admin to role sxt with admin option;

查看:show role grant role sxt;

查看 admin 角色被授予的列表:show principals admin;

撤销角色:

        revoke admin from role sxt;#从角色 sxt 撤销 admin 角色

        revoke admin from user gtjin;#从用户 gtjin 撤销 admin 角色

删除角色:drop role test;

权限列表:

1. ALL - Gives users all privileges
2. ALTER - Allows users to modify the metadata of an object
3. UPDATE - Allows users to modify the physical data of an object
4. CREATE - Allows users to create objects. For a database, this means
users can create tables, and for a table, this means users can create
partitions
5. DROP - Allows users to drop objects
6. INDEX - Allows users to create indexes on an object (Note: this is not currently implemented)
7. LOCK - Allows users to lock or unlock tables when concurrency is enabled
8. SELECT - Allows users to access data for objects
9. SHOW_DATABASE - Allows users to view available databases

链接:

https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=45876173#Hivedeprecatedauthorizationmode/LegacyMode-Grant/RevokePrivileges

授予权限:

grant select on person to user gtjin with grant option;

切换 gtjin 登录,查询 person 表可以,别的表无权限。

#grant select on person to role sxt with grant option;

查看权限:

show grant user gtjin on all;

show grant user gtjin on table person;

撤销权限:

revoke select on person from user gtjin;

root 登录,且切换 admin 角色后才能删除

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

plenilune-望月

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值