HDFS ACL 权限管理

来源:互联网 发布:pp助手软件源地址 编辑:程序博客网 时间:2024/05/08 00:05

What is ACL

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

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


getfacl

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

[root@ecs1 tao]# hadoop dfs -getfacl /user/taoDEPRECATED: Use of this script to execute hdfs command is deprecated.Instead use the hdfs command for it.# file: /user/tao# owner: tao# group: supergroupuser::rwxgroup::rwxother::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-dataDEPRECATED: 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: supergroupuser::rwxuser:hbase:rwxgroup::r-xmask::rwxother::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-dataDEPRECATED: Use of this script to execute hdfs command is deprecated.Instead use the hdfs command for it.Found 1 itemsdrwxr-xr-x   - hbase supergroup          0 2015-05-22 16:33 /user/tao/xt-data/testDir[root@ecs3 tao]# 

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

[root@ecs3 tao]# hadoop dfs -getfacl /user/tao/xt-data/testDirDEPRECATED: 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: supergroupuser::rwxgroup::r-xother::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等;
错误的写法有: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: supergroupuser::rwxgroup::rwxother::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: supergroupuser::rwxgroup::rwxother::rwxdefault:user::rwxdefault:user:hbase:rwxdefault:group::rwxdefault:mask::rwxdefault:other::rwx

检查是否生效:

[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: supergroupuser::rwxuser:hbase:rwx  #effective:r-xgroup::rwx  #effective:r-xmask::r-xother::r-xdefault:user::rwxdefault:user:hbase:rwxdefault:group::rwxdefault:mask::rwxdefault:other::rwx
0 0
原创粉丝点击