美文网首页
hive权限问题

hive权限问题

作者: 后知不觉1 | 来源:发表于2022-06-03 01:19 被阅读0次

背景

  • hadoop 3.1.2
  • hive 2.1.1
    hive创建库时默认用户为个人用户,这个在ranger授权后访问hive库时没有hdfs权限,需要解决创建文件夹默认权限问题

原因分析

hive权限分为两层,一层是hdfs目录权限管控,一层是hive的权限管控。一般解决思路有两种,通过ranger两边授权。另一种是直接放开hdfs的目录权限管控,授权为777,通过ranger管理hive的权限,这种方式有风险

解决方法

  • ranger中授权时在 hive中授权,再到hdfs中授权
  • 修改warehouseq目录权限,让所有的hdfs目录权限都为777
    • hive 配置继承
    • hdfs umask
    • hdfs acls设置

1、hive配置权限继承

1.1、设置warehouse目录权限为777

export HADOOP_USER_NAME=hdfs
hdfs dfs -chmod 777 /apps/hive/warehouse

1.2、修改hive-site.xml

主要是metastore的hive-site.xml配置文件

<property>
  <name>hive.warehouse.subdir.inherit.perms</name>
  <value>true</value>
  <description>
    Set this to false if the table directories should be created
    with the permissions derived from dfs umask instead of
    inheriting the permission of the warehouse or database directory.
  </description>
</property>
image.png

umask

hadoop的umask 与linux的umask类似,umask-mode值为022,默认为创建文件夹为755对应rwxr-xr-x,文件为644对应rw-r--r--
针对上述问题,设置为002即可解决,但是存在设置权限过大问题。而且验证还影响ranger鉴权。

acls

hadoop shell提供命令setfacl,来设置一个目录额外添加权限,指定用户,组可以访问的权限。

1、前提条件,开启acks权限设置

需要确定hdfs-site.xml文件的两个配置项为true:

<property>
    <name>dfs.permissions.enabled</name>
    <value>true</value>
</property>
<property>
    <name>dfs.namenode.acls.enabled</name>
    <value>true</value>
</property>
2、命令setfacl
hdfs dfs -setfacl -R|[--set <acl_spec> <path>]
 -b: 删除基本ACL条目以外的所有条目。保留用户,组和其他条目以与权限位兼容。
 -k: 删除默认ACL。default
 -R: 以递归方式将操作应用于所有文件和目录。常用。
 -m: 修改ACL。新条目将添加到ACL,并保留现有条目。常用。
 -x: 删除指定的ACL条目。保留其他ACL条目。常用。
 --set: 完全替换ACL,丢弃所有现有条目。 acl_spec必须包含用户,组和其他条目,以便与权限位兼容。
 acl_spec: 逗号分隔的ACL条目列表。
 path: 要修改的文件或目录。

demo

hdfs dfs -setfacl -m user:hadoop:rw- /file
hdfs dfs -setfacl -x user:hadoop /file
hdfs dfs -setfacl -b /file
hdfs dfs -setfacl -k /dir
hdfs dfs -setfacl --set user::rw-,user:hadoop:rw-,group::r--,other::r-- /file
hdfs dfs -setfacl -R -m user:hadoop:r-x /dir
hdfs dfs -setfacl -m default:user:hadoop:r-x /dir

说明
default:user:hadoop:r-x 在添加默认用户权限时会被子目录,文件继承,如果不使用默认修饰则不会

可以继承的说明
image.png
不可以继承的说明
image.png

ThroubleShooting

hadoop 2.7.3版本不生效,因为在3.x才支持dfs.namenode.posix.acl.inheritance.enabled,默认为true,如果开启了hdfs默认继承父目录的权限,不以umask为准

解决办法
修改client的umask参数,在不支持dfs.namenode.posix.acl.inheritance.enabled以前通过client的umask配置来确定的

相关文章

网友评论

      本文标题:hive权限问题

      本文链接:https://www.haomeiwen.com/subject/afijprtx.html