Skip to content

Commit ef1cc72

Browse files
authored
HDDS-1538. Update ozone protobuf message for ACLs. Contributed by Ajay Kumar. (#828)
1 parent a85451c commit ef1cc72

File tree

19 files changed

+338
-243
lines changed

19 files changed

+338
-243
lines changed

hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ public final class OzoneConsts {
5252
public static final String OZONE_ACL_USER_TYPE = "user";
5353
public static final String OZONE_ACL_GROUP_TYPE = "group";
5454
public static final String OZONE_ACL_WORLD_TYPE = "world";
55+
public static final String OZONE_ACL_ANONYMOUS_TYPE = "anonymous";
5556
public static final String OZONE_ACL_IP_TYPE = "ip";
5657

5758
public static final String OZONE_ACL_READ = "r";
5859
public static final String OZONE_ACL_WRITE = "w";
59-
public static final String OZONE_ACL_READ_WRITE = "rw";
60-
public static final String OZONE_ACL_WRITE_READ = "wr";
6160
public static final String OZONE_ACL_DELETE = "d";
6261
public static final String OZONE_ACL_LIST = "l";
6362
public static final String OZONE_ACL_ALL = "a";

hadoop-hdds/common/src/main/resources/ozone-default.xml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -540,14 +540,6 @@
540540
the address of the OM.
541541
</description>
542542
</property>
543-
<property>
544-
<name>ozone.om.group.rights</name>
545-
<value>READ_WRITE</value>
546-
<tag>OM, SECURITY</tag>
547-
<description>
548-
Default group permissions in Ozone OM.
549-
</description>
550-
</property>
551543
<property>
552544
<name>ozone.om.handler.count.key</name>
553545
<value>20</value>
@@ -640,14 +632,6 @@
640632
of buckets or keys inside each bucket a user can create.
641633
</description>
642634
</property>
643-
<property>
644-
<name>ozone.om.user.rights</name>
645-
<value>READ_WRITE</value>
646-
<tag>OM, SECURITY</tag>
647-
<description>
648-
Default user permissions used in OM.
649-
</description>
650-
</property>
651635
<property>
652636
<name>ozone.om.db.dirs</name>
653637
<value/>
@@ -1809,7 +1793,7 @@
18091793
assumed.
18101794
</description>
18111795
</property>
1812-
1796+
18131797
<property>
18141798
<name>hdds.block.token.enabled</name>
18151799
<value>false</value>

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rest/RestClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public class RestClient implements ClientProtocol {
112112
private final URI ozoneRestUri;
113113
private final CloseableHttpClient httpClient;
114114
private final UserGroupInformation ugi;
115-
private final OzoneAcl.OzoneACLRights userRights;
115+
// private final OzoneAcl.OzoneACLRights userRights;
116116

117117
/**
118118
* Creates RestClient instance with the given configuration.
@@ -161,8 +161,8 @@ public RestClient(Configuration conf)
161161
.build())
162162
.build();
163163

164-
this.userRights = conf.getEnum(OMConfigKeys.OZONE_OM_USER_RIGHTS,
165-
OMConfigKeys.OZONE_OM_USER_RIGHTS_DEFAULT);
164+
// this.userRights = conf.getEnum(OMConfigKeys.OZONE_OM_USER_RIGHTS,
165+
// OMConfigKeys.OZONE_OM_USER_RIGHTS_DEFAULT);
166166

167167
// TODO: Add new configuration parameter to configure RestServerSelector.
168168
RestServerSelector defaultSelector = new DefaultRestServerSelector();

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
.OzoneManagerProtocolClientSideTranslatorPB;
7474
import org.apache.hadoop.net.NetUtils;
7575
import org.apache.hadoop.ozone.OzoneAcl;
76-
import org.apache.hadoop.ozone.om.OMConfigKeys;
7776
import org.apache.hadoop.ozone.protocol.proto
7877
.OzoneManagerProtocolProtos.ServicePort;
7978
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
@@ -85,6 +84,9 @@
8584
import org.apache.hadoop.hdds.scm.protocolPB
8685
.StorageContainerLocationProtocolPB;
8786
import org.apache.hadoop.ozone.security.OzoneTokenIdentifier;
87+
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType;
88+
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType;
89+
import org.apache.hadoop.ozone.security.acl.OzoneAclConfig;
8890
import org.apache.hadoop.ozone.web.utils.OzoneUtils;
8991
import org.apache.hadoop.security.UserGroupInformation;
9092
import org.apache.hadoop.security.token.Token;
@@ -121,8 +123,8 @@ public class RpcClient implements ClientProtocol, KeyProviderTokenIssuer {
121123
private final int bytesPerChecksum;
122124
private boolean verifyChecksum;
123125
private final UserGroupInformation ugi;
124-
private final OzoneAcl.OzoneACLRights userRights;
125-
private final OzoneAcl.OzoneACLRights groupRights;
126+
private final ACLType userRights;
127+
private final ACLType groupRights;
126128
private final long streamBufferFlushSize;
127129
private final long streamBufferMaxSize;
128130
private final long blockSize;
@@ -141,10 +143,11 @@ public RpcClient(Configuration conf) throws IOException {
141143
Preconditions.checkNotNull(conf);
142144
this.conf = new OzoneConfiguration(conf);
143145
this.ugi = UserGroupInformation.getCurrentUser();
144-
this.userRights = conf.getEnum(OMConfigKeys.OZONE_OM_USER_RIGHTS,
145-
OMConfigKeys.OZONE_OM_USER_RIGHTS_DEFAULT);
146-
this.groupRights = conf.getEnum(OMConfigKeys.OZONE_OM_GROUP_RIGHTS,
147-
OMConfigKeys.OZONE_OM_GROUP_RIGHTS_DEFAULT);
146+
// Get default acl rights for user and group.
147+
OzoneAclConfig aclConfig = this.conf.getObject(OzoneAclConfig.class);
148+
this.userRights = aclConfig.getUserDefaultRights();
149+
this.groupRights = aclConfig.getGroupDefaultRights();
150+
148151
this.ozoneManagerClient = new OzoneManagerProtocolClientSideTranslatorPB(
149152
this.conf, clientId.toString(), ugi);
150153
long scmVersion =
@@ -256,13 +259,13 @@ public void createVolume(String volumeName, VolumeArgs volArgs)
256259
OzoneQuota.parseQuota(volArgs.getQuota()).sizeInBytes();
257260
List<OzoneAcl> listOfAcls = new ArrayList<>();
258261
//User ACL
259-
listOfAcls.add(new OzoneAcl(OzoneAcl.OzoneACLType.USER,
262+
listOfAcls.add(new OzoneAcl(ACLIdentityType.USER,
260263
owner, userRights));
261264
//Group ACLs of the User
262265
List<String> userGroups = Arrays.asList(UserGroupInformation
263266
.createRemoteUser(owner).getGroupNames());
264267
userGroups.stream().forEach((group) -> listOfAcls.add(
265-
new OzoneAcl(OzoneAcl.OzoneACLType.GROUP, group, groupRights)));
268+
new OzoneAcl(ACLIdentityType.GROUP, group, groupRights)));
266269
//ACLs from VolumeArgs
267270
if(volArgs.getAcls() != null) {
268271
listOfAcls.addAll(volArgs.getAcls());
@@ -403,13 +406,13 @@ public void createBucket(
403406

404407
List<OzoneAcl> listOfAcls = new ArrayList<>();
405408
//User ACL
406-
listOfAcls.add(new OzoneAcl(OzoneAcl.OzoneACLType.USER,
409+
listOfAcls.add(new OzoneAcl(ACLIdentityType.USER,
407410
ugi.getUserName(), userRights));
408411
//Group ACLs of the User
409412
List<String> userGroups = Arrays.asList(UserGroupInformation
410413
.createRemoteUser(ugi.getUserName()).getGroupNames());
411414
userGroups.stream().forEach((group) -> listOfAcls.add(
412-
new OzoneAcl(OzoneAcl.OzoneACLType.GROUP, group, groupRights)));
415+
new OzoneAcl(ACLIdentityType.GROUP, group, groupRights)));
413416
//ACLs from BucketArgs
414417
if(bucketArgs.getAcls() != null) {
415418
listOfAcls.addAll(bucketArgs.getAcls());

hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneAcl.java renamed to hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OzoneAcl.java

Lines changed: 43 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919

2020
package org.apache.hadoop.ozone;
2121

22+
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType;
23+
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType;
24+
25+
import java.util.ArrayList;
26+
import java.util.List;
2227
import java.util.Objects;
2328

2429
/**
@@ -32,9 +37,9 @@
3237
* </ul>
3338
*/
3439
public class OzoneAcl {
35-
private OzoneACLType type;
40+
private ACLIdentityType type;
3641
private String name;
37-
private OzoneACLRights rights;
42+
private List<ACLType> rights;
3843

3944
/**
4045
* Constructor for OzoneAcl.
@@ -47,16 +52,37 @@ public OzoneAcl() {
4752
*
4853
* @param type - Type
4954
* @param name - Name of user
50-
* @param rights - Rights
55+
* @param acl - Rights
5156
*/
52-
public OzoneAcl(OzoneACLType type, String name, OzoneACLRights rights) {
57+
public OzoneAcl(ACLIdentityType type, String name, ACLType acl) {
5358
this.name = name;
54-
this.rights = rights;
59+
this.rights = new ArrayList<>();
60+
this.rights.add(acl);
5561
this.type = type;
56-
if (type == OzoneACLType.WORLD && name.length() != 0) {
62+
if (type == ACLIdentityType.WORLD && name.length() != 0) {
5763
throw new IllegalArgumentException("Unexpected name part in world type");
5864
}
59-
if (((type == OzoneACLType.USER) || (type == OzoneACLType.GROUP))
65+
if (((type == ACLIdentityType.USER) || (type == ACLIdentityType.GROUP))
66+
&& (name.length() == 0)) {
67+
throw new IllegalArgumentException("User or group name is required");
68+
}
69+
}
70+
71+
/**
72+
* Constructor for OzoneAcl.
73+
*
74+
* @param type - Type
75+
* @param name - Name of user
76+
* @param acls - Rights
77+
*/
78+
public OzoneAcl(ACLIdentityType type, String name, List<ACLType> acls) {
79+
this.name = name;
80+
this.rights = acls;
81+
this.type = type;
82+
if (type == ACLIdentityType.WORLD && name.length() != 0) {
83+
throw new IllegalArgumentException("Unexpected name part in world type");
84+
}
85+
if (((type == ACLIdentityType.USER) || (type == ACLIdentityType.GROUP))
6086
&& (name.length() == 0)) {
6187
throw new IllegalArgumentException("User or group name is required");
6288
}
@@ -78,17 +104,20 @@ public static OzoneAcl parseAcl(String acl) throws IllegalArgumentException {
78104
throw new IllegalArgumentException("ACLs are not in expected format");
79105
}
80106

81-
OzoneACLType aclType = OzoneACLType.valueOf(parts[0].toUpperCase());
82-
OzoneACLRights rights = OzoneACLRights.getACLRight(parts[2].toLowerCase());
107+
ACLIdentityType aclType = ACLIdentityType.valueOf(parts[0].toUpperCase());
108+
List<ACLType> acls = new ArrayList<>();
109+
for (char ch : parts[2].toCharArray()) {
110+
acls.add(ACLType.getACLRight(String.valueOf(ch)));
111+
}
83112

84113
// TODO : Support sanitation of these user names by calling into
85114
// userAuth Interface.
86-
return new OzoneAcl(aclType, parts[1], rights);
115+
return new OzoneAcl(aclType, parts[1], acls);
87116
}
88117

89118
@Override
90119
public String toString() {
91-
return type + ":" + name + ":" + OzoneACLRights.getACLRightsString(rights);
120+
return type + ":" + name + ":" + ACLType.getACLString(rights);
92121
}
93122

94123
/**
@@ -120,7 +149,7 @@ public String getName() {
120149
*
121150
* @return - Rights
122151
*/
123-
public OzoneACLRights getRights() {
152+
public List<ACLType> getRights() {
124153
return rights;
125154
}
126155

@@ -129,7 +158,7 @@ public OzoneACLRights getRights() {
129158
*
130159
* @return type
131160
*/
132-
public OzoneACLType getType() {
161+
public ACLIdentityType getType() {
133162
return type;
134163
}
135164

@@ -150,9 +179,7 @@ public boolean equals(Object obj) {
150179
return false;
151180
}
152181
OzoneAcl otherAcl = (OzoneAcl) obj;
153-
return otherAcl.getName().equals(this.getName()) &&
154-
otherAcl.getRights() == this.getRights() &&
155-
otherAcl.getType() == this.getType();
182+
return otherAcl.toString().equals(this.toString());
156183
}
157184

158185
/**
@@ -177,57 +204,4 @@ public enum OzoneACLType {
177204
value = val;
178205
}
179206
}
180-
181-
/**
182-
* ACL rights.
183-
*/
184-
public enum OzoneACLRights {
185-
READ, WRITE, READ_WRITE;
186-
187-
/**
188-
* Returns the ACL rights based on passed in String.
189-
*
190-
* @param type ACL right string
191-
*
192-
* @return OzoneACLRights
193-
*/
194-
public static OzoneACLRights getACLRight(String type) {
195-
if (type == null || type.isEmpty()) {
196-
throw new IllegalArgumentException("ACL right cannot be empty");
197-
}
198-
199-
switch (type) {
200-
case OzoneConsts.OZONE_ACL_READ:
201-
return OzoneACLRights.READ;
202-
case OzoneConsts.OZONE_ACL_WRITE:
203-
return OzoneACLRights.WRITE;
204-
case OzoneConsts.OZONE_ACL_READ_WRITE:
205-
case OzoneConsts.OZONE_ACL_WRITE_READ:
206-
return OzoneACLRights.READ_WRITE;
207-
default:
208-
throw new IllegalArgumentException("ACL right is not recognized");
209-
}
210-
211-
}
212-
213-
/**
214-
* Returns String representation of ACL rights.
215-
* @param acl OzoneACLRights
216-
* @return String representation of acl
217-
*/
218-
public static String getACLRightsString(OzoneACLRights acl) {
219-
switch(acl) {
220-
case READ:
221-
return OzoneConsts.OZONE_ACL_READ;
222-
case WRITE:
223-
return OzoneConsts.OZONE_ACL_WRITE;
224-
case READ_WRITE:
225-
return OzoneConsts.OZONE_ACL_READ_WRITE;
226-
default:
227-
throw new IllegalArgumentException("ACL right is not recognized");
228-
}
229-
}
230-
231-
}
232-
233207
}

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OMConfigKeys.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.util.concurrent.TimeUnit;
2121

22-
import org.apache.hadoop.ozone.OzoneAcl;
2322
import org.apache.ratis.util.TimeDuration;
2423

2524
/**
@@ -78,17 +77,6 @@ private OMConfigKeys() {
7877
"ozone.om.user.max.volume";
7978
public static final int OZONE_OM_USER_MAX_VOLUME_DEFAULT = 1024;
8079

81-
// OM Default user/group permissions
82-
public static final String OZONE_OM_USER_RIGHTS =
83-
"ozone.om.user.rights";
84-
public static final OzoneAcl.OzoneACLRights OZONE_OM_USER_RIGHTS_DEFAULT =
85-
OzoneAcl.OzoneACLRights.READ_WRITE;
86-
87-
public static final String OZONE_OM_GROUP_RIGHTS =
88-
"ozone.om.group.rights";
89-
public static final OzoneAcl.OzoneACLRights OZONE_OM_GROUP_RIGHTS_DEFAULT =
90-
OzoneAcl.OzoneACLRights.READ_WRITE;
91-
9280
public static final String OZONE_KEY_DELETING_LIMIT_PER_TASK =
9381
"ozone.key.deleting.limit.per.task";
9482
public static final int OZONE_KEY_DELETING_LIMIT_PER_TASK_DEFAULT = 1000;

0 commit comments

Comments
 (0)