Skip to content

Commit 139a470

Browse files
HDDS-1600. Add userName and IPAddress as part of OMRequest.
1 parent 9122b9b commit 139a470

File tree

17 files changed

+369
-162
lines changed

17 files changed

+369
-162
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,5 +196,9 @@ public enum ResultCodes {
196196
FILE_ALREADY_EXISTS,
197197

198198
NOT_A_FILE,
199+
200+
PERMISSION_DENIED, // Error codes used during acl validation
201+
202+
TIMEOUT // Error codes used during acl validation
199203
}
200204
}

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/acl/IAccessAuthorizer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.hadoop.classification.InterfaceAudience;
2020
import org.apache.hadoop.classification.InterfaceStability;
2121
import org.apache.hadoop.ozone.OzoneConsts;
22+
import org.apache.hadoop.ozone.om.exceptions.OMException;
2223

2324
import java.util.BitSet;
2425

@@ -35,11 +36,11 @@ public interface IAccessAuthorizer {
3536
*
3637
* @param ozoneObject object for which access needs to be checked.
3738
* @param context Context object encapsulating all user related information.
38-
* @throws OzoneAclException
39+
* @throws org.apache.hadoop.ozone.om.exceptions.OMException
3940
* @return true if user has access else false.
4041
*/
4142
boolean checkAccess(IOzoneObj ozoneObject, RequestContext context)
42-
throws OzoneAclException;
43+
throws OMException;
4344

4445
/**
4546
* ACL rights.

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/acl/OzoneAccessAuthorizer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
*/
1717
package org.apache.hadoop.ozone.security.acl;
1818

19+
import org.apache.hadoop.ozone.om.exceptions.OMException;
20+
1921
/**
2022
* Default implementation for {@link IAccessAuthorizer}.
2123
* */
2224
public class OzoneAccessAuthorizer implements IAccessAuthorizer {
2325

2426
@Override
2527
public boolean checkAccess(IOzoneObj ozoneObject, RequestContext context)
26-
throws OzoneAclException {
28+
throws OMException {
2729
return true;
2830
}
2931
}

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/acl/OzoneAclException.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

hadoop-ozone/common/src/main/proto/OzoneManagerProtocol.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ message OMRequest {
102102

103103
required string clientId = 3;
104104

105+
optional UserInfo userInfo = 4;
106+
107+
105108
optional CreateVolumeRequest createVolumeRequest = 11;
106109
optional SetVolumePropertyRequest setVolumePropertyRequest = 12;
107110
optional CheckVolumeAccessRequest checkVolumeAccessRequest = 13;
@@ -271,6 +274,8 @@ enum Status {
271274
DIRECTORY_NOT_FOUND = 45;
272275
FILE_ALREADY_EXISTS = 46;
273276
NOT_A_FILE = 47;
277+
PERMISSION_DENIED = 48;
278+
TIMEOUT = 49;
274279
}
275280

276281

@@ -284,6 +289,16 @@ message VolumeInfo {
284289
required uint64 creationTime = 7;
285290
}
286291

292+
/**
293+
User information which will be extracted during RPC context and used
294+
during validating Acl.
295+
*/
296+
message UserInfo {
297+
optional string userName = 1;
298+
optional string remoteAddress = 3;
299+
}
300+
301+
287302
/**
288303
Creates a volume
289304
*/

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmAcls.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import org.apache.hadoop.hdfs.server.datanode.ObjectStoreHandler;
2525
import org.apache.hadoop.ozone.MiniOzoneCluster;
2626
import org.apache.hadoop.ozone.OzoneTestUtils;
27+
import org.apache.hadoop.ozone.om.exceptions.OMException;
2728
import org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes;
2829
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
2930
import org.apache.hadoop.ozone.security.acl.IOzoneObj;
30-
import org.apache.hadoop.ozone.security.acl.OzoneAclException;
3131
import org.apache.hadoop.ozone.security.acl.RequestContext;
3232
import org.apache.hadoop.ozone.web.handlers.BucketArgs;
3333
import org.apache.hadoop.ozone.web.handlers.KeyArgs;
@@ -169,7 +169,7 @@ class OzoneAccessAuthrizerTest implements IAccessAuthorizer {
169169

170170
@Override
171171
public boolean checkAccess(IOzoneObj ozoneObject, RequestContext context)
172-
throws OzoneAclException {
172+
throws OMException {
173173
return false;
174174
}
175175
}

hadoop-ozone/ozone-manager/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
8282
<scope>test</scope>
8383
</dependency>
8484

85+
<dependency>
86+
<groupId>org.jmockit</groupId>
87+
<artifactId>jmockit</artifactId>
88+
<version>1.24</version>
89+
<scope>test</scope>
90+
</dependency>
91+
8592
</dependencies>
8693
<build>
8794
<plugins>

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.common.base.Preconditions;
2525
import com.google.protobuf.BlockingService;
2626

27+
import java.net.InetAddress;
2728
import java.security.PrivateKey;
2829
import java.security.PublicKey;
2930
import java.security.KeyPair;
@@ -127,8 +128,6 @@
127128
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType;
128129
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType;
129130
import org.apache.hadoop.ozone.security.acl.OzoneAccessAuthorizer;
130-
import org.apache.hadoop.ozone.security.acl.OzoneAclException;
131-
import org.apache.hadoop.ozone.security.acl.OzoneAclException.ErrorCode;
132131
import org.apache.hadoop.ozone.security.acl.OzoneObj;
133132
import org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType;
134133
import org.apache.hadoop.ozone.security.acl.OzoneObj.ResourceType;
@@ -1733,18 +1732,36 @@ public void applyDeleteVolume(String volume, String owner,
17331732
* @param vol - name of volume
17341733
* @param bucket - bucket name
17351734
* @param key - key
1736-
* @throws OzoneAclException
1735+
* @throws OMException
17371736
*/
17381737
private void checkAcls(ResourceType resType, StoreType store,
17391738
ACLType acl, String vol, String bucket, String key)
1740-
throws OzoneAclException {
1741-
if(!isAclEnabled) {
1742-
return;
1743-
}
1739+
throws OMException {
1740+
checkAcls(resType, store, acl, vol, bucket, key,
1741+
ProtobufRpcEngine.Server.getRemoteUser(),
1742+
ProtobufRpcEngine.Server.getRemoteIp());
1743+
}
17441744

1745+
/**
1746+
* CheckAcls for the ozone object.
1747+
* @param resType
1748+
* @param storeType
1749+
* @param aclType
1750+
* @param vol
1751+
* @param bucket
1752+
* @param key
1753+
* @param ugi
1754+
* @param remoteAddress
1755+
* @throws OMException
1756+
*/
1757+
@SuppressWarnings("parameternumber")
1758+
public void checkAcls(ResourceType resType, StoreType storeType,
1759+
ACLType aclType, String vol, String bucket, String key,
1760+
UserGroupInformation ugi, InetAddress remoteAddress)
1761+
throws OMException {
17451762
OzoneObj obj = OzoneObjInfo.Builder.newBuilder()
17461763
.setResType(resType)
1747-
.setStoreType(store)
1764+
.setStoreType(storeType)
17481765
.setVolumeName(vol)
17491766
.setBucketName(bucket)
17501767
.setKeyName(key).build();
@@ -1753,17 +1770,26 @@ private void checkAcls(ResourceType resType, StoreType store,
17531770
.setClientUgi(user)
17541771
.setIp(ProtobufRpcEngine.Server.getRemoteIp())
17551772
.setAclType(ACLIdentityType.USER)
1756-
.setAclRights(acl)
1773+
.setAclRights(aclType)
17571774
.build();
17581775
if (!accessAuthorizer.checkAccess(obj, context)) {
17591776
LOG.warn("User {} doesn't have {} permission to access {}",
1760-
user.getUserName(), acl, resType);
1761-
throw new OzoneAclException("User " + user.getUserName() + " doesn't " +
1762-
"have " + acl + " permission to access " + resType,
1763-
ErrorCode.PERMISSION_DENIED);
1777+
user.getUserName(), aclType, resType);
1778+
throw new OMException("User " + user.getUserName() + " doesn't " +
1779+
"have " + aclType + " permission to access " + resType,
1780+
ResultCodes.PERMISSION_DENIED);
17641781
}
17651782
}
17661783

1784+
/**
1785+
*
1786+
* Return true if Ozone acl's are enabled, else false.
1787+
* @return boolean
1788+
*/
1789+
public boolean getAclsEnabled() {
1790+
return isAclEnabled;
1791+
}
1792+
17671793
/**
17681794
* Changes the owner of a volume.
17691795
*
@@ -2406,8 +2432,10 @@ public void setBucketProperty(OmBucketArgs args)
24062432
*/
24072433
@Override
24082434
public void deleteBucket(String volume, String bucket) throws IOException {
2409-
checkAcls(ResourceType.BUCKET, StoreType.OZONE, ACLType.WRITE, volume,
2410-
bucket, null);
2435+
if (isAclEnabled) {
2436+
checkAcls(ResourceType.BUCKET, StoreType.OZONE, ACLType.WRITE, volume,
2437+
bucket, null);
2438+
}
24112439
Map<String, String> auditMap = buildAuditMap(volume);
24122440
auditMap.put(OzoneConsts.BUCKET, bucket);
24132441
try {

0 commit comments

Comments
 (0)