hive0.13权限bug fix

最近线上的hive升级到了0.13,遇到不少问题。权限上面,设置了hive.security.authorization.createtable.owner.grants 在hive0.13中,用户自己创建的表也没有权限。通过对源码的分析和debug找到了rc并fix,下面记录下。

1.首先在hive0.11中和hive0.13中分别做建表测试,通过查看数据库中的元数据,发现在hive0.11中如果设置了owner的参数在表创建之后,用户会有这个表的all的权限(具体可以分析db_privs ,tbl_privs表,hive.security.authorization.createtable.owner.grants设置为了all),而在hive0.13中则为空的。

2.通过

hive -hiveconf hive.root.logger=DEBUG,console

对比前后的日志,发现在hive0.11的时候,创建的表的属性中有权限的设置

而在hive0.11中这个是为空的

hive0.11:
14/07/16 17:05:39 DEBUG hive.log: DDL: struct ericni4 { string a}14/07/16 17:05:39 DEBUG
 lazy.LazySimpleSerDe: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe initialized with:
  columnNames=[a] columnTypes=[string] separator=[[[email protected]] nullstring=\N 
  lastColumnTakesRest=false14/07/16 17:05:39 INFO metastore.HiveMetaStore: 0: 
  create_table: Table(tableName:ericni4, dbName:temp, owner:ericni2, createTime:1405501539,
   lastAccessTime:0, retention:0,sd:StorageDescriptor(cols:[FieldSchema(name:a, 
   type:string, comment:null)], location:null, 
   inputFormat:org.apache.hadoop.mapred.SequenceFileInputFormat,
   outputFormat:org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat, 
   compressed:false, numBuckets:-1,
   serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.
   LazySimpleSerDe,parameters:{serialization.format=1}), bucketCols:[], sortCols:[], 
   parameters:{}, skewedInfo:SkewedInfo(skewedColNames:[], skewedColValues:[], 
   skewedColValueLocationMaps:{}), storedAsSubDirectories:false),partitionKeys:[],
   parameters:{}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE,
   privileges:PrincipalPrivilegeSet(userPrivileges:{ericni2=[PrivilegeGrantInfo(privilege:
   all, createTime:-1, grantor:ericni2, grantorType:USER, grantOption:true)]}, 
   groupPrivileges:null, rolePrivileges:null)) #hive0.11创建表的时候增加了这个设置
   
hive0.13
14/07/16 17:10:07 DEBUG hive.log: DDL: struct ericni4 { string a}14/07/16 17:10:07 DEBUG
 lazy.LazySimpleSerDe: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe initialized with:
  columnNames=[a] columnTypes=[string] separator=[[[email protected]] nullstring=\N 
  lastColumnTakesRest=false14/07/16 17:10:07 INFO metastore.HiveMetaStore: 0: 
  create_table: Table(tableName:ericni4, dbName:temp, owner:ericni1, createTime:1405501807,
   lastAccessTime:0, retention:0,sd:StorageDescriptor(cols:[FieldSchema(name:a, 
   type:string, comment:null)], location:null, 
   inputFormat:org.apache.hadoop.mapred.SequenceFileInputFormat,
   outputFormat:org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat, 
   compressed:false, numBuckets:-1,
   serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy
   .LazySimpleSerDe,parameters:{serialization.format=1}), bucketCols:[], sortCols:[], 
   parameters:{}, skewedInfo:SkewedInfo(skewedColNames:[], skewedColValues:[], 
   skewedColValueLocationMaps:{}), storedAsSubDirectories:false),partitionKeys:[], 
   parameters:{}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE)

3.会不会是参数没有生效?在hive0.13中注释掉这个设置做对比,发现create_table的属性并没有改变,说明至少在现在的0.13环境下这个参数并没有生效。而在0.11中前后是有变化的。

4.在hive0.11中我们设置一个错误的值来获取堆栈的调用信息:

得到0.11的调用栈:

        at org.apache.hadoop.hive.ql.session.CreateTableAutomaticGrant.checkPrivilege(CreateTableAutomaticGrant.java:118)
        at org.apache.hadoop.hive.ql.session.CreateTableAutomaticGrant.getGrantorInfoList(CreateTableAutomaticGrant.java:97)
        at org.apache.hadoop.hive.ql.session.CreateTableAutomaticGrant.create(CreateTableAutomaticGrant.java:52)
        at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:275)    
        at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:278)
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:670)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:614)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:208)

再来分析源码

在hive0.11中,在初始化session时,调用SessionState的start方法,会直接根据CreateTableAutomaticGrant类设置createTableGrants属性。

SessionState.start:
    try {
      startSs. authenticator = HiveUtils.getAuthenticator(
          startSs.getConf(),HiveConf.ConfVars.HIVE_AUTHENTICATOR_MANAGER);
      startSs. authorizer = HiveUtils.getAuthorizeProviderManager(
          startSs.getConf(), HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER,
          startSs. authenticator);
      startSs. createTableGrants = CreateTableAutomaticGrant.create(startSs
          .getConf()); //设置owner的相关权限
    } catch (HiveException e) {
      throw new RuntimeException(e);
    }

