设为首页 加入收藏

TOP

Hadoop_Hdfs ACL 权限控制详解
2018-12-13 12:17:51 】 浏览:137
Tags:Hadoop_Hdfs ACL 权限 控制 详解
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010003835/article/details/71172873

借鉴文章:

1.HDFS ACL 权限管理

http://blog.csdn.net/u011491148/article/details/45918841

2.Hadoop-2.4.1学习之HDFS文件权限和ACL

http://blog.csdn.net/skywalker_only/article/details/40709447

3.Hadoop 创建用户及HDFS权限,HDFS操作等常用Shell命令

http://www.linuxidc.com/Linux/2012-05/60635.htm


该文章主要讲解Hadoop 的ACL权限控制,对基础的权限控制不做过多介绍:

基础的权限控制可以参考文章3。


1.开启ACL权限控制

Hadoop HDFS 默认没有使用 ACL 权限控制机制。这里介绍下如何开启 hdfs 的权限控制机制:

第一次使用需要修改hdfs-site.xml 把以下配置加进hdfs-site.xml 中, 并重启NameNode。

<property>
<name>dfs.namenode.acls.enabled</name>
<value>true</value>
</property>

我们主要是通过setfacl getfacl这两个指令对 hdfs 的 acl 权限控制进行管理。

下面介绍下什么是ACL, 以及如何使用 setfaclgetfacl 对hdfs 的权限进行管控。




2.What isACL

Hadoop中的ACL与Linux中的ACL机制基本相同,都是用于为文件系统提供更精细化的权限控制。

参考HDFS ACLs: Fine-Grained Permission for HDFS Files in Hadoop

上述文章对Hadoop的 ACL进行了介绍,并对比比较了ACL 与 普通的Linux 位文件系统的区别。

文章ACL 介绍部分摘录:

In general, plain Unix permissions aren’t sufficient when you have permission requirements that don’t map cleanly to an enterprise’s natural hierarchy of users and groups. Working in collaboration with the Apache community, we developed the HDFS ACLs feature to address this shortcoming. HDFS ACLs will be available in Apache Hadoop 2.4.0 and Hortonworks Data Platform 2.1.

HDFS ACLs give you the ability to specify fine-grained file permissions for specific named users or named groups, not just the file’s owner and group. HDFS ACLs are modeled after POSIX ACLs [5]. If you’ve ever used POSIX ACLs on a Linux file system, then you already know how ACLs work in HDFS. Best practice is to rely on traditional permission bits to implement most permission requirements, and define a smaller number of ACLs to augment the permission bits with a few exceptional rules.

下面附上我自己的理解:

普通的位权限控制 与 ACL权限控制 的区别 与优势 :

普通的位权限:

对于 单个文件, 该文件只能从属于 一个用户 , 一个组, 如果使得 该文件属于多个组, 这种需求没办法实现。

ACL 权限控制:

对于一个文件,该文件有着 自己的所属用户,所属组。 如一些特定的突发性需求:

1.该文件对另外的一个组开放

2.组内的某个人对该文件不可修改,ACL可以非常方便的实现该文件对 特定人,特定组的 一个权限管控。不仅是文件的 所属用户, 所属组。


普通的位权限控制 与 ACL权限控制 的关联:

ACL权限控制只是对 普通的位权限控制的一个补充,其基础还是构建于 rwx 这种位权限控制上的。最好的方案是对于一个文件,尽量的使用基础的位权限控制,尽量少用ACL权限增加额外的控制。 优化 hdfs 文件的所有者, 设置合适的所有组,而不是一味的添加其他的组用户进行管控。



3.getfacl 与 setfacl 命令介绍:

getfacl

getfacl用于查看一个文件/目录的ACL状态,例如:

[root@ecs1 tao]# hadoop dfs -getfacl /user/tao
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.

# file: /user/tao
# owner: tao
# group: supergroup
user::rwx
group::rwx
other::rwx
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10




setfacl

基本用法

假设,我们有一个HDFS目录/user/tao/xt-data,它目前的权限为drwxrwxr-x tao supergroup。我希望让另一个用户Hbase(不属于任何group)对该目录有rwx的权限,那么可以如下操作:

[tao@ecs3 ~]$ hadoop dfs -setfacl -m user:hbase:rwx /user/tao/xt-data

