From ef1cc725b8c1301f33bcb80b63b12d45dc23bed8 Mon Sep 17 00:00:00 2001
From: Ajay Yadav <7813154+ajayydv@users.noreply.github.com>
Date: Tue, 21 May 2019 15:53:40 -0700
Subject: [PATCH] HDDS-1538. Update ozone protobuf message for ACLs.
Contributed by Ajay Kumar. (#828)
---
.../org/apache/hadoop/ozone/OzoneConsts.java | 3 +-
.../src/main/resources/ozone-default.xml | 18 +--
.../hadoop/ozone/client/rest/RestClient.java | 6 +-
.../hadoop/ozone/client/rpc/RpcClient.java | 25 ++--
.../org/apache/hadoop/ozone/OzoneAcl.java | 112 +++++++-----------
.../apache/hadoop/ozone/om/OMConfigKeys.java | 12 --
.../ozone/om/helpers/OmOzoneAclMap.java | 60 +++++++---
.../hadoop/ozone/protocolPB/OMPBHelper.java | 67 ++++++-----
.../ozone/security/acl/IAccessAuthorizer.java | 20 +++-
.../ozone/security/acl/OzoneAclConfig.java | 65 ++++++++++
.../src/main/proto/OzoneManagerProtocol.proto | 17 ++-
.../apache/hadoop/ozone/TestOzoneAcls.java | 79 ++++++++----
.../rpc/TestOzoneRpcClientAbstract.java | 20 ++--
.../hadoop/ozone/om/TestOzoneManager.java | 21 ++--
.../hadoop/ozone/ozShell/TestOzoneShell.java | 13 +-
.../storage/DistributedStorageHandler.java | 21 ++--
.../hadoop/ozone/om/VolumeManagerImpl.java | 4 +-
.../ozone/om/TestBucketManagerImpl.java | 18 +--
.../apache/hadoop/ozone/scm/cli/SQLCLI.java | 2 +-
19 files changed, 339 insertions(+), 244 deletions(-)
rename {hadoop-hdds => hadoop-ozone}/common/src/main/java/org/apache/hadoop/ozone/OzoneAcl.java (63%)
create mode 100644 hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/acl/OzoneAclConfig.java
rename {hadoop-hdds => hadoop-ozone}/common/src/test/java/org/apache/hadoop/ozone/TestOzoneAcls.java (57%)
diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java
index ce1e97e34d..4f249f854b 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java
@@ -52,12 +52,11 @@ public final class OzoneConsts {
public static final String OZONE_ACL_USER_TYPE = "user";
public static final String OZONE_ACL_GROUP_TYPE = "group";
public static final String OZONE_ACL_WORLD_TYPE = "world";
+ public static final String OZONE_ACL_ANONYMOUS_TYPE = "anonymous";
public static final String OZONE_ACL_IP_TYPE = "ip";
public static final String OZONE_ACL_READ = "r";
public static final String OZONE_ACL_WRITE = "w";
- public static final String OZONE_ACL_READ_WRITE = "rw";
- public static final String OZONE_ACL_WRITE_READ = "wr";
public static final String OZONE_ACL_DELETE = "d";
public static final String OZONE_ACL_LIST = "l";
public static final String OZONE_ACL_ALL = "a";
diff --git a/hadoop-hdds/common/src/main/resources/ozone-default.xml b/hadoop-hdds/common/src/main/resources/ozone-default.xml
index a46ddb16a8..305cac5a2c 100644
--- a/hadoop-hdds/common/src/main/resources/ozone-default.xml
+++ b/hadoop-hdds/common/src/main/resources/ozone-default.xml
@@ -540,14 +540,6 @@
the address of the OM.
-
- ozone.om.group.rights
- READ_WRITE
- OM, SECURITY
-
- Default group permissions in Ozone OM.
-
-
ozone.om.handler.count.key
20
@@ -640,14 +632,6 @@
of buckets or keys inside each bucket a user can create.
-
- ozone.om.user.rights
- READ_WRITE
- OM, SECURITY
-
- Default user permissions used in OM.
-
-
ozone.om.db.dirs
@@ -1809,7 +1793,7 @@
assumed.
-
+
hdds.block.token.enabled
false
diff --git a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rest/RestClient.java b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rest/RestClient.java
index 2f37713159..71fb8ca8c6 100644
--- a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rest/RestClient.java
+++ b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rest/RestClient.java
@@ -112,7 +112,7 @@ public class RestClient implements ClientProtocol {
private final URI ozoneRestUri;
private final CloseableHttpClient httpClient;
private final UserGroupInformation ugi;
- private final OzoneAcl.OzoneACLRights userRights;
+ // private final OzoneAcl.OzoneACLRights userRights;
/**
* Creates RestClient instance with the given configuration.
@@ -161,8 +161,8 @@ public RestClient(Configuration conf)
.build())
.build();
- this.userRights = conf.getEnum(OMConfigKeys.OZONE_OM_USER_RIGHTS,
- OMConfigKeys.OZONE_OM_USER_RIGHTS_DEFAULT);
+// this.userRights = conf.getEnum(OMConfigKeys.OZONE_OM_USER_RIGHTS,
+// OMConfigKeys.OZONE_OM_USER_RIGHTS_DEFAULT);
// TODO: Add new configuration parameter to configure RestServerSelector.
RestServerSelector defaultSelector = new DefaultRestServerSelector();
diff --git a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
index ab40c5231a..3aa4fb8e63 100644
--- a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
+++ b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
@@ -73,7 +73,6 @@
.OzoneManagerProtocolClientSideTranslatorPB;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.ozone.OzoneAcl;
-import org.apache.hadoop.ozone.om.OMConfigKeys;
import org.apache.hadoop.ozone.protocol.proto
.OzoneManagerProtocolProtos.ServicePort;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
@@ -85,6 +84,9 @@
import org.apache.hadoop.hdds.scm.protocolPB
.StorageContainerLocationProtocolPB;
import org.apache.hadoop.ozone.security.OzoneTokenIdentifier;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType;
+import org.apache.hadoop.ozone.security.acl.OzoneAclConfig;
import org.apache.hadoop.ozone.web.utils.OzoneUtils;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.token.Token;
@@ -121,8 +123,8 @@ public class RpcClient implements ClientProtocol, KeyProviderTokenIssuer {
private final int bytesPerChecksum;
private boolean verifyChecksum;
private final UserGroupInformation ugi;
- private final OzoneAcl.OzoneACLRights userRights;
- private final OzoneAcl.OzoneACLRights groupRights;
+ private final ACLType userRights;
+ private final ACLType groupRights;
private final long streamBufferFlushSize;
private final long streamBufferMaxSize;
private final long blockSize;
@@ -141,10 +143,11 @@ public RpcClient(Configuration conf) throws IOException {
Preconditions.checkNotNull(conf);
this.conf = new OzoneConfiguration(conf);
this.ugi = UserGroupInformation.getCurrentUser();
- this.userRights = conf.getEnum(OMConfigKeys.OZONE_OM_USER_RIGHTS,
- OMConfigKeys.OZONE_OM_USER_RIGHTS_DEFAULT);
- this.groupRights = conf.getEnum(OMConfigKeys.OZONE_OM_GROUP_RIGHTS,
- OMConfigKeys.OZONE_OM_GROUP_RIGHTS_DEFAULT);
+ // Get default acl rights for user and group.
+ OzoneAclConfig aclConfig = this.conf.getObject(OzoneAclConfig.class);
+ this.userRights = aclConfig.getUserDefaultRights();
+ this.groupRights = aclConfig.getGroupDefaultRights();
+
this.ozoneManagerClient = new OzoneManagerProtocolClientSideTranslatorPB(
this.conf, clientId.toString(), ugi);
long scmVersion =
@@ -256,13 +259,13 @@ public void createVolume(String volumeName, VolumeArgs volArgs)
OzoneQuota.parseQuota(volArgs.getQuota()).sizeInBytes();
List listOfAcls = new ArrayList<>();
//User ACL
- listOfAcls.add(new OzoneAcl(OzoneAcl.OzoneACLType.USER,
+ listOfAcls.add(new OzoneAcl(ACLIdentityType.USER,
owner, userRights));
//Group ACLs of the User
List userGroups = Arrays.asList(UserGroupInformation
.createRemoteUser(owner).getGroupNames());
userGroups.stream().forEach((group) -> listOfAcls.add(
- new OzoneAcl(OzoneAcl.OzoneACLType.GROUP, group, groupRights)));
+ new OzoneAcl(ACLIdentityType.GROUP, group, groupRights)));
//ACLs from VolumeArgs
if(volArgs.getAcls() != null) {
listOfAcls.addAll(volArgs.getAcls());
@@ -403,13 +406,13 @@ public void createBucket(
List listOfAcls = new ArrayList<>();
//User ACL
- listOfAcls.add(new OzoneAcl(OzoneAcl.OzoneACLType.USER,
+ listOfAcls.add(new OzoneAcl(ACLIdentityType.USER,
ugi.getUserName(), userRights));
//Group ACLs of the User
List userGroups = Arrays.asList(UserGroupInformation
.createRemoteUser(ugi.getUserName()).getGroupNames());
userGroups.stream().forEach((group) -> listOfAcls.add(
- new OzoneAcl(OzoneAcl.OzoneACLType.GROUP, group, groupRights)));
+ new OzoneAcl(ACLIdentityType.GROUP, group, groupRights)));
//ACLs from BucketArgs
if(bucketArgs.getAcls() != null) {
listOfAcls.addAll(bucketArgs.getAcls());
diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneAcl.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OzoneAcl.java
similarity index 63%
rename from hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneAcl.java
rename to hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OzoneAcl.java
index 1827b23bf1..eaec507314 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneAcl.java
+++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OzoneAcl.java
@@ -19,6 +19,11 @@
package org.apache.hadoop.ozone;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType;
+
+import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
/**
@@ -32,9 +37,9 @@
*
*/
public class OzoneAcl {
- private OzoneACLType type;
+ private ACLIdentityType type;
private String name;
- private OzoneACLRights rights;
+ private List rights;
/**
* Constructor for OzoneAcl.
@@ -47,16 +52,37 @@ public OzoneAcl() {
*
* @param type - Type
* @param name - Name of user
- * @param rights - Rights
+ * @param acl - Rights
*/
- public OzoneAcl(OzoneACLType type, String name, OzoneACLRights rights) {
+ public OzoneAcl(ACLIdentityType type, String name, ACLType acl) {
this.name = name;
- this.rights = rights;
+ this.rights = new ArrayList<>();
+ this.rights.add(acl);
this.type = type;
- if (type == OzoneACLType.WORLD && name.length() != 0) {
+ if (type == ACLIdentityType.WORLD && name.length() != 0) {
throw new IllegalArgumentException("Unexpected name part in world type");
}
- if (((type == OzoneACLType.USER) || (type == OzoneACLType.GROUP))
+ if (((type == ACLIdentityType.USER) || (type == ACLIdentityType.GROUP))
+ && (name.length() == 0)) {
+ throw new IllegalArgumentException("User or group name is required");
+ }
+ }
+
+ /**
+ * Constructor for OzoneAcl.
+ *
+ * @param type - Type
+ * @param name - Name of user
+ * @param acls - Rights
+ */
+ public OzoneAcl(ACLIdentityType type, String name, List acls) {
+ this.name = name;
+ this.rights = acls;
+ this.type = type;
+ if (type == ACLIdentityType.WORLD && name.length() != 0) {
+ throw new IllegalArgumentException("Unexpected name part in world type");
+ }
+ if (((type == ACLIdentityType.USER) || (type == ACLIdentityType.GROUP))
&& (name.length() == 0)) {
throw new IllegalArgumentException("User or group name is required");
}
@@ -78,17 +104,20 @@ public static OzoneAcl parseAcl(String acl) throws IllegalArgumentException {
throw new IllegalArgumentException("ACLs are not in expected format");
}
- OzoneACLType aclType = OzoneACLType.valueOf(parts[0].toUpperCase());
- OzoneACLRights rights = OzoneACLRights.getACLRight(parts[2].toLowerCase());
+ ACLIdentityType aclType = ACLIdentityType.valueOf(parts[0].toUpperCase());
+ List acls = new ArrayList<>();
+ for (char ch : parts[2].toCharArray()) {
+ acls.add(ACLType.getACLRight(String.valueOf(ch)));
+ }
// TODO : Support sanitation of these user names by calling into
// userAuth Interface.
- return new OzoneAcl(aclType, parts[1], rights);
+ return new OzoneAcl(aclType, parts[1], acls);
}
@Override
public String toString() {
- return type + ":" + name + ":" + OzoneACLRights.getACLRightsString(rights);
+ return type + ":" + name + ":" + ACLType.getACLString(rights);
}
/**
@@ -120,7 +149,7 @@ public String getName() {
*
* @return - Rights
*/
- public OzoneACLRights getRights() {
+ public List getRights() {
return rights;
}
@@ -129,7 +158,7 @@ public OzoneACLRights getRights() {
*
* @return type
*/
- public OzoneACLType getType() {
+ public ACLIdentityType getType() {
return type;
}
@@ -150,9 +179,7 @@ public boolean equals(Object obj) {
return false;
}
OzoneAcl otherAcl = (OzoneAcl) obj;
- return otherAcl.getName().equals(this.getName()) &&
- otherAcl.getRights() == this.getRights() &&
- otherAcl.getType() == this.getType();
+ return otherAcl.toString().equals(this.toString());
}
/**
@@ -177,57 +204,4 @@ public enum OzoneACLType {
value = val;
}
}
-
- /**
- * ACL rights.
- */
- public enum OzoneACLRights {
- READ, WRITE, READ_WRITE;
-
- /**
- * Returns the ACL rights based on passed in String.
- *
- * @param type ACL right string
- *
- * @return OzoneACLRights
- */
- public static OzoneACLRights getACLRight(String type) {
- if (type == null || type.isEmpty()) {
- throw new IllegalArgumentException("ACL right cannot be empty");
- }
-
- switch (type) {
- case OzoneConsts.OZONE_ACL_READ:
- return OzoneACLRights.READ;
- case OzoneConsts.OZONE_ACL_WRITE:
- return OzoneACLRights.WRITE;
- case OzoneConsts.OZONE_ACL_READ_WRITE:
- case OzoneConsts.OZONE_ACL_WRITE_READ:
- return OzoneACLRights.READ_WRITE;
- default:
- throw new IllegalArgumentException("ACL right is not recognized");
- }
-
- }
-
- /**
- * Returns String representation of ACL rights.
- * @param acl OzoneACLRights
- * @return String representation of acl
- */
- public static String getACLRightsString(OzoneACLRights acl) {
- switch(acl) {
- case READ:
- return OzoneConsts.OZONE_ACL_READ;
- case WRITE:
- return OzoneConsts.OZONE_ACL_WRITE;
- case READ_WRITE:
- return OzoneConsts.OZONE_ACL_READ_WRITE;
- default:
- throw new IllegalArgumentException("ACL right is not recognized");
- }
- }
-
- }
-
}
diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OMConfigKeys.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OMConfigKeys.java
index 60dde44119..5f1f579f6d 100644
--- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OMConfigKeys.java
+++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OMConfigKeys.java
@@ -19,7 +19,6 @@
import java.util.concurrent.TimeUnit;
-import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.ratis.util.TimeDuration;
/**
@@ -78,17 +77,6 @@ private OMConfigKeys() {
"ozone.om.user.max.volume";
public static final int OZONE_OM_USER_MAX_VOLUME_DEFAULT = 1024;
- // OM Default user/group permissions
- public static final String OZONE_OM_USER_RIGHTS =
- "ozone.om.user.rights";
- public static final OzoneAcl.OzoneACLRights OZONE_OM_USER_RIGHTS_DEFAULT =
- OzoneAcl.OzoneACLRights.READ_WRITE;
-
- public static final String OZONE_OM_GROUP_RIGHTS =
- "ozone.om.group.rights";
- public static final OzoneAcl.OzoneACLRights OZONE_OM_GROUP_RIGHTS_DEFAULT =
- OzoneAcl.OzoneACLRights.READ_WRITE;
-
public static final String OZONE_KEY_DELETING_LIMIT_PER_TASK =
"ozone.key.deleting.limit.per.task";
public static final int OZONE_KEY_DELETING_LIMIT_PER_TASK_DEFAULT = 1000;
diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmOzoneAclMap.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmOzoneAclMap.java
index 2584eb58c2..8831c6b879 100644
--- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmOzoneAclMap.java
+++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmOzoneAclMap.java
@@ -37,7 +37,7 @@
@SuppressWarnings("ProtocolBufferOrdinal")
public class OmOzoneAclMap {
// per Acl Type user:rights map
- private ArrayList