然后在创建表的时候,调用Hive.createTable的方法

(public void createTable(Table tbl, boolean ifNotExists))
  public CreateTableAutomaticGrant getCreateTableGrants() {
    return createTableGrants;
  }

而在hive0.13中,即使设置错误也不会有报错产生,通过debug源码发现这里的调用关系有些变化,SessionState的getCreateTableGrants方法调用的是setupAuth方法。

  public CreateTableAutomaticGrant getCreateTableGrants() {
    setupAuth(); //调用setupAuth方法设置createTableGrants
    return createTableGrants;
  }

其中setupAuth方法如下:

 private void setupAuth() {
    if (authenticator != null) {
      // auth has been initialized
      return;
    }
    try {
      authenticator = HiveUtils.getAuthenticator( conf,
          HiveConf.ConfVars.HIVE_AUTHENTICATOR_MANAGER);
      authenticator.setSessionState( this);
      authorizer = HiveUtils.getAuthorizeProviderManager( conf,
          HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, authenticator, true );
     
      if (authorizer == null) { //在authorizer 的取值为null时,才会生成权限
        // if it was null, the new authorization plugin must be specified in
        // config
        HiveAuthorizerFactory authorizerFactory = HiveUtils.getAuthorizerFactory(conf ,
            HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER);
        authorizerV2 = authorizerFactory.createHiveAuthorizer(new HiveMetastoreClientFactoryImpl(),
            conf, authenticator);
        authorizerV2.applyAuthorizationConfigPolicy(conf );
        // create the create table grants with new config
        createTableGrants = CreateTableAutomaticGrant.create( conf);
      }
    } catch (HiveException e) {
      throw new RuntimeException(e);
    }
    if(LOG.isDebugEnabled()){
      Object authorizationClass = getAuthorizationMode() == AuthorizationMode. V1 ?
          getAuthorizer() : getAuthorizerV2();
          LOG.debug("Session is using authorization class " + authorizationClass.getClass());
    }
    return;
  }

可以看到在在authorizer 的取值为null时,才会有生产ower权限的操作(CreateTableAutomaticGrant.create(conf))

authorizer 的值由参数hive.security.authorization.manager获得,在hive0.13里面这个是有默认值的:

HIVE_AUTHORIZATION_MANAGER("hive.security.authorization.manager",
      "org.apache.hadoop.hive.ql.security.authorization.DefaultHiveAuthorizationProvider"),

这样就导致在setupAuth方法中并不会通过CreateTableAutomaticGrant.create(conf)来设置owner的权限,rc找到了。fix也比较简单。

    try {
      authenticator = HiveUtils.getAuthenticator( conf,
          HiveConf.ConfVars.HIVE_AUTHENTICATOR_MANAGER);
      authenticator.setSessionState( this);
      authorizer = HiveUtils.getAuthorizeProviderManager( conf,
          HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, authenticator, true );
     
      createTableGrants = CreateTableAutomaticGrant.create(conf); //不管authorizer 是否为空都设置相关权限
      if (authorizer == null) { 
.......

bug fix之后,使用错误的参数,堆栈如下,说明生效了:

14/07/18 12:33:38 WARN session.SessionState: authenticator is null ,return,auth has been initialized
14/07/18 12:33:38 WARN session.CreateTableAutomaticGrant: Privilege is null
FAILED: RuntimeException org.apache.hadoop.hive.ql.metadata.HiveException: Privilege alldddd is not found.
14/07/18 12:33:38 ERROR ql.Driver: FAILED: RuntimeException org.apache.hadoop.hive.ql.metadata.HiveException: Privilege alldddd is not found.
java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Privilege alldddd is not found.
        at org.apache.hadoop.hive.ql.session.SessionState.setupAuth(SessionState.java:410)
        at org.apache.hadoop.hive.ql.session.SessionState.getAuthorizationMode(SessionState.java:979)
        at org.apache.hadoop.hive.ql.session.SessionState.isAuthorizationModeV2(SessionState.java:990)
        at org.apache.hadoop.hive.ql.Driver.doAuthorization(Driver.java:508)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:461)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:322)
        at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:975)
        at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1040)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:911)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:901)
        at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:268)
        at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:220)
        at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:423)
        at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:359)
        at org.apache.hadoop.hive.cli.CliDriver.processReader(CliDriver.java:456)
        at org.apache.hadoop.hive.cli.CliDriver.processFile(CliDriver.java:466)
        at org.apache.hadoop.hive.cli.CliDriver.processInitFiles(CliDriver.java:502)
        at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:739)
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:686)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:625)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:208)
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Privilege alldddd is not found.
        at org.apache.hadoop.hive.ql.session.CreateTableAutomaticGrant.validatePrivilege(CreateTableAutomaticGrant.java:129)
        at org.apache.hadoop.hive.ql.session.CreateTableAutomaticGrant.getGrantorInfoList(CreateTableAutomaticGrant.java:105)
        at org.apache.hadoop.hive.ql.session.CreateTableAutomaticGrant.create(CreateTableAutomaticGrant.java:57)
        at org.apache.hadoop.hive.ql.session.SessionState.setupAuth(SessionState.java:392)
        ... 24 more
