Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*/
package org.apache.hadoop.ozone.om;

import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.StorageType;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.client.BucketArgs;
import org.apache.hadoop.ozone.client.ObjectStore;
Expand All @@ -31,19 +29,17 @@
import org.apache.hadoop.ozone.security.acl.OzoneObj;
import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;
import org.apache.hadoop.security.UserGroupInformation;
import org.junit.jupiter.api.AfterAll;
import org.apache.ozone.test.AclTests;
import org.apache.ozone.test.NonHATests;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.UUID;

import static org.apache.hadoop.ozone.OzoneAcl.AclScope.DEFAULT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_AUTHORIZER_CLASS;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_AUTHORIZER_CLASS_NATIVE;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_ENABLED;
import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType.USER;
import static org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType.OZONE;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -52,63 +48,48 @@
/**
* Test for Ozone Bucket Owner.
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Timeout(120)
public class TestBucketOwner {
public abstract class TestBucketOwner implements NonHATests.TestCase {

private static MiniOzoneCluster cluster;
private static final Logger LOG =
LoggerFactory.getLogger(TestBucketOwner.class);
private static UserGroupInformation adminUser =
UserGroupInformation.createUserForTesting("om", new String[]{"ozone"});
private static final String UNIQUE = UUID.randomUUID().toString();
private static final String VOLUME_NAME = "vol-" + UNIQUE;
private static UserGroupInformation user1 = UserGroupInformation
.createUserForTesting("user1", new String[] {"test1"});
.createUserForTesting("user-" + UNIQUE + 1, new String[] {"test1"});
private static UserGroupInformation user2 = UserGroupInformation
.createUserForTesting("user2", new String[] {"test2"});
.createUserForTesting("user-" + UNIQUE + 2, new String[] {"test2"});
private static UserGroupInformation user3 = UserGroupInformation
.createUserForTesting("user3", new String[] {"test3"});
.createUserForTesting("user-" + UNIQUE + 3, new String[] {"test3"});

@BeforeAll
public static void init() throws Exception {
// loginUser is the user running this test.
UserGroupInformation.setLoginUser(adminUser);
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(OZONE_ACL_AUTHORIZER_CLASS, OZONE_ACL_AUTHORIZER_CLASS_NATIVE);
conf.setBoolean(OZONE_ACL_ENABLED, true);
cluster = MiniOzoneCluster.newBuilder(conf).build();
cluster.waitForClusterToBeReady();
try (OzoneClient client = cluster.newClient()) {
void init() throws Exception {
UserGroupInformation.setLoginUser(AclTests.ADMIN_UGI);
try (OzoneClient client = cluster().newClient()) {
ObjectStore objectStore = client.getObjectStore();
/* r = READ, w = WRITE, c = CREATE, d = DELETE
l = LIST, a = ALL, n = NONE, x = READ_ACL, y = WRITE_ACL */
String aclWorldAll = "world::a";
createVolumeWithOwnerAndAcl(objectStore, "volume1", "user2", aclWorldAll);
createVolumeWithOwnerAndAcl(objectStore, VOLUME_NAME, user2.getShortUserName(), aclWorldAll);
}
UserGroupInformation.setLoginUser(user1);
try (OzoneClient client = cluster.newClient()) {
try (OzoneClient client = cluster().newClient()) {
ObjectStore objectStore = client.getObjectStore();
OzoneVolume volume = objectStore.getVolume("volume1");
OzoneVolume volume = objectStore.getVolume(VOLUME_NAME);
BucketArgs omBucketArgs = BucketArgs.newBuilder()
.setStorageType(StorageType.DISK).setOwner("user1").build();
.setStorageType(StorageType.DISK).setOwner(user1.getShortUserName()).build();
volume.createBucket("bucket1", omBucketArgs);
volume.createBucket("bucket2", omBucketArgs);
volume.createBucket("bucket3", omBucketArgs);
}
}

@AfterAll
public static void stopCluster() {
if (cluster != null) {
cluster.shutdown();
}
}

