Search in sources :

Example 71 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class TestAclWithSnapshot method testGetAclStatusDotSnapshotPath.

@Test
public void testGetAclStatusDotSnapshotPath() throws Exception {
    hdfs.mkdirs(path);
    SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);
    AclStatus s = hdfs.getAclStatus(new Path(path, ".snapshot"));
    AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(new AclEntry[] {}, returned);
}
Also used : Path(org.apache.hadoop.fs.Path) AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) FSAclBaseTest(org.apache.hadoop.hdfs.server.namenode.FSAclBaseTest) Test(org.junit.Test)

Example 72 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class TestAclWithSnapshot method testRemoveAclExceedsQuota.

@Test
public void testRemoveAclExceedsQuota() throws Exception {
    Path filePath = new Path(path, "file1");
    Path fileSnapshotPath = new Path(snapshotPath, "file1");
    FileSystem.mkdirs(hdfs, path, FsPermission.createImmutable((short) 0755));
    hdfs.allowSnapshot(path);
    hdfs.setQuota(path, 3, HdfsConstants.QUOTA_DONT_SET);
    FileSystem.create(hdfs, filePath, FsPermission.createImmutable((short) 0600)).close();
    hdfs.setPermission(filePath, FsPermission.createImmutable((short) 0600));
    List<AclEntry> aclSpec = Lists.newArrayList(aclEntry(ACCESS, USER, "bruce", READ_WRITE));
    hdfs.modifyAclEntries(filePath, aclSpec);
    hdfs.createSnapshot(path, snapshotName);
    AclStatus s = hdfs.getAclStatus(filePath);
    AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(new AclEntry[] { aclEntry(ACCESS, USER, "bruce", READ_WRITE), aclEntry(ACCESS, GROUP, NONE) }, returned);
    assertPermission((short) 010660, filePath);
    s = hdfs.getAclStatus(fileSnapshotPath);
    returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(new AclEntry[] { aclEntry(ACCESS, USER, "bruce", READ_WRITE), aclEntry(ACCESS, GROUP, NONE) }, returned);
    assertPermission((short) 010660, filePath);
    aclSpec = Lists.newArrayList(aclEntry(ACCESS, USER, "bruce", READ));
    hdfs.removeAcl(filePath);
}
Also used : Path(org.apache.hadoop.fs.Path) AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) FSAclBaseTest(org.apache.hadoop.hdfs.server.namenode.FSAclBaseTest) Test(org.junit.Test)

Example 73 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class TestAclWithSnapshot method testDeDuplication.

