hive权限管理之实践
一、实践心得
主要参考这个连接,里面说得也挺详细的。http://www.aboutyun.com/thread-12549-1-1.html
总结如下:
1、若赋予用户某个表的权限,查用户在该表所属数据库的权限,是查询不出来的,要指定到那张表
2、若要赋予用户db1数据库下的t1表权限,首先要在执行 use db1;
3、编写钩子函数时,经过我自己的测试,这边是hive0.13版本,感觉非超级管理员的grant、revoke控制不了,而create role r_name是可以控制,证明该控制类是起作用的,不知道是HiveParser.TOK_XXXX有遗漏还是其他问题,或者可以直接用ast.getToken().getText()与"TOK_CREATEROLE"字符匹配,这样是没问题。
4、以上的hive权限控制,只适合于hive cli控制权限,若用jdbc、thrift接口或hue查询页面是不能起到权限控制的,所以不是完全安全的,只是用来防止用户不小心做了不适合的事情,而不是防止坏人干坏事的。
5、倘若想更好更安全控制hive权限,可以使用Kerberos认证,听说Kerberos很强大,并且可以管理hdfs与hbase等。
简单归纳如下,方便以后查询,主要分两步,第一,修改配置文件;第二,熟悉授权语法。
二、修改配置文件
1、修改hive-site.xml
- <!--参数调优-->
- <property>
- <name>hive.exec.parallel</name>
- <value>true</value>
- <description>Whether to execute jobs in parallel</description>
- </property>
- <property>
- <name>hive.exec.parallel.thread.number</name>
- <value>16</value>
- <description>How many jobs at most can be executed in parallel</description>
- </property>
- <!-- 权限配置-->
- <!-- 开启hive cli的控制权限 -->
- <property>
- <name>hive.security.authorization.enabled</name>
- <value>true</value>
- <description>enable or disable the hive clientauthorization</description>
- </property>
- <!-- 定义表创建者的权限 -->
- <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.
- </description>
- </property>
- <!-- 在做类似drop partition操作时,metastore是否要认证权限,默认是false -->
- <property>
- <name>hive.metastore.authorization.storage.checks</name>
- <value>true</value>
- <description>
- Should the metastore do authorization checks against
- the underlying storage for operations like drop-partition (disallow
- the drop-partition if the user in question doesn't have permissions
- to delete the corresponding directory on the storage).
- </description>
- </property>
- <!-- 非安全模式,设置为true会令metastore以客户端的用户和组权限执行DFS操作,默认是false,这个属性需要服务端和客户端同时设置 -->
- <property>
- <name>hive.metastore.execute.setugi</name>
- <value>false</value>
- <description>
- In unsecure mode, setting this property to true will cause the metastore to execute DFS operations using the client's reported user
- and group permissions. Note that this property must be set on both the client
- and server sides. Further note that its best effort. If client sets its to true and server sets it to false, client setting will be ignored.
- </description>
- </property>
- <!-- 配置超级管理员,需要自定义控制类继承这个AbstractSemanticAnalyzerHook-->
- <property>
- <name>hive.semantic.analyzer.hook</name>
- <value>com.kent.test.AuthorityHook</value>
- </property>
- <!-- 假如出现以下错误:
- Error while compiling statement: FAILED: SemanticException The current builtin authorization in Hive is incomplete and disabled.
- 需要配置下面的属性 -->
- <property>
- <name>hive.security.authorization.task.factory</name>
- <value>org.apache.hadoop.hive.ql.parse.authorization.HiveAuthorizationTaskFactoryImpl</value>
- </property>
2、自定义控制类(继承AbstractSemanticAnalyzerHook)
- package com.kent.test;
- import org.apache.hadoop.hive.ql.parse.ASTNode;
- import org.apache.hadoop.hive.ql.parse.AbstractSemanticAnalyzerHook;
- import org.apache.hadoop.hive.ql.parse.HiveParser;
- import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHookContext;
- import org.apache.hadoop.hive.ql.parse.SemanticException;
- import org.apache.hadoop.hive.ql.session.SessionState;
- public class AuthorityHook extends AbstractSemanticAnalyzerHook {
- private static String[] admin = {"admin", "root"};
- @Override
- public ASTNode preAnalyze(HiveSemanticAnalyzerHookContext context,ASTNode ast) throws SemanticException {
- switch (ast.getToken().getType()) {
- case HiveParser.TOK_CREATEDATABASE:
- case HiveParser.TOK_DROPDATABASE:
- case HiveParser.TOK_CREATEROLE:
- case HiveParser.TOK_DROPROLE:
- case HiveParser.TOK_GRANT:
- case HiveParser.TOK_REVOKE:
- case HiveParser.TOK_GRANT_ROLE:
- case HiveParser.TOK_REVOKE_ROLE:
- String userName = null;
- if (SessionState.get() != null&&SessionState.get().getAuthenticator() != null){
- userName=SessionState.get().getAuthenticator().getUserName();
- }
- if (!admin[0].equalsIgnoreCase(userName) && !admin[1].equalsIgnoreCase(userName)) {
- throw new SemanticException(userName + " can't use ADMIN options, except "
- + admin[0]+","+admin[1] +".");
- }
- break;
- default:
- break;
- }
- return ast;
- }
- public static void main(String[] args) throws SemanticException {
- String[] admin = {"admin", "root"};
- String userName = "root";
- for(String tmp: admin){
- System.out.println(tmp);
- if (!tmp.equalsIgnoreCase(userName)) {
- throw new SemanticException(userName + " can't use ADMIN options, except "
- + admin[0]+","+admin[1] +".");
- }
- }
- }
- }
三、权限控制语法
1、角色权限控制
- --创建和删除角色
- create role role_name;
- drop role role_name;
- --展示所有roles
- show roles
- --赋予角色权限
- grant select on database db_name to role role_name;
- grant select on [table] t_name to role role_name;
- --查看角色权限
- show grant role role_name on database db_name;
- show grant role role_name on [table] t_name;
- --角色赋予用户
- grant role role_name to user user_name
- --回收角色权限
- revoke select on database db_name from role role_name;
- revoke select on [table] t_name from role role_name;
- --查看某个用户所有角色
- show role grant user user_name;
2、用户角色控制
- 操作(opera) 解释
- ALL 所有权限
- ALTER 允许修改元数据(modify metadata data of object)---表信息数据
- UPDATE 允许修改物理数据(modify physical data of object)---实际数据
- CREATE 允许进行Create操作
- DROP 允许进行DROP操作
- INDEX 允许建索引(目前还没有实现)
- LOCK 当出现并发的使用允许用户进行LOCK和UNLOCK操作
- SELECT 允许用户进行SELECT操作
- SHOW_DATABASE 允许用户查看可用的数据库
- --赋予用户权限
- grant opera on database db_name to user user_name;
- grant opera on [table] t_name to user user_name;
- --回收用户权限
- revoke opera on database db_name from user user_name;
- --查看用户权限
- show grant user user_name on database db_name;
- show grant user user_name on [table] t_name;
hive权限管理之实践的更多相关文章
- Android 6.0 权限管理最佳实践
博客: Android 6.0 运行时权限管理最佳实践 github: https://github.com/yanzhenjie/AndPermission
- HADOOP docker(七):hive权限管理
1. hive权限简介1.1 hive中的用户与组1.2 使用场景1.3 权限模型1.3 hive的超级用户2. 授权管理2.1 开启权限管理2.2 实现超级用户2.3 实现hiveserver2用户 ...
- SNF快速开发平台2019-用户安全控制-权限管理模型实践-权限都在这里
1.1 是否保存密码 勾选记住密码后,再次开启程序用户密码不需要再次输入,直接显示在密码输入框内,方便快捷. 图 4.1‑1 记住密码的登录页面框 1.2 是否自动登录 勾选自动登录后,再 ...
- Hive权限管理(十)
Hive权限管理 1.hive授权模型介绍 (1)Storage Based Authorization in the Metastore Server 基于存储的授权 - 可以对Metastore中 ...
- Hive权限管理
最近遇到一个hive权限的问题,先简单记录一下,目前自己的理解不一定对,后续根据自己的理解程度更新 一.hive用户的概念 hive本身没有创建用户的命令,hive的用户就是Linux用户,若当前是用 ...
- HDFS、Yarn、Hive…MRS中使用Ranger实现权限管理全栈式实践
摘要:Ranger为组件提供基于PBAC的鉴权插件,供组件服务端运行,目前支持Ranger鉴权的组件有HDFS.Yarn.Hive.HBase.Kafka.Storm和Spark2x,后续会支持更多组 ...
- 【Hive学习之七】Hive 运行方式&权限管理
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 apache-hive-3.1.1 ...
- hive(七)hive-运行方式、GUI接口、权限管理
1.Hive运行方式: 命令行方式cli:控制台模式 脚本运行方式(实际生产环境中用最多) JDBC方式:hiveserver2 web GUI接口 (hwi.hue等) 1.1Hive在CLI模 ...
- SNF快速开发平台2019-权限管理模型实践-权限都在这里
其它权限实践系列文章: 1.角色.权限.账户的概念理解-非常全的理论讲解权限控制 https://www.cnblogs.com/spring_wang/p/10954370.html 2.权限管理模 ...
随机推荐
- Windows任务计划
任务计划,可以将任何脚本.程序或文档安排在某个时间运行.“任务计划”在每次启动windows系统的时候自动启动(默认Task Scheduler服务是开启的)并在后台运行.使用“任务计划”可以完成以下 ...
- sql 给数据库表 字段 添加注释
最近发现一些代码生成器 有针对注释做一个很好的转化,之前建表的时候 没有这块的注释.现在想增加,专门去看了下 如何增加注释 1 -- 表加注释 2 EXEC sys.sp_addextendedpro ...
- java基础之 异常
Throwable是所有Java程序中错误处理的父类,有两种资类:Error和Exception. Error:表示由JVM所侦测到的无法预期的错误,由于这是属于JVM层次的严重错误,导致JVM无法继 ...
- linux下的deb/rpm文件的说明和安装方法
1. deb 是 ubuntu .debian 的格式. rpm 是 redhat .fedora .suse 的格式. 他们不通用(虽然可以转换一下). deb是debian发行版的软件 ...
- Android布局— — —帧布局
帧布局,开发中很少使用,最简单的布局 添加多个控件,这些控件会按顺序在屏幕左上角重叠显示,且会透明显示之前控件的文本语法格式:<?xml version="1.0" enco ...
- 一段显示隐藏列表HTML代码
一段显示隐藏列表HTML代码, 技巧在于把页面上的元素(“返回首页”)和控制显示/隐藏的元素(id=navs-menu)放在一个共同的div上,并在该div上绑定onmouseover和onmouse ...
- Android弱网测试中关于网络检测的一些借鉴方法
Android 平台下提供了一个android.net.ConnectivityManager类来监控当前的网络状态包括wifi.gprs.UMTS等.可以判断当前用户网络到底是WIFI还是移动网络, ...
- BZOJ 1968 约数研究
其实打个表就会发现,这个玩意儿是积性的,然后很happy的搞了一下. 不,不是这样. 考虑每个约数对答案的贡献,不难发现:约数i的贡献为n/i. 加之即可. #include<iostream& ...
- 爬虫再探实战(三)———爬取动态加载页面——selenium
自学python爬虫也快半年了,在目前看来,我面临着三个待解决的爬虫技术方面的问题:动态加载,多线程并发抓取,模拟登陆.目前正在不断学习相关知识.下面简单写一下用selenium处理动态加载页面相关的 ...
- linux命令:ls
1.介绍: ls是linux日常操作中用的最多命令,是list的缩写,默认按名称排序列出当前目录和文件,ls --help可以查看帮助. 2.命令格式: ls [OPTION] [FILE] 3.命令 ...