hive超级用户drop partition权限问题bug

今天有个etl开发在drop partition的时候遇到了问题,因为是使用了自己的账号,而hdfs中对应partition的文件属主是hdfs的,在删除时会因为权限问题报错,切换用户为hdfs,做drop partition的错误,还是报错,看来没这么简单。

查看表的hdfs属性,目录的属主不是hdfs且目录对 hdfs没有写权限:

[[email protected] ~]$ hadoop fs -ls -d hdfs://xxxx:9000/bip/external_table/vipdw/droptest      
Found 1 items
drwxr-x r-x   - ericni hdfs          0 2014-08-21 17:13 hdfs://xxxxx:9000/bip/external_table/vipdw/droptest

drop partition报错,报hdfs用户没有权限,在hive中是设置了hdfs为超级管理员的,所以如果直接用hadoop fs命令是可以删除的,也就是权限问题不是出在hdfs上,而是在hive上,这里怎么会没有权限呢?

hive (vipdw)> ALTER TABLE droptest DROP PARTITION(dt=‘20140840‘);
14/08/21 17:31:21 ERROR metastore.RetryingHMSHandler: MetaException(message:Table partition not deleted since hdfs://xxxx:9000/bip/external_table/vipdw/droptest is not writable by hdfs

根据调用信息,异常是在HiveMetaStore类中的verifyIsWritablePath 方法中抛出, verifyIsWritablePath类用来判断本目录的上层目录对当前用户是否可写,按照一般的思路,所有的hdfs目录都应该对超级管理员可写的。

 private void verifyIsWritablePath(Path dir) throws MetaException {
      try {
        if (!wh.isWritable(dir.getParent())) {
          throw new MetaException("Table partition not deleted since " + dir.getParent()
              + " is not writable by " + hiveConf.getUser());
        }
      } catch (IOException ex) {
        LOG.warn("Error from isWritable", ex);
        throw new MetaException("Table partition not deleted since " + dir.getParent()
            + " access cannot be checked: " + ex.getMessage());
      }
    }

这里判断调用了 Warehouse类的isWritable 的方法,但是实现方法有些问题,不会区分超级用户,只会根据目录的属主和属组的权限做判断。

public boolean isWritable(Path path) throws IOException {
    if (!storageAuthCheck) {
      // no checks for non-secure hadoop installations
      return true;
    }
    if (path == null) { //what??!!
      return false;
    }
    final FileStatus stat;
    try {
      stat = getFs(path).getFileStatus(path);
    } catch (FileNotFoundException fnfe){
      // File named by path doesn‘t exist; nothing to validate.
      return true;
    } catch (Exception e) {
      // all other exceptions are considered as emanating from
      // unauthorized accesses
      return false;
    }
    final UserGroupInformation ugi;
    try {
      ugi = ShimLoader.getHadoopShims().getUGIForConf(conf);
    } catch (LoginException le) {
      throw new IOException(le);
    }
    String user = ShimLoader.getHadoopShims().getShortUserName(ugi);
    //check whether owner can delete
    if (stat.getOwner().equals(user) &&
        stat.getPermission().getUserAction().implies(FsAction.WRITE)) {   // 判断属主有没有写权限
      return true;
    }
    //check whether group of the user can delete
    if (stat.getPermission().getGroupAction().implies(FsAction.WRITE)) {  // 判断属组有没有有写权限
      String[] groups = ugi.getGroupNames();
      if (ArrayUtils.contains(groups, stat.getGroup())) {
        return true;
      }
    }
    //check whether others can delete (uncommon case!!) //  // 判断other有没有写权限
    if (stat.getPermission().getOtherAction().implies(FsAction.WRITE)) {
      return true;
    }
    return false;
  }

fix这个bug也比较简单:

git diff
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java b/metastore/src/java/org/apache/hadoop/hive/metastor
index a4f9b0a..c69e49d 100755
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java
@@ -263,7 +263,17 @@ public boolean isWritable(Path path) throws IOException {
     }
     String user = ShimLoader.getHadoopShims().getShortUserName(ugi);
     //check whether owner can delete
-    if (stat.getOwner().equals(user) &&
+      
+       //fix hdfs drop partition bug
+       LOG.warn("in Warehouse user is " + user);
+       String adminStr = HiveConf.getVar(conf,HiveConf.ConfVars.USERS_IN_ADMIN_ROLE,"hdfs").trim();
+       LOG.warn("adminStr is " + adminStr);
+       if (user.equals(adminStr)){
+               return true;
+       }
+      
+      
+       if (stat.getOwner().equals(user) &&
         stat.getPermission().getUserAction().implies(FsAction.WRITE)) {
       return true;
     }
时间: 2024-08-07 16:39:22

hive超级用户drop partition权限问题bug的相关文章

hive的用户和用户权限

hive的用户和用户权限 HiverServer2支持远程多客户端的并发和认证,支持通过JDBC.Beeline等连接操作.hive默认的Derby数据库,由于是内嵌的文件数据库,只支持一个用户的操作访问,支持多用户需用mysql保存元数据.现在关心的是HiveServer如何基于mysql元数据库管理用户权限,其安全控制体系与Linux及Hadoop的用户是否存在联系. 1)remote方式部署Hive Hive中metastore(元数据存储)的三种方式:内嵌Derby方式.基于mysql的

hive可以drop所有表的bug fix

之前遇到的一个drop table的小问题,默认任何人都可以有使用drop db.table的权限这是一个bug, bugid:https://issues.apache.org/jira/browse/HIVE-2817 解决方法:可以通过设置 set hive.exec.drop.ignorenonexistent=false(Do not report an error if DROP TABLE/VIEW specifies a non-existent table/view, 这个值默

超级用户find: `/home/pipi/.gvfs': 权限不够

http://blog.csdn.net/pipisorry/article/details/39536433 用  sudo su 命令切换成的根用户,在找某文件的时候报错 [email protected]:/home/pipi# find / -perm -2000 /sbin/unix_chkpwd find: `/home/pipi/.gvfs': 权限不够 就是普通用户pipi的主目录下的一个叫 .gvfs 的目录, dr-x------  2 pipi pipi        0 

为linux普通用户添加超级用户权限sudo

问题:假设用户名为:ali如果用户名没有超级用户权限,当输入 sudo + 命令 时, 系统提示: ali is not in the sudoers file.  This incident will be reported. 解决:1. 进入超级用户模式.即输入"su",系统会让你输入超级用户密码,输入密码后就进入了超级用户模式. 2. 添加文件的写权限. chmod u+w /etc/sudoers 3. 编辑/etc/sudoers文件.即输入命令"vim /etc/

如何使普通用户创建的文件具有超级用户的权限呢

在这里,为了之后复习回顾的知识点更加的全面,所以补充一个很小的知识点. 就是在开发的过程中我们有时候会让我们自己(普通用户)创建的某个文件具有超级用户的权限,这样更加方便我们的开发进程,那么我们应该怎样去设置我们的linux以及我们的文件呢? 其实想要实现,只需要设置两步即可: <1>改变文件的所有者为root ,  sudo chown root filename <2>打开我们的set-bit位 , sudo chmod u+s filename  这里面的filename 指

初识CentOS(二)&mdash;&mdash;获得超级用户(root)权限

为了安全起见,linux对普通用户权限限制较大,但我们平时还是需要超级用户权限的,这类似于windows里的管理员权限.本文简单介绍如何在centos中获取超级用户权限,各linux发行版类似 在登陆界面选择"other"后输入用户名root及密码直接登陆即可.如图: 二.普通用户进入超级用户状态 在终端输入su -,然后输入密码即可,如图:大专栏  初识CentOS(二)--获得超级用户(root)权限34.png" /> 三.以普通用户使用超级用户权限 一些命令的执

oracle如何创建用户并赋予权限

本文将从用户创建讲起,特别讲述Oracle授予用户权限的一个实例,希望对大家了解Oracle授予用户权限有所帮助. 这两天在测数据库同步软件的时候,需要在Oracle里创建一个用户名和密码均为SYSDATA的用户,找了找资料,创建成功,现将Oracle中用户的创建和授予命令摘录下来:  1.Linux 下Oracle的启动 以Oracle身份登录 启动lsnrctl start 登录sqplus /nolog 连接数据库connect/assysdba 启动数据库startup 关闭数据库shu

Mysql用户设置密码和权限

http://apps.hi.baidu.com/share/detail/5530778 我的mysql安装在c:\mysql 一.更改密码 第一种方式: 1.更改之前root没有密码的情况 c:\mysql\bin>mysqladmin -u root password "your password" 2.更改之前root有密码的情况,假如为123456 c:\mysql\bin>mysqladmin -u root -p123456 password "yo

Linux之用户管理与权限控制(上)

早期Linux系统设计为了能够实现多用户.多进程高效的利用服务器资源,在此种情况下,为了能够保证用户与用户之间的文件不被随意的访问及修改.删除等操作,用户.组的管理能在某种程序上实现管理用户或批量管理用户.由于Linux的设计哲学思想『一切皆文件』,用户对设备的访问就是对文件的访问. 一.用户与组 Linux下有三类用户 1.超级用户: root 具有操作系统的一切权限 UID 值为0 2.普通用户: 普通用户具有操作系统有限的权限, UID值 500+ 3.伪用户: 是为了方便系统管理, 满足