@Test
public void testBucketOwner() throws Exception {
// Test Key Operations as Bucket Owner, Non-Volume Owner
UserGroupInformation.setLoginUser(user1);
try (OzoneClient client = cluster.newClient()) {
try (OzoneClient client = cluster().newClient()) {
OzoneVolume volume = client.getObjectStore()
.getVolume("volume1");
.getVolume(VOLUME_NAME);
OzoneBucket ozoneBucket = volume.getBucket("bucket1");
//Key Create
createKey(ozoneBucket, "key1", 10, new byte[10]);
Expand All @@ -133,50 +114,50 @@ public void testNonBucketNonVolumeOwner() throws Exception {
// Test Key Operations Non-Bucket Owner, Non-Volume Owner
//Key Create
UserGroupInformation.setLoginUser(user3);
try (OzoneClient client = cluster.newClient()) {
try (OzoneClient client = cluster().newClient()) {
assertThrows(Exception.class, () -> {
OzoneVolume volume = client.getObjectStore().getVolume("volume1");
OzoneVolume volume = client.getObjectStore().getVolume(VOLUME_NAME);
OzoneBucket ozoneBucket = volume.getBucket("bucket1");
createKey(ozoneBucket, "key3", 10, new byte[10]);
}, "Create key as non-volume and non-bucket owner should fail");
}
//Key Delete - should fail
try (OzoneClient client = cluster.newClient()) {
try (OzoneClient client = cluster().newClient()) {
assertThrows(Exception.class, () -> {
OzoneVolume volume = client.getObjectStore().getVolume("volume1");
OzoneVolume volume = client.getObjectStore().getVolume(VOLUME_NAME);
OzoneBucket ozoneBucket = volume.getBucket("bucket1");
ozoneBucket.deleteKey("key2");
}, "Delete key as non-volume and non-bucket owner should fail");
}
//Key Rename - should fail
try (OzoneClient client = cluster.newClient()) {
try (OzoneClient client = cluster().newClient()) {
assertThrows(Exception.class, () -> {
OzoneVolume volume = client.getObjectStore().getVolume("volume1");
OzoneVolume volume = client.getObjectStore().getVolume(VOLUME_NAME);
OzoneBucket ozoneBucket = volume.getBucket("bucket1");
ozoneBucket.renameKey("key2", "key4");
}, "Rename key as non-volume and non-bucket owner should fail");
}
//List Keys - should fail
try (OzoneClient client = cluster.newClient()) {
try (OzoneClient client = cluster().newClient()) {
assertThrows(Exception.class, () -> {
OzoneVolume volume = client.getObjectStore().getVolume("volume1");
OzoneVolume volume = client.getObjectStore().getVolume(VOLUME_NAME);
OzoneBucket ozoneBucket = volume.getBucket("bucket1");
ozoneBucket.listKeys("key");
}, "List keys as non-volume and non-bucket owner should fail");
}
//Get Acls - should fail
try (OzoneClient client = cluster.newClient()) {
try (OzoneClient client = cluster().newClient()) {
assertThrows(Exception.class, () -> {
OzoneVolume volume = client.getObjectStore().getVolume("volume1");
OzoneVolume volume = client.getObjectStore().getVolume(VOLUME_NAME);
OzoneBucket ozoneBucket = volume.getBucket("bucket1");
ozoneBucket.getAcls();
}, "Get Acls as non-volume and non-bucket owner should fail");
}

//Add Acls - should fail
try (OzoneClient client = cluster.newClient()) {
try (OzoneClient client = cluster().newClient()) {
assertThrows(Exception.class, () -> {
OzoneVolume volume = client.getObjectStore().getVolume("volume1");
OzoneVolume volume = client.getObjectStore().getVolume(VOLUME_NAME);
OzoneBucket ozoneBucket = volume.getBucket("bucket1");
OzoneAcl acl = new OzoneAcl(USER, "testuser1",
DEFAULT, IAccessAuthorizer.ACLType.ALL);
Expand All @@ -189,8 +170,8 @@ public void testNonBucketNonVolumeOwner() throws Exception {
public void testVolumeOwner() throws Exception {
//Test Key Operations for Volume Owner
UserGroupInformation.setLoginUser(user2);
try (OzoneClient client = cluster.newClient()) {
OzoneVolume volume = client.getObjectStore().getVolume("volume1");
try (OzoneClient client = cluster().newClient()) {
OzoneVolume volume = client.getObjectStore().getVolume(VOLUME_NAME);
OzoneBucket ozoneBucket = volume.getBucket("bucket1");
//Key Create
createKey(ozoneBucket, "key2", 10, new byte[10]);
Expand Down
Loading