时间: 2024-07-30 10:14:29

hive0.13权限bug fix的相关文章

【独家】K8S漏洞报告 | 近期bug fix解读

安全漏洞CVE-2019-1002100 3月2日,kubernetes社区公布了一个中等程度的安全漏洞CVE-2019-1002100. 该漏洞最早由Carl Henrik Lunde发现,并于2月25日在kubernetes发布issue(#74534).根据描述,具有patch权限的用户可以通过发送一个精心构造的patch请求来消耗apiserver的资源,最终会导致apiserver无法响应其他请求. 具体被构造的请求是一个json-patch类型的patch请求,比如kubectl p

hive0.13 rows loaded为空问题源码分析及fix

升级hive0.13之后发现job运行完成后Rows loaded的信息没有了. rows loaded的信息在hive0.11中由HiveHistory类的printRowCount输出.HiveHistory类的主要用途是记录job运行的信息,包括task的counter等.默认的目录在/tmp/$user中. hive0.11在SessionState 的start方法中会初始化HiveHistory的对象  if (startSs. hiveHist == null) {       s

hive0.13.1的安装

准备:去hive官方下载,本次教程安装的是hive0.13.1版本的,当然你也可以去我的百度云盘下载. 1.解压hive,命令如图所示: 2.配置hive的环境变量, 配置完后,执行下source /ect/profile 使其立即生效 3.在hive中修改hive-config.sh文件. 3.修改hadoop-env.sh里面的配置文件,修改hadoop的hadoop-env.sh(否则启动hive汇报找不到类的错误) export HADOOP_CLASSPATH=.:$CLASSPATH

hive0.13.1安装-mysql server作为hive的metastore

hive0.13.1在hadoop2.4.1伪分布式部署上安装过程 环境:redhat enterprice 6.5 +hadoop2.4.1+hive0.13.1+mysql单节点伪分布式部署 相关网址: hive官网安装指导:https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-InstallingHivefromaStableRelease hive之metastore的三种保存方式:h

hive0.13.1 orc兼容性问题

线上使用cdh4.6.0和hive0.13.1,在hive0.11之后开始支持orcfile,hive0.13.1使用的是pb2.5.0,cdh4.6.0是用的2.4.0a,线上测试orcfile,建表正常,但是插入数据时报错报错: java.lang.VerifyError: class org.apache.hadoop.hive.ql.io.orc.OrcProto$RowIndex overrides final method getUnknownFields.()Lcom/google

hive-0.13固化自定义UDF

之前帮业务方固化过hive-0.7的自定义的UDF,由于现在大部分业务数据都已经迁移到hadoop2.4.0,hive使用的版本是0.13,之前固化的UDF不能用了,让在0.13上面也固化一下,以下是固化过程: 1.常用的自定义函数有:mid,url_to_mid ,row_number ,findid ,nvl 2.udf包:hive-udf-1.0.jar 3.将hive-udf-1.0.jar包作为编译hive-exec依赖的方式有以下两种,选择其中一种就行: (1).将hive-udf-

【甘道夫】Sqoop1.4.4 实现将 Oracle10g 中的增量数据导入 Hive0.13.1 ,并更新Hive中的主表

需求 将Oracle中的业务基础表增量数据导入Hive中,与当前的全量表合并为最新的全量表. ***欢迎转载,请注明来源***    http://blog.csdn.net/u010967382/article/details/38735381 设计 涉及的三张表: 全量表:保存了截止上一次同步时间的全量基础数据表 增量表:增量临时表 更新后的全量表:更新后的全量数据表 步骤: 通过Sqoop将Oracle中的表导入Hive,模拟全量表和增量表 通过Hive将"全量表+增量表"合并为

基于Mysql的Hive0.13单机安装

一,安装环境 硬件:虚拟机 操作系统:Centos 6.4 64位 IP:10.51.121.10 主机名:datanode-4 安装用户:root Hadoop:Hadoop2.6,Hadoop2.6的单机安装请见:http://www.cnblogs.com/zouzhongfan/p/4309405.html 二,安装Mysql 1,到http://dev.mysql.com/downloads/repo/yum/ 下载mysql-community-release-el6-5.noarc

Hadoop-2.2.0 + Hbase-0.96.2 + Hive-0.13.1(转)

From:http://www.itnose.net/detail/6065872.html # 需要软件 Hadoop-2.2.0(目前Apache官网最新的Stable版本) Hbase-0.96.2(这里就用这个版本,跟Hadoop-2.2.0是配套的,不用覆盖jar包什么的) Hive-0.13.1(目前是最新版本) Zookeepr-3.4.6(这里推荐使用 3.4.5) Jdk1.7.0_60(这里推荐使用1.7.0_45) Mysql-5.5.31 # 集群结构图 NN : Nam