@Test
public void testDeDuplication() throws Exception {
    int startSize = AclStorage.getUniqueAclFeatures().getUniqueElementsSize();
    // unique default AclEntries for this test
    List<AclEntry> aclSpec = Lists.newArrayList(aclEntry(ACCESS, USER, "testdeduplicateuser", ALL), aclEntry(ACCESS, GROUP, "testdeduplicategroup", ALL));
    hdfs.mkdirs(path);
    hdfs.modifyAclEntries(path, aclSpec);
    assertEquals("One more ACL feature should be unique", startSize + 1, AclStorage.getUniqueAclFeatures().getUniqueElementsSize());
    Path subdir = new Path(path, "sub-dir");
    hdfs.mkdirs(subdir);
    Path file = new Path(path, "file");
    hdfs.create(file).close();
    AclFeature aclFeature;
    {
        // create the snapshot with root directory having ACLs should refer to
        // same ACLFeature without incrementing the reference count
        aclFeature = FSAclBaseTest.getAclFeature(path, cluster);
        assertEquals("Reference count should be one before snapshot", 1, aclFeature.getRefCount());
        Path snapshotPath = SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);
        AclFeature snapshotAclFeature = FSAclBaseTest.getAclFeature(snapshotPath, cluster);
        assertSame(aclFeature, snapshotAclFeature);
        assertEquals("Reference count should be increased", 2, snapshotAclFeature.getRefCount());
    }
    {
        // deleting the snapshot with root directory having ACLs should not alter
        // the reference count of the ACLFeature
        deleteSnapshotWithAclAndVerify(aclFeature, path, startSize);
    }
    {
        hdfs.modifyAclEntries(subdir, aclSpec);
        aclFeature = FSAclBaseTest.getAclFeature(subdir, cluster);
        assertEquals("Reference count should be 1", 1, aclFeature.getRefCount());
        Path snapshotPath = SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);
        Path subdirInSnapshot = new Path(snapshotPath, "sub-dir");
        AclFeature snapshotAcl = FSAclBaseTest.getAclFeature(subdirInSnapshot, cluster);
        assertSame(aclFeature, snapshotAcl);
        assertEquals("Reference count should remain same", 1, aclFeature.getRefCount());
        // Delete the snapshot with sub-directory containing the ACLs should not
        // alter the reference count for AclFeature
        deleteSnapshotWithAclAndVerify(aclFeature, subdir, startSize);
    }
    {
        hdfs.modifyAclEntries(file, aclSpec);
        aclFeature = FSAclBaseTest.getAclFeature(file, cluster);
        assertEquals("Reference count should be 1", 1, aclFeature.getRefCount());
        Path snapshotPath = SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);
        Path fileInSnapshot = new Path(snapshotPath, file.getName());
        AclFeature snapshotAcl = FSAclBaseTest.getAclFeature(fileInSnapshot, cluster);
        assertSame(aclFeature, snapshotAcl);
        assertEquals("Reference count should remain same", 1, aclFeature.getRefCount());
        // Delete the snapshot with contained file having ACLs should not
        // alter the reference count for AclFeature
        deleteSnapshotWithAclAndVerify(aclFeature, file, startSize);
    }
    {
        // Modifying the ACLs of root directory of the snapshot should refer new
        // AclFeature. And old AclFeature should be referenced by snapshot
        hdfs.modifyAclEntries(path, aclSpec);
        Path snapshotPath = SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);
        AclFeature snapshotAcl = FSAclBaseTest.getAclFeature(snapshotPath, cluster);
        aclFeature = FSAclBaseTest.getAclFeature(path, cluster);
        assertEquals("Before modification same ACL should be referenced twice", 2, aclFeature.getRefCount());
        List<AclEntry> newAcl = Lists.newArrayList(aclEntry(ACCESS, USER, "testNewUser", ALL));
        hdfs.modifyAclEntries(path, newAcl);
        aclFeature = FSAclBaseTest.getAclFeature(path, cluster);
        AclFeature snapshotAclPostModification = FSAclBaseTest.getAclFeature(snapshotPath, cluster);
        assertSame(snapshotAcl, snapshotAclPostModification);
        assertNotSame(aclFeature, snapshotAclPostModification);
        assertEquals("Old ACL feature reference count should be same", 1, snapshotAcl.getRefCount());
        assertEquals("New ACL feature reference should be used", 1, aclFeature.getRefCount());
        deleteSnapshotWithAclAndVerify(aclFeature, path, startSize);
    }
    {
        // Modifying the ACLs of sub directory of the snapshot root should refer
        // new AclFeature. And old AclFeature should be referenced by snapshot
        hdfs.modifyAclEntries(subdir, aclSpec);
        Path snapshotPath = SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);
        Path subdirInSnapshot = new Path(snapshotPath, "sub-dir");
        AclFeature snapshotAclFeature = FSAclBaseTest.getAclFeature(subdirInSnapshot, cluster);
        List<AclEntry> newAcl = Lists.newArrayList(aclEntry(ACCESS, USER, "testNewUser", ALL));
        hdfs.modifyAclEntries(subdir, newAcl);
        aclFeature = FSAclBaseTest.getAclFeature(subdir, cluster);
        assertNotSame(aclFeature, snapshotAclFeature);
        assertEquals("Reference count should remain same", 1, snapshotAclFeature.getRefCount());
        assertEquals("New AclFeature should be used", 1, aclFeature.getRefCount());
        deleteSnapshotWithAclAndVerify(aclFeature, subdir, startSize);
    }
    {
        // Modifying the ACLs of file inside the snapshot root should refer new
        // AclFeature. And old AclFeature should be referenced by snapshot
        hdfs.modifyAclEntries(file, aclSpec);
        Path snapshotPath = SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);
        Path fileInSnapshot = new Path(snapshotPath, file.getName());
        AclFeature snapshotAclFeature = FSAclBaseTest.getAclFeature(fileInSnapshot, cluster);
        List<AclEntry> newAcl = Lists.newArrayList(aclEntry(ACCESS, USER, "testNewUser", ALL));
        hdfs.modifyAclEntries(file, newAcl);
        aclFeature = FSAclBaseTest.getAclFeature(file, cluster);
        assertNotSame(aclFeature, snapshotAclFeature);
        assertEquals("Reference count should remain same", 1, snapshotAclFeature.getRefCount());
        deleteSnapshotWithAclAndVerify(aclFeature, file, startSize);
    }
    {
        // deleting the original directory containing dirs and files with ACLs
        // with snapshot
        hdfs.delete(path, true);
        Path dir = new Path(subdir, "dir");
        hdfs.mkdirs(dir);
        hdfs.modifyAclEntries(dir, aclSpec);
        file = new Path(subdir, "file");
        hdfs.create(file).close();
        aclSpec.add(aclEntry(ACCESS, USER, "testNewUser", ALL));
        hdfs.modifyAclEntries(file, aclSpec);
        AclFeature fileAcl = FSAclBaseTest.getAclFeature(file, cluster);
        AclFeature dirAcl = FSAclBaseTest.getAclFeature(dir, cluster);
        Path snapshotPath = SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);
        Path dirInSnapshot = new Path(snapshotPath, "sub-dir/dir");
        AclFeature snapshotDirAclFeature = FSAclBaseTest.getAclFeature(dirInSnapshot, cluster);
        Path fileInSnapshot = new Path(snapshotPath, "sub-dir/file");
        AclFeature snapshotFileAclFeature = FSAclBaseTest.getAclFeature(fileInSnapshot, cluster);
        assertSame(fileAcl, snapshotFileAclFeature);
        assertSame(dirAcl, snapshotDirAclFeature);
        hdfs.delete(subdir, true);
        assertEquals("Original ACLs references should be maintained for snapshot", 1, snapshotFileAclFeature.getRefCount());
        assertEquals("Original ACLs references should be maintained for snapshot", 1, snapshotDirAclFeature.getRefCount());
        hdfs.deleteSnapshot(path, snapshotName);
        assertEquals("ACLs should be deleted from snapshot", startSize, AclStorage.getUniqueAclFeatures().getUniqueElementsSize());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AclEntry(org.apache.hadoop.fs.permission.AclEntry) AclFeature(org.apache.hadoop.hdfs.server.namenode.AclFeature) List(java.util.List) FSAclBaseTest(org.apache.hadoop.hdfs.server.namenode.FSAclBaseTest) Test(org.junit.Test)

