一、实践心得

主要参考这个连接,里面说得也挺详细的。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

  1. <!--参数调优-->
  2. <property>
  3. <name>hive.exec.parallel</name>
  4. <value>true</value>
  5. <description>Whether to execute jobs in parallel</description>
  6. </property>
  7. <property>
  8. <name>hive.exec.parallel.thread.number</name>
  9. <value>16</value>
  10. <description>How many jobs at most can be executed in parallel</description>
  11. </property>
  12. <!-- 权限配置-->
  13. <!-- 开启hive cli的控制权限 -->
  14. <property>
  15. <name>hive.security.authorization.enabled</name>
  16. <value>true</value>
  17. <description>enable or disable the hive clientauthorization</description>
  18. </property>
  19. <!-- 定义表创建者的权限 -->
  20. <property>
  21. <name>hive.security.authorization.createtable.owner.grants</name>
  22. <value>ALL</value>
  23. <description>
  24. the privileges automatically granted to the owner whenever a table gets created.
  25. </description>
  26. </property>
  27. <!-- 在做类似drop partition操作时,metastore是否要认证权限,默认是false -->
  28. <property>
  29. <name>hive.metastore.authorization.storage.checks</name>
  30. <value>true</value>
  31. <description>
  32. Should the metastore do authorization checks against
  33. the underlying storage for operations like drop-partition (disallow
  34. the drop-partition if the user in question doesn't have permissions
  35. to delete the corresponding directory on the storage).
  36. </description>
  37. </property>
  38. <!-- 非安全模式,设置为true会令metastore以客户端的用户和组权限执行DFS操作,默认是false,这个属性需要服务端和客户端同时设置 -->
  39. <property>
  40. <name>hive.metastore.execute.setugi</name>
  41. <value>false</value>
  42. <description>
  43. In unsecure mode, setting this property to true will cause the metastore to execute DFS operations using the client's reported user
  44. and group permissions. Note that this property must be set on both the client
  45. 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.
  46. </description>
  47. </property>
  48. <!-- 配置超级管理员,需要自定义控制类继承这个AbstractSemanticAnalyzerHook-->
  49. <property>
  50. <name>hive.semantic.analyzer.hook</name>
  51. <value>com.kent.test.AuthorityHook</value>
  52. </property>
  53. <!-- 假如出现以下错误:
  54. Error while compiling statement: FAILED: SemanticException The current builtin authorization in Hive is incomplete and disabled.
  55. 需要配置下面的属性 -->
  56. <property>
  57. <name>hive.security.authorization.task.factory</name>
  58. <value>org.apache.hadoop.hive.ql.parse.authorization.HiveAuthorizationTaskFactoryImpl</value>
  59. </property>
 

2、自定义控制类(继承AbstractSemanticAnalyzerHook)

  1. package com.kent.test;
  2. import org.apache.hadoop.hive.ql.parse.ASTNode;
  3. import org.apache.hadoop.hive.ql.parse.AbstractSemanticAnalyzerHook;
  4. import org.apache.hadoop.hive.ql.parse.HiveParser;
  5. import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHookContext;
  6. import org.apache.hadoop.hive.ql.parse.SemanticException;
  7. import org.apache.hadoop.hive.ql.session.SessionState;
  8. public class  AuthorityHook extends AbstractSemanticAnalyzerHook {
  9. private static String[] admin = {"admin", "root"};
  10. @Override
  11. public ASTNode preAnalyze(HiveSemanticAnalyzerHookContext context,ASTNode ast) throws SemanticException {
  12. switch (ast.getToken().getType()) {
  13. case HiveParser.TOK_CREATEDATABASE:
  14. case HiveParser.TOK_DROPDATABASE:
  15. case HiveParser.TOK_CREATEROLE:
  16. case HiveParser.TOK_DROPROLE:
  17. case HiveParser.TOK_GRANT:
  18. case HiveParser.TOK_REVOKE:
  19. case HiveParser.TOK_GRANT_ROLE:
  20. case HiveParser.TOK_REVOKE_ROLE:
  21. String userName = null;
  22. if (SessionState.get() != null&&SessionState.get().getAuthenticator() != null){
  23. userName=SessionState.get().getAuthenticator().getUserName();
  24. }
  25. if (!admin[0].equalsIgnoreCase(userName) && !admin[1].equalsIgnoreCase(userName)) {
  26. throw new SemanticException(userName + " can't use ADMIN options, except "
  27. + admin[0]+","+admin[1] +".");
  28. }
  29. break;
  30. default:
  31. break;
  32. }
  33. return ast;
  34. }
  35. public static void main(String[] args) throws SemanticException {
  36. String[] admin = {"admin", "root"};
  37. String userName = "root";
  38. for(String tmp: admin){
  39. System.out.println(tmp);
  40. if (!tmp.equalsIgnoreCase(userName)) {
  41. throw new SemanticException(userName + " can't use ADMIN options, except "
  42. + admin[0]+","+admin[1] +".");
  43. }
  44. }
  45. }
  46. }

三、权限控制语法

1、角色权限控制

  1. --创建和删除角色
  2. create role role_name;
  3. drop role role_name;
  4. --展示所有roles
  5. show roles
  6. --赋予角色权限
  7. grant select on database db_name to role role_name;
  8. grant select on [table] t_name to role role_name;
  9. --查看角色权限
  10. show grant role role_name on database db_name;
  11. show grant role role_name on [table] t_name;
  12. --角色赋予用户
  13. grant role role_name to user user_name
  14. --回收角色权限
  15. revoke select on database db_name from role role_name;
  16. revoke select on [table] t_name from role role_name;
  17. --查看某个用户所有角色
  18. show role grant user user_name;