[tao@ecs3 ~]$ hadoop dfs -getfacl /user/tao/xt-data
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.

# file: /user/tao/xt-data
# owner: tao
# group: supergroup
user::rwx
user:hbase:rwx
group::r-x
mask::rwx
other::r-x

[tao@ecs3 ~]$ su

[root@ecs3 tao]# sudo -u hbase hadoop dfs -mkdir /user/tao/xt-data/testDir

[root@ecs3 tao]# sudo -u hbase hadoop dfs -ls /user/tao/xt-data
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.

Found 1 items
drwxr-xr-x   - hbase supergroup          0 2015-05-22 16:33 /user/tao/xt-data/testDir
[root@ecs3 tao]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

可以看到,现在用户hbase可以在/user/tao/xt-data中新建一个目录testDir了。那么,这个新建的目录的权限是什么呢?

[root@ecs3 tao]# hadoop dfs -getfacl /user/tao/xt-data/testDir
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.

# file: /user/tao/xt-data/testDir
# owner: hbase
# group: supergroup
user::rwx
group::r-x
other::r-x
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

可以看到,这个新建的目录与其他普通的目录在权限是一样的。如果想使得新建的目录/文件的ACL也满足我们的要求,可以使用default acl来实现。

关于权限标志位的顺序: 在命令hadoop dfs -setfacl -m user:hbase:rwx /user/tao/xt-data中,权限标志位rwx的顺序不能改变,否则会报错:-setfacl: Invalid permission in
正确的写法有:rwx,r-x,-r-,-rx等;
错误的写法有:wrxw-x等。

Default ACL

可以为某个目录设置一个默认的ACL权限,使得以后在该目录中新建文件或者子目录时,新建的文件/目录的ACL权限都是之前设置的default ACLs。

例如,现在已经有了一个HDFS目录/user/tao,其当前的ACL状态为:

[root@ecs1 tao]# hadoop dfs -getfacl /user/tao
# file: /user/tao
# owner: tao
# group: supergroup
user::rwx
group::rwx
other::rwx
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7



我们想将其default acl权限设置为user:hbase:rwx,用命令:

[root@ecs1 tao]# sudo -u tao hadoop dfs -setfacl -m default:user:hbase:rwx /user/tao

[root@ecs1 tao]# hadoop dfs -getfacl /user/tao
# file: /user/tao
# owner: tao
# group: supergroup
user::rwx
group::rwx
other::rwx
default:user::rwx
default:user:hbase:rwx
default:group::rwx
default:mask::rwx
default:other::rwx
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

检查是否生效:

[root@ecs1 tao]# sudo -u tao hadoop dfs -mkdir /user/tao/testDir

[root@ecs1 tao]# hadoop dfs -getfacl /user/tao/testDir
# file: /user/tao/testDir
# owner: tao
# group: supergroup
user::rwx
user:hbase:rwx  #effective:r-x
group::rwx  #effective:r-x
mask::r-x
other::r-x
default:user::rwx
default:user:hbase:rwx
default:group::rwx
default:mask::rwx
default:other::rwx
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16






4.ACL 与 普通位权限判断的优先级:


It’s important to keep in mind the order of eva luation for ACL entries when a user attempts to access a file system object:


1.If the user is the file owner, then the owner permission bits are enforced.

2.Else if the user has a named user ACL entry, then those permissions are enforced.

3.Else if the user is a member of the file’s group or any named group in an ACL entry, then the union of permissions for all matching entries are enforced. (The user may be a member of multiple groups.)

4.If none of the above were applicable, then the other permission bits are enforced.


In this example, the named user ACL entry accomplished our goal, because the user is not the file owner, and the named user entry takes precedence over all other entries.


优先级为 1最高 4最小:

下面对原文进行下翻译:

当对hdfs 中的文件进行访问的时候, 需要对 执行hadoop 的客户端 的用户权限进行检测。取1,2,3,4的并集, 只要执行hdfs 指令用户只要满足 1,2,3,4的一种情况即可。(取最高优先级的访问权限)

1. 文件所有者 位权限 (rwx) 优先级最高。

2. 文件的特定ACL用户的权限。

3. 该用户是文件的所有组 或者是 ACL组内用户, 取满足条件组的权限并集。

4.是ohter用户


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇hadoop 提交任务总是挂起状态 下一篇在命令行中运行Hadoop自带的WordC..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目