Example 74 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class TestAclWithSnapshot method testOriginalAclEnforcedForSnapshotContentsAfterRemoval.

@Test
public void testOriginalAclEnforcedForSnapshotContentsAfterRemoval() throws Exception {
    Path filePath = new Path(path, "file1");
    Path subdirPath = new Path(path, "subdir1");
    Path fileSnapshotPath = new Path(snapshotPath, "file1");
    Path subdirSnapshotPath = new Path(snapshotPath, "subdir1");
    FileSystem.mkdirs(hdfs, path, FsPermission.createImmutable((short) 0777));
    FileSystem.create(hdfs, filePath, FsPermission.createImmutable((short) 0600)).close();
    FileSystem.mkdirs(hdfs, subdirPath, FsPermission.createImmutable((short) 0700));
    List<AclEntry> aclSpec = Lists.newArrayList(aclEntry(ACCESS, USER, READ_EXECUTE), aclEntry(ACCESS, USER, "bruce", READ_EXECUTE), aclEntry(ACCESS, GROUP, NONE), aclEntry(ACCESS, OTHER, NONE));
    hdfs.setAcl(filePath, aclSpec);
    hdfs.setAcl(subdirPath, aclSpec);
    assertFilePermissionGranted(fsAsBruce, BRUCE, filePath);
    assertFilePermissionDenied(fsAsDiana, DIANA, filePath);
    assertDirPermissionGranted(fsAsBruce, BRUCE, subdirPath);
    assertDirPermissionDenied(fsAsDiana, DIANA, subdirPath);
    SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);
    // Both original and snapshot still have same ACL.
    AclEntry[] expected = new AclEntry[] { aclEntry(ACCESS, USER, "bruce", READ_EXECUTE), aclEntry(ACCESS, GROUP, NONE) };
    AclStatus s = hdfs.getAclStatus(filePath);
    AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(expected, returned);
    assertPermission((short) 010550, filePath);
    s = hdfs.getAclStatus(subdirPath);
    returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(expected, returned);
    assertPermission((short) 010550, subdirPath);
    s = hdfs.getAclStatus(fileSnapshotPath);
    returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(expected, returned);
    assertPermission((short) 010550, fileSnapshotPath);
    assertFilePermissionGranted(fsAsBruce, BRUCE, fileSnapshotPath);
    assertFilePermissionDenied(fsAsDiana, DIANA, fileSnapshotPath);
    s = hdfs.getAclStatus(subdirSnapshotPath);
    returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(expected, returned);
    assertPermission((short) 010550, subdirSnapshotPath);
    assertDirPermissionGranted(fsAsBruce, BRUCE, subdirSnapshotPath);
    assertDirPermissionDenied(fsAsDiana, DIANA, subdirSnapshotPath);
    hdfs.removeAcl(filePath);
    hdfs.removeAcl(subdirPath);
    // Original has changed, but snapshot still has old ACL.
    doSnapshotContentsRemovalAssertions(filePath, fileSnapshotPath, subdirPath, subdirSnapshotPath);
    restart(false);
    doSnapshotContentsRemovalAssertions(filePath, fileSnapshotPath, subdirPath, subdirSnapshotPath);
    restart(true);
    doSnapshotContentsRemovalAssertions(filePath, fileSnapshotPath, subdirPath, subdirSnapshotPath);
}
Also used : Path(org.apache.hadoop.fs.Path) AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) FSAclBaseTest(org.apache.hadoop.hdfs.server.namenode.FSAclBaseTest) Test(org.junit.Test)