2、用户角色控制

 
1)权限控制表
  1. 操作(opera)           解释
  2. ALL             所有权限
  3. ALTER           允许修改元数据(modify metadata data of  object)---表信息数据
  4. UPDATE          允许修改物理数据(modify physical data of  object)---实际数据
  5. CREATE          允许进行Create操作
  6. DROP            允许进行DROP操作
  7. INDEX           允许建索引(目前还没有实现)
  8. LOCK            当出现并发的使用允许用户进行LOCK和UNLOCK操作
  9. SELECT          允许用户进行SELECT操作
  10. SHOW_DATABASE   允许用户查看可用的数据库
 
2)语法
  1. --赋予用户权限
  2. grant opera on database db_name to user user_name;
  3. grant opera on [table] t_name to user user_name;
  4. --回收用户权限
  5. revoke opera on database db_name from user user_name;
  6. --查看用户权限
  7. show grant user user_name on database db_name;
  8. show grant user user_name on [table] t_name;

hive权限管理之实践的更多相关文章

  1. Android 6.0 权限管理最佳实践

    博客: Android 6.0 运行时权限管理最佳实践 github: https://github.com/yanzhenjie/AndPermission

  2. HADOOP docker(七):hive权限管理

    1. hive权限简介1.1 hive中的用户与组1.2 使用场景1.3 权限模型1.3 hive的超级用户2. 授权管理2.1 开启权限管理2.2 实现超级用户2.3 实现hiveserver2用户 ...

  3. SNF快速开发平台2019-用户安全控制-权限管理模型实践-权限都在这里

    1.1    是否保存密码 勾选记住密码后,再次开启程序用户密码不需要再次输入,直接显示在密码输入框内,方便快捷. 图 4.1‑1 记住密码的登录页面框 1.2    是否自动登录 勾选自动登录后,再 ...

  4. Hive权限管理(十)

    Hive权限管理 1.hive授权模型介绍 (1)Storage Based Authorization in the Metastore Server 基于存储的授权 - 可以对Metastore中 ...

  5. Hive权限管理

    最近遇到一个hive权限的问题,先简单记录一下,目前自己的理解不一定对,后续根据自己的理解程度更新 一.hive用户的概念 hive本身没有创建用户的命令,hive的用户就是Linux用户,若当前是用 ...

  6. HDFS、Yarn、Hive…MRS中使用Ranger实现权限管理全栈式实践

    摘要:Ranger为组件提供基于PBAC的鉴权插件,供组件服务端运行,目前支持Ranger鉴权的组件有HDFS.Yarn.Hive.HBase.Kafka.Storm和Spark2x,后续会支持更多组 ...

  7. 【Hive学习之七】Hive 运行方式&权限管理

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 apache-hive-3.1.1 ...

  8. hive(七)hive-运行方式、GUI接口、权限管理

    1.Hive运行方式: 命令行方式cli:控制台模式 脚本运行方式(实际生产环境中用最多) JDBC方式:hiveserver2 web GUI接口 (hwi.hue等)   1.1Hive在CLI模 ...

  9. SNF快速开发平台2019-权限管理模型实践-权限都在这里

    其它权限实践系列文章: 1.角色.权限.账户的概念理解-非常全的理论讲解权限控制 https://www.cnblogs.com/spring_wang/p/10954370.html 2.权限管理模 ...

随机推荐

  1. 浏览器Firefox新标签页默认打开地址设置

    1.地址栏输入about:config 2.找到browser.newtab.url 修改它的值为你想要的地址,如:https://www.baidu.com

  2. [vijos P1023] Victoria的舞会3

    这… 本来想学习一下Tarjan算法的,没想到码都码好了发现这题不是求强连通分量而是简单的连通分量…图论基础都还给老师了啊啊啊!最后深搜通通解决! v标记是否被访问过,scc标记每个的祖先(本来想写T ...

  3. C++中两块内存重叠的string的copy方法

    如果两段内存重叠,用memcpy函数可能会导致行为未定义. 而memmove函数能够避免这种问题,下面是一种实现方式: #include <iostream> using namespac ...

  4. Java知识结构思维导图

  5. 主线程中一定不能放耗时操作,必须要开子线程,比如下载文件,不然会不让你拿到输入流--报错显示android.os.NetworkOnMainThreadException

    1.必须要开子线程来操作耗时操作,android.os.NetworkOnMainThreadException new Thread(new Runnable() { @Override publi ...

  6. <button>使用注意问题

    最近在项目的上传功能下(IE8)发现了如下的错误: 2015-08-13 09:14:03,396 WARN   [WARN] [http-8080-5] : Handler execution re ...

  7. IOS创建目录接口createDirectoryAtPath:withIntermediateDirectories:中参数attributes的设置

    在应用程序执行时,经常需要本地化保存一些重要的数据,这时就有可能需要创建一些目录.Objective-C提供了一个非常强大的创建目录的接口: - (BOOL)createDirectoryAtPath ...

  8. C语言数据类型在IA32中的大小

    这个主要是一些常识问题,以及在使用AT&T语法汇编时会使用的编码后缀: C声明 Intel数据类型 汇编后缀 大小(byte) char 字节  b  1 short 字  w  2 int ...

  9. Android之Activity与Service通信

    一.当Acitivity和Service处于同一个Application和进程时,通过继承Binder类来实现. 当一个Activity绑定到一个Service上时,它负责维护Service实例的引用 ...

  10. HDU1556-color the ball(线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 #include<cstdio> using namespace std; stru ...