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]
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.
user::rwx
group::rwx
other::rwx
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.
user::rwx
user:hbase:rwx
group::r-x
mask::rwx
other::r-x
[tao@ecs3 ~]$ su
[root@ecs3 tao]
[root@ecs3 tao]
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]
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.
user::rwx
group::r-x
other::r-x
可以看到,这个新建的目录与其他普通的目录在权限是一样的。如果想使得新建的目录/文件的ACL也满足我们的要求,可以使用default acl来实现。
关于权限标志位的顺序: 在命令hadoop dfs -setfacl -m user:hbase:rwx /user/tao/xt-data
中,权限标志位rwx
的顺序不能改变,否则会报错:-setfacl:
Invalid permission in
正确的写法有:rwx
,r-x
,-r-
,-rx
等;
错误的写法有:wrx
,w-x
等。
Default ACL
可以为某个目录设置一个默认的ACL权限,使得以后在该目录中新建文件或者子目录时,新建的文件/目录的ACL权限都是之前设置的default ACLs。
例如,现在已经有了一个HDFS目录/user/tao
,其当前的ACL状态为:
[root@ecs1 tao]
user::rwx
group::rwx
other::rwx
我们想将其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
检查是否生效:
[root@ecs1 tao]
[root@ecs1 tao]
user::rwx
user:hbase:rwx
group::rwx
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
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.
当对hdfs 中的文件进行访问的时候, 需要对 执行hadoop 的客户端 的用户权限进行检测。取1,2,3,4的并集, 只要执行hdfs 指令用户只要满足 1,2,3,4的一种情况即可。(取最高优先级的访问权限)
1. 文件所有者 位权限 (rwx) 优先级最高。
2. 文件的特定ACL用户的权限。
3. 该用户是文件的所有组 或者是 ACL组内用户, 取满足条件组的权限并集。