diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-4685.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-4685.txt index a42833ed79..333352c00a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-4685.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-4685.txt @@ -44,6 +44,9 @@ HDFS-4685 (Unreleased) HADOOP-10241. Clean up output of FsShell getfacl. (Chris Nauroth via wheat9) + HDFS-5702. FsShell Cli: Add XML based End-to-End test for getfacl and + setfacl commands. (Vinay via cnauroth) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestAclCLI.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestAclCLI.java new file mode 100644 index 0000000000..2b0859d415 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestAclCLI.java @@ -0,0 +1,83 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.cli; + +import org.apache.hadoop.cli.util.CLICommand; +import org.apache.hadoop.cli.util.CommandExecutor.Result; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.hdfs.DFSConfigKeys; +import org.apache.hadoop.hdfs.MiniDFSCluster; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class TestAclCLI extends CLITestHelperDFS { + private MiniDFSCluster cluster = null; + private FileSystem fs = null; + private String namenode = null; + private String username = null; + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); + fs = cluster.getFileSystem(); + namenode = conf.get(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "file:///"); + username = System.getProperty("user.name"); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + if (fs != null) { + fs.close(); + } + if (cluster != null) { + cluster.shutdown(); + } + } + + @Override + protected String getTestFile() { + return "testAclCLI.xml"; + } + + @Override + protected String expandCommand(final String cmd) { + String expCmd = cmd; + expCmd = expCmd.replaceAll("NAMENODE", namenode); + expCmd = expCmd.replaceAll("USERNAME", username); + expCmd = expCmd.replaceAll("#LF#", + System.getProperty("line.separator")); + expCmd = super.expandCommand(expCmd); + return expCmd; + } + + @Override + protected Result execute(CLICommand cmd) throws Exception { + return cmd.getExecutor(namenode).executeCommand(cmd.getCmd()); + } + + @Test + @Override + public void testAll() { + super.testAll(); + } +} diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testAclCLI.xml b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testAclCLI.xml new file mode 100644 index 0000000000..aeb530a132 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testAclCLI.xml @@ -0,0 +1,760 @@ + + + + + + + + test + + + + + + getfacl: basic permissions + + -fs NAMENODE -touchz /file1 + -fs NAMENODE -getfacl /file1 + + + -fs NAMENODE -rm /file1 + + + + SubstringComparator + # file: /file1 + + + SubstringComparator + # owner: USERNAME + + + SubstringComparator + # group: supergroup + + + SubstringComparator + user::rw- + + + SubstringComparator + group::r-- + + + SubstringComparator + other::r-- + + + + + getfacl: basic permissions for directory + + -fs NAMENODE -mkdir /dir1 + -fs NAMENODE -getfacl /dir1 + + + -fs NAMENODE -rm /dir1 + + + + SubstringComparator + # file: /dir1 + + + SubstringComparator + # owner: USERNAME + + + SubstringComparator + # group: supergroup + + + SubstringComparator + user::rwx + + + SubstringComparator + group::r-x + + + SubstringComparator + other::r-x + + + + + setfacl : Add an ACL + + -fs NAMENODE -touchz /file1 + -fs NAMENODE -setfacl -m user:bob:r-- /file1 + -fs NAMENODE -getfacl /file1 + + + -fs NAMENODE -rm /file1 + + + + SubstringComparator + # file: /file1 + + + SubstringComparator + # owner: USERNAME + + + SubstringComparator + # group: supergroup + + + SubstringComparator + user::rw- + + + SubstringComparator + user:bob:r-- + + + SubstringComparator + group::r-- + + + SubstringComparator + mask::r-- + + + SubstringComparator + other::r-- + + + + + setfacl : Add multiple ACLs at once + + -fs NAMENODE -touchz /file1 + -fs NAMENODE -setfacl -m user:bob:r--,group:users:r-x /file1 + -fs NAMENODE -getfacl /file1 + + + -fs NAMENODE -rm /file1 + + + + SubstringComparator + # file: /file1 + + + SubstringComparator + # owner: USERNAME + + + SubstringComparator + # group: supergroup + + + SubstringComparator + user::rw- + + + SubstringComparator + user:bob:r-- + + + SubstringComparator + group::r-- + + + SubstringComparator + group:users:r-x + + + SubstringComparator + mask::r-x + + + SubstringComparator + other::r-- + + + + + setfacl : Remove an ACL + + -fs NAMENODE -touchz /file1 + -fs NAMENODE -setfacl -m user:bob:r--,user:charlie:r-x /file1 + -fs NAMENODE -setfacl -x user:bob /file1 + -fs NAMENODE -getfacl /file1 + + + -fs NAMENODE -rm /file1 + + + + SubstringComparator + # file: /file1 + + + SubstringComparator + # owner: USERNAME + + + SubstringComparator + # group: supergroup + + + SubstringComparator + user::rw- + + + SubstringComparator + user:charlie:r-x + + + SubstringComparator + group::r-- + + + SubstringComparator + other::r-- + + + RegexpAcrossOutputComparator + .*(?!bob)* + + + + + setfacl : Add default ACL + + -fs NAMENODE -mkdir /dir1 + -fs NAMENODE -setfacl -m user:bob:r--,group:users:r-x /dir1 + -fs NAMENODE -setfacl -m default:user:charlie:r-x,default:group:admin:rwx /dir1 + -fs NAMENODE -getfacl /dir1 + + + -fs NAMENODE -rm -R /dir1 + + + + SubstringComparator + # file: /dir1 + + + SubstringComparator + # owner: USERNAME + + + SubstringComparator + # group: supergroup + + + SubstringComparator + user::rwx + + + SubstringComparator + user:bob:r-- + + + SubstringComparator + group::r-x + + + SubstringComparator + group:users:r-x + + + SubstringComparator + mask::r-x + + + SubstringComparator + other::r-x + + + SubstringComparator + default:user::rwx + + + SubstringComparator + default:user:charlie:r-x + + + SubstringComparator + default:group::r-x + + + SubstringComparator + default:group:admin:rwx + + + SubstringComparator + default:mask::rwx + + + SubstringComparator + default:other::r-x + + + + + setfacl : try adding default ACL to file + + -fs NAMENODE -touchz /file1 + -fs NAMENODE -setfacl -m default:user:charlie:r-x /file1 + + + -fs NAMENODE -rm /file1 + + + + SubstringComparator + setfacl: Invalid ACL: only directories may have a default ACL + + + + + setfacl : Remove one default ACL + + -fs NAMENODE -mkdir /dir1 + -fs NAMENODE -setfacl -m user:bob:r--,group:users:r-x /dir1 + -fs NAMENODE -setfacl -m default:user:charlie:r-x,default:group:admin:rwx /dir1 + -fs NAMENODE -setfacl -x default:user:charlie /dir1 + -fs NAMENODE -getfacl /dir1 + + + -fs NAMENODE -rm -R /dir1 + + + + SubstringComparator + # file: /dir1 + + + SubstringComparator + # owner: USERNAME + + + SubstringComparator + # group: supergroup + + + SubstringComparator + user::rwx + + + SubstringComparator + user:bob:r-- + + + SubstringComparator + group::r-x + + + SubstringComparator + group:users:r-x + + + SubstringComparator + mask::r-x + + + SubstringComparator + other::r-x + + + SubstringComparator + default:user::rwx + + + SubstringComparator + default:group::r-x + + + SubstringComparator + default:group:admin:rwx + + + SubstringComparator + default:mask::rwx + + + SubstringComparator + default:other::r-x + + + RegexpAcrossOutputComparator + .*(?!default:user:charlie).* + + + + + setfacl : Remove all default ACL + + -fs NAMENODE -mkdir /dir1 + -fs NAMENODE -setfacl -m user:bob:r--,group:users:r-x /dir1 + -fs NAMENODE -setfacl -m default:user:charlie:r-x,default:group:admin:rwx /dir1 + -fs NAMENODE -setfacl -k /dir1 + -fs NAMENODE -getfacl /dir1 + + + -fs NAMENODE -rm -R /dir1 + + + + SubstringComparator + # file: /dir1 + + + SubstringComparator + # owner: USERNAME + + + SubstringComparator + # group: supergroup + + + SubstringComparator + user::rwx + + + SubstringComparator + user:bob:r-- + + + SubstringComparator + group::r-x + + + SubstringComparator + group:users:r-x + + + SubstringComparator + mask::r-x + + + SubstringComparator + other::r-x + + + RegexpAcrossOutputComparator + .*(?!default).* + + + + + setfacl : Remove all but base ACLs for a directory + + -fs NAMENODE -mkdir /dir1 + -fs NAMENODE -setfacl -m user:charlie:r-x,default:group:admin:rwx /dir1 + -fs NAMENODE -setfacl -b /dir1 + -fs NAMENODE -getfacl /dir1 + + + -fs NAMENODE -rm -R /dir1 + + + + SubstringComparator + # file: /dir1 + + + SubstringComparator + # owner: USERNAME + + + SubstringComparator + # group: supergroup + + + SubstringComparator + user::rwx + + + SubstringComparator + group::r-x + + + SubstringComparator + other::r-x + + + RegexpAcrossOutputComparator + .*(?!charlie).* + + + RegexpAcrossOutputComparator + .*(?!default).* + + + RegexpAcrossOutputComparator + .*(?!admin).* + + + + + setfacl : Remove all but base ACLs for a file + + -fs NAMENODE -touchz /file1 + -fs NAMENODE -setfacl -m user:charlie:r-x,group:admin:rwx /file1 + -fs NAMENODE -setfacl -b /file1 + -fs NAMENODE -getfacl /file1 + + + -fs NAMENODE -rm /file1 + + + + SubstringComparator + # file: /file1 + + + SubstringComparator + # owner: USERNAME + + + SubstringComparator + # group: supergroup + + + SubstringComparator + user::rw- + + + SubstringComparator + group::r-- + + + SubstringComparator + other::r-- + + + RegexpAcrossOutputComparator + .*(?!charlie).* + + + RegexpAcrossOutputComparator + .*(?!admin).* + + + + + setfacl : check inherit default ACL to file + + -fs NAMENODE -mkdir /dir1 + -fs NAMENODE -setfacl -m default:user:charlie:r-x,default:group:admin:rwx /dir1 + -fs NAMENODE -touchz /dir1/file + -fs NAMENODE -getfacl /dir1/file + + + -fs NAMENODE -rm -R /dir1 + + + + SubstringComparator + # file: /dir1/file + + + SubstringComparator + # owner: USERNAME + + + SubstringComparator + # group: supergroup + + + SubstringComparator + user::rw- + + + SubstringComparator + user:charlie:r-x + + + SubstringComparator + group::r-- + + + SubstringComparator + group:admin:rwx + + + SubstringComparator + other::r-- + + + RegexpAcrossOutputComparator + .*(?!default).* + + + + + setfacl : check inherit default ACL to dir + + -fs NAMENODE -mkdir /dir1 + -fs NAMENODE -setfacl -m default:user:charlie:r-x,default:group:admin:rwx /dir1 + -fs NAMENODE -mkdir /dir1/dir2 + -fs NAMENODE -getfacl /dir1/dir2 + + + -fs NAMENODE -rm -R /dir1 + + + + SubstringComparator + # file: /dir1/dir2 + + + SubstringComparator + # owner: USERNAME + + + SubstringComparator + # group: supergroup + + + SubstringComparator + user::rwx + + + SubstringComparator + user:charlie:r-x + + + SubstringComparator + group::r-x + + + SubstringComparator + group:admin:rwx + + + SubstringComparator + mask::rwx + + + SubstringComparator + default:user::rwx + + + SubstringComparator + default:user:charlie:r-x + + + SubstringComparator + default:group::r-x + + + SubstringComparator + default:group:admin:rwx + + + SubstringComparator + default:mask::rwx + + + SubstringComparator + default:other::r-x + + + SubstringComparator + other::r-x + + + + + getfacl -R : recursive + + -fs NAMENODE -mkdir /dir1 + -fs NAMENODE -setfacl -m user:charlie:r-x,group:admin:rwx /dir1 + -fs NAMENODE -mkdir /dir1/dir2 + -fs NAMENODE -setfacl -m user:user1:r-x,group:users:rwx /dir1/dir2 + -fs NAMENODE -getfacl -R /dir1 + + + -fs NAMENODE -rm -R /dir1 + + + + ExactComparator + # file: /dir1#LF## owner: USERNAME#LF## group: supergroup#LF#user::rwx#LF#user:charlie:r-x#LF#group::r-x#LF#group:admin:rwx#LF#mask::rwx#LF#other::r-x#LF##LF## file: /dir1/dir2#LF## owner: USERNAME#LF## group: supergroup#LF#user::rwx#LF#user:user1:r-x#LF#group::r-x#LF#group:users:rwx#LF#mask::rwx#LF#other::r-x#LF##LF# + + + + + setfacl -R : recursive + + -fs NAMENODE -mkdir /dir1 + -fs NAMENODE -mkdir /dir1/dir2 + -fs NAMENODE -setfacl -R -m user:charlie:r-x,group:admin:rwx /dir1 + -fs NAMENODE -getfacl -R /dir1 + + + -fs NAMENODE -rm -R /dir1 + + + + ExactComparator + # file: /dir1#LF## owner: USERNAME#LF## group: supergroup#LF#user::rwx#LF#user:charlie:r-x#LF#group::r-x#LF#group:admin:rwx#LF#mask::rwx#LF#other::r-x#LF##LF## file: /dir1/dir2#LF## owner: USERNAME#LF## group: supergroup#LF#user::rwx#LF#user:charlie:r-x#LF#group::r-x#LF#group:admin:rwx#LF#mask::rwx#LF#other::r-x#LF##LF# + + + + + setfacl --set : Set full set of ACLs + + -fs NAMENODE -mkdir /dir1 + -fs NAMENODE -setfacl -m user:charlie:r-x,group:admin:rwx /dir1 + -fs NAMENODE -setfacl --set user::rw-,group::r--,other::r--,user:user1:r-x,group:users:rw- /dir1 + -fs NAMENODE -getfacl /dir1 + + + -fs NAMENODE -rm -R /dir1 + + + + ExactComparator + # file: /dir1#LF## owner: USERNAME#LF## group: supergroup#LF#user::rw-#LF#user:user1:r-x#LF#group::r--#LF#group:users:rw-#LF#mask::rwx#LF#other::r--#LF##LF# + + + + + setfacl -x mask : remove mask entry along with other ACL entries + + -fs NAMENODE -mkdir /dir1 + -fs NAMENODE -setfacl -m user:charlie:r-x,group:admin:rwx /dir1 + -fs NAMENODE -setfacl -x mask::,user:charlie,group:admin /dir1 + -fs NAMENODE -getfacl /dir1 + + + -fs NAMENODE -rm -R /dir1 + + + + ExactComparator + # file: /dir1#LF## owner: USERNAME#LF## group: supergroup#LF#user::rwx#LF#group::r-x#LF#other::r-x#LF##LF# + + + + + \ No newline at end of file