Example 75 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class TestAclWithSnapshot method testOriginalAclEnforcedForSnapshotContentsAfterChange.

@Test
public void testOriginalAclEnforcedForSnapshotContentsAfterChange() throws Exception {
    Path filePath = new Path(path, "file1");
    Path subdirPath = new Path(path, "subdir1");
    Path fileSnapshotPath = new Path(snapshotPath, "file1");
    Path subdirSnapshotPath = new Path(snapshotPath, "subdir1");
    FileSystem.mkdirs(hdfs, path, FsPermission.createImmutable((short) 0777));
    FileSystem.create(hdfs, filePath, FsPermission.createImmutable((short) 0600)).close();
    FileSystem.mkdirs(hdfs, subdirPath, FsPermission.createImmutable((short) 0700));
    List<AclEntry> aclSpec = Lists.newArrayList(aclEntry(ACCESS, USER, READ_EXECUTE), aclEntry(ACCESS, USER, "bruce", READ_EXECUTE), aclEntry(ACCESS, GROUP, NONE), aclEntry(ACCESS, OTHER, NONE));
    hdfs.setAcl(filePath, aclSpec);
    hdfs.setAcl(subdirPath, aclSpec);
    assertFilePermissionGranted(fsAsBruce, BRUCE, filePath);
    assertFilePermissionDenied(fsAsDiana, DIANA, filePath);
    assertDirPermissionGranted(fsAsBruce, BRUCE, subdirPath);
    assertDirPermissionDenied(fsAsDiana, DIANA, subdirPath);
    SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);
    // Both original and snapshot still have same ACL.
    AclEntry[] expected = new AclEntry[] { aclEntry(ACCESS, USER, "bruce", READ_EXECUTE), aclEntry(ACCESS, GROUP, NONE) };
    AclStatus s = hdfs.getAclStatus(filePath);
    AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(expected, returned);
    assertPermission((short) 010550, filePath);
    s = hdfs.getAclStatus(subdirPath);
    returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(expected, returned);
    assertPermission((short) 010550, subdirPath);
    s = hdfs.getAclStatus(fileSnapshotPath);
    returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(expected, returned);
    assertPermission((short) 010550, fileSnapshotPath);
    assertFilePermissionGranted(fsAsBruce, BRUCE, fileSnapshotPath);
    assertFilePermissionDenied(fsAsDiana, DIANA, fileSnapshotPath);
    s = hdfs.getAclStatus(subdirSnapshotPath);
    returned = s.getEntries().toArray(new AclEntry[0]);
    assertArrayEquals(expected, returned);
    assertPermission((short) 010550, subdirSnapshotPath);
    assertDirPermissionGranted(fsAsBruce, BRUCE, subdirSnapshotPath);
    assertDirPermissionDenied(fsAsDiana, DIANA, subdirSnapshotPath);
    aclSpec = Lists.newArrayList(aclEntry(ACCESS, USER, READ_EXECUTE), aclEntry(ACCESS, USER, "diana", ALL), aclEntry(ACCESS, GROUP, NONE), aclEntry(ACCESS, OTHER, NONE));
    hdfs.setAcl(filePath, aclSpec);
    hdfs.setAcl(subdirPath, aclSpec);
    // Original has changed, but snapshot still has old ACL.
    doSnapshotContentsChangeAssertions(filePath, fileSnapshotPath, subdirPath, subdirSnapshotPath);
    restart(false);
    doSnapshotContentsChangeAssertions(filePath, fileSnapshotPath, subdirPath, subdirSnapshotPath);
    restart(true);
    doSnapshotContentsChangeAssertions(filePath, fileSnapshotPath, subdirPath, subdirSnapshotPath);
}
Also used : Path(org.apache.hadoop.fs.Path) AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) FSAclBaseTest(org.apache.hadoop.hdfs.server.namenode.FSAclBaseTest) Test(org.junit.Test)

Aggregations

AclEntry (org.apache.hadoop.fs.permission.AclEntry)137 Test (org.junit.Test)90 AclStatus (org.apache.hadoop.fs.permission.AclStatus)81 Path (org.apache.hadoop.fs.Path)52 FsPermission (org.apache.hadoop.fs.permission.FsPermission)25 ArrayList (java.util.ArrayList)11 FSAclBaseTest (org.apache.hadoop.hdfs.server.namenode.FSAclBaseTest)11 FileSystem (org.apache.hadoop.fs.FileSystem)10 Configuration (org.apache.hadoop.conf.Configuration)7 FileStatus (org.apache.hadoop.fs.FileStatus)6 MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)5 ScopedAclEntries (org.apache.hadoop.fs.permission.ScopedAclEntries)5 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)5 DatanodeInfoBuilder (org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder)5 IOException (java.io.IOException)4 List (java.util.List)4 AclEntryScope (org.apache.hadoop.fs.permission.AclEntryScope)4 AclEntryProto (org.apache.hadoop.hdfs.protocol.proto.AclProtos.AclEntryProto)4 URI (java.net.URI)3 AclEntryType (org.apache.hadoop.fs.permission.AclEntryType)3