You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/11/23 06:35:39 UTC

[GitHub] [ozone] smengcl commented on a change in pull request #2826: HDDS-5903. Add Support for Bucket Owner Acls

smengcl commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r754762120



##########
File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmAcls.java
##########
@@ -132,7 +132,7 @@ public void testBucketCreationPermissionDenied() throws Exception {
         () -> volume.createBucket(bucketName));
 
     assertTrue(logCapturer.getOutput()
-        .contains("doesn't have CREATE permission to access bucket"));
+        .contains("doesn't have READ permission to access volume"));

Review comment:
       Hmm. I thought we weren't changing OzoneNativeAuthorizer logic? Should say "doesn't have WRITE permission" here?

##########
File path: hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
##########
@@ -473,6 +473,8 @@ public void createBucket(
     verifyCountsQuota(bucketArgs.getQuotaInNamespace());
     verifySpaceQuota(bucketArgs.getQuotaInBytes());
 
+    String owner = bucketArgs.getOwner() == null ?
+            ugi.getShortUserName() : bucketArgs.getOwner();

Review comment:
       Do we **always** fall back to current ugi as bucket owner at this time?

##########
File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmAcls.java
##########
@@ -147,8 +147,8 @@ public void testFailureInKeyOp() throws Exception {
 
     OzoneTestUtils.expectOmException(ResultCodes.PERMISSION_DENIED,
         () -> TestDataUtil.createKey(bucket, "testKey", "testcontent"));
-    assertTrue(logCapturer.getOutput().contains("doesn't have CREATE " +
-        "permission to access key"));
+    assertTrue(logCapturer.getOutput().contains("doesn't have READ " +
+            "permission to access volume"));

Review comment:
       nit: indentation
   ```suggestion
           "permission to access volume"));
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneAclUtils.java
##########
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.security.UserGroupInformation;
+
+import java.io.IOException;
+import java.net.InetAddress;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_REQUEST;
+
+/**
+ * Ozone Acl Wrapper class.
+ */
+public final class OzoneAclUtils {
+
+  private OzoneAclUtils() {
+  }
+
+  /**
+   * Check Acls of ozone object with volOwner given.
+   * @param ozoneManager
+   * @param resType
+   * @param storeType
+   * @param aclType
+   * @param vol
+   * @param bucket
+   * @param key
+   * @param volOwner
+   * @param bucketOwner
+   * @throws IOException
+   */
+  @SuppressWarnings("parameternumber")
+  public static void checkAllAcls(OzoneManager ozoneManager,
+      OzoneObj.ResourceType resType,
+      OzoneObj.StoreType storeType, IAccessAuthorizer.ACLType aclType,
+      String vol, String bucket, String key, String volOwner,
+      String bucketOwner, UserGroupInformation user, InetAddress remoteAddress,
+      String hostName) throws IOException {
+
+    boolean isVolOwner = isOwner(user, volOwner);
+
+    IAccessAuthorizer.ACLType parentAclRight = aclType;
+
+    if(ozoneManager.isNativeAuthorizerEnabled()) {
+      if (aclType == IAccessAuthorizer.ACLType.CREATE ||
+          aclType == IAccessAuthorizer.ACLType.DELETE ||
+          aclType == IAccessAuthorizer.ACLType.WRITE_ACL) {
+        parentAclRight = IAccessAuthorizer.ACLType.WRITE;
+      } else if (aclType == IAccessAuthorizer.ACLType.READ_ACL ||
+          aclType == IAccessAuthorizer.ACLType.LIST) {
+        parentAclRight = IAccessAuthorizer.ACLType.READ;
+      }
+    } else {
+      parentAclRight =  IAccessAuthorizer.ACLType.READ;
+
+    }
+
+    switch (resType) {
+    case VOLUME:
+      ozoneManager.checkAcls(resType, storeType, aclType, vol, bucket, key,
+          user, remoteAddress, hostName, true,
+          volOwner);
+      break;
+    case BUCKET:
+    case KEY:
+    case PREFIX:
+      ozoneManager.checkAcls(OzoneObj.ResourceType.VOLUME, storeType,
+          parentAclRight, vol, bucket, key, user,
+          remoteAddress, hostName, true,
+          volOwner);
+      if(isVolOwner){

Review comment:
       nit
   ```suggestion
         if (isVolOwner) {
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/OMClientRequest.java
##########
@@ -234,15 +233,66 @@ protected void checkACLs(OzoneManager ozoneManager, String volumeName,
     if (ozoneManager.getAclsEnabled()) {
       String volumeOwner = ozoneManager.getVolumeOwner(obj.getVolumeName(),
           contextBuilder.getAclRights(), obj.getResourceType());
-      contextBuilder.setClientUgi(createUGI());
+      String bucketOwner = ozoneManager.getBucketOwner(obj.getVolumeName(),
+          obj.getBucketName(), contextBuilder.getAclRights(),
+          obj.getResourceType());
+      UserGroupInformation currentUser = createUGI();
+      contextBuilder.setClientUgi(currentUser);
       contextBuilder.setIp(getRemoteAddress());
       contextBuilder.setHost(getHostName());
       contextBuilder.setAclType(IAccessAuthorizer.ACLIdentityType.USER);
-      contextBuilder.setOwnerName(volumeOwner);
+
+      boolean isVolOwner = isOwner(currentUser, volumeOwner);
+      IAccessAuthorizer.ACLType parentAclRight = aclType;
+      if(isVolOwner) {
+        contextBuilder.setOwnerName(volumeOwner);
+      } else {
+        contextBuilder.setOwnerName(bucketOwner);
+      }
+      if(ozoneManager.isNativeAuthorizerEnabled()) {
+        if (aclType == IAccessAuthorizer.ACLType.CREATE ||
+                aclType == IAccessAuthorizer.ACLType.DELETE ||
+                aclType == IAccessAuthorizer.ACLType.WRITE_ACL) {
+          parentAclRight = IAccessAuthorizer.ACLType.WRITE;
+        } else if (aclType == IAccessAuthorizer.ACLType.READ_ACL ||
+                aclType == IAccessAuthorizer.ACLType.LIST) {
+          parentAclRight = IAccessAuthorizer.ACLType.READ;
+        }
+      } else {
+        parentAclRight =  IAccessAuthorizer.ACLType.READ;
+
+      }
+      OzoneObj volumeObj = OzoneObjInfo.Builder.newBuilder()
+              .setResType(OzoneObj.ResourceType.VOLUME)
+              .setStoreType(OzoneObj.StoreType.OZONE)
+              .setVolumeName(volumeName)
+              .setBucketName(bucketName)
+              .setKeyName(keyName).build();
+      RequestContext volumeContext = RequestContext.newBuilder()
+              .setClientUgi(currentUser)
+              .setIp(getRemoteAddress())
+              .setHost(getHostName())
+              .setAclType(IAccessAuthorizer.ACLIdentityType.USER)
+              .setAclRights(parentAclRight)
+              .setOwnerName(volumeOwner)
+              .build();
+      ozoneManager.checkAcls(volumeObj, volumeContext, true);
       ozoneManager.checkAcls(obj, contextBuilder.build(), true);
     }
   }
 
+  private boolean isOwner(UserGroupInformation callerUgi,
+                                 String ownerName) {
+    if (ownerName == null) {
+      return false;
+    }
+    if (callerUgi.getUserName().equals(ownerName) ||
+            callerUgi.getShortUserName().equals(ownerName)) {

Review comment:
       ```suggestion
           callerUgi.getShortUserName().equals(ownerName)) {
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/OMClientRequest.java
##########
@@ -234,15 +233,66 @@ protected void checkACLs(OzoneManager ozoneManager, String volumeName,
     if (ozoneManager.getAclsEnabled()) {
       String volumeOwner = ozoneManager.getVolumeOwner(obj.getVolumeName(),
           contextBuilder.getAclRights(), obj.getResourceType());
-      contextBuilder.setClientUgi(createUGI());
+      String bucketOwner = ozoneManager.getBucketOwner(obj.getVolumeName(),
+          obj.getBucketName(), contextBuilder.getAclRights(),
+          obj.getResourceType());
+      UserGroupInformation currentUser = createUGI();
+      contextBuilder.setClientUgi(currentUser);
       contextBuilder.setIp(getRemoteAddress());
       contextBuilder.setHost(getHostName());
       contextBuilder.setAclType(IAccessAuthorizer.ACLIdentityType.USER);
-      contextBuilder.setOwnerName(volumeOwner);
+
+      boolean isVolOwner = isOwner(currentUser, volumeOwner);
+      IAccessAuthorizer.ACLType parentAclRight = aclType;
+      if(isVolOwner) {

Review comment:
       ```suggestion
         if (isVolOwner) {
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneAclUtils.java
##########
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.security.UserGroupInformation;
+
+import java.io.IOException;
+import java.net.InetAddress;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_REQUEST;
+
+/**
+ * Ozone Acl Wrapper class.
+ */
+public final class OzoneAclUtils {
+
+  private OzoneAclUtils() {
+  }
+
+  /**
+   * Check Acls of ozone object with volOwner given.
+   * @param ozoneManager
+   * @param resType
+   * @param storeType
+   * @param aclType
+   * @param vol
+   * @param bucket
+   * @param key
+   * @param volOwner
+   * @param bucketOwner
+   * @throws IOException
+   */
+  @SuppressWarnings("parameternumber")
+  public static void checkAllAcls(OzoneManager ozoneManager,
+      OzoneObj.ResourceType resType,
+      OzoneObj.StoreType storeType, IAccessAuthorizer.ACLType aclType,
+      String vol, String bucket, String key, String volOwner,
+      String bucketOwner, UserGroupInformation user, InetAddress remoteAddress,
+      String hostName) throws IOException {
+
+    boolean isVolOwner = isOwner(user, volOwner);
+
+    IAccessAuthorizer.ACLType parentAclRight = aclType;
+
+    if(ozoneManager.isNativeAuthorizerEnabled()) {

Review comment:
       Add some comments here. To explain why we made the choice of using different parent ACL check for native and others. And caveats. So others can more easily understand the code later on.
   ```suggestion
       //
       if (ozoneManager.isNativeAuthorizerEnabled()) {
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneAclUtils.java
##########
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.security.UserGroupInformation;
+
+import java.io.IOException;
+import java.net.InetAddress;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_REQUEST;
+
+/**
+ * Ozone Acl Wrapper class.
+ */
+public final class OzoneAclUtils {
+
+  private OzoneAclUtils() {
+  }
+
+  /**
+   * Check Acls of ozone object with volOwner given.
+   * @param ozoneManager
+   * @param resType
+   * @param storeType
+   * @param aclType
+   * @param vol
+   * @param bucket
+   * @param key
+   * @param volOwner
+   * @param bucketOwner
+   * @throws IOException
+   */
+  @SuppressWarnings("parameternumber")
+  public static void checkAllAcls(OzoneManager ozoneManager,
+      OzoneObj.ResourceType resType,
+      OzoneObj.StoreType storeType, IAccessAuthorizer.ACLType aclType,
+      String vol, String bucket, String key, String volOwner,
+      String bucketOwner, UserGroupInformation user, InetAddress remoteAddress,
+      String hostName) throws IOException {
+
+    boolean isVolOwner = isOwner(user, volOwner);
+
+    IAccessAuthorizer.ACLType parentAclRight = aclType;
+
+    if(ozoneManager.isNativeAuthorizerEnabled()) {
+      if (aclType == IAccessAuthorizer.ACLType.CREATE ||
+          aclType == IAccessAuthorizer.ACLType.DELETE ||
+          aclType == IAccessAuthorizer.ACLType.WRITE_ACL) {
+        parentAclRight = IAccessAuthorizer.ACLType.WRITE;
+      } else if (aclType == IAccessAuthorizer.ACLType.READ_ACL ||
+          aclType == IAccessAuthorizer.ACLType.LIST) {
+        parentAclRight = IAccessAuthorizer.ACLType.READ;
+      }
+    } else {
+      parentAclRight =  IAccessAuthorizer.ACLType.READ;
+
+    }
+
+    switch (resType) {
+    case VOLUME:
+      ozoneManager.checkAcls(resType, storeType, aclType, vol, bucket, key,

Review comment:
       Add comment above this line. e.g. For a volume, we only need to check the ACL with {OWNER} tag equals volume owner.

##########
File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmAcls.java
##########
@@ -147,8 +147,8 @@ public void testFailureInKeyOp() throws Exception {
 
     OzoneTestUtils.expectOmException(ResultCodes.PERMISSION_DENIED,
         () -> TestDataUtil.createKey(bucket, "testKey", "testcontent"));
-    assertTrue(logCapturer.getOutput().contains("doesn't have CREATE " +
-        "permission to access key"));
+    assertTrue(logCapturer.getOutput().contains("doesn't have READ " +

Review comment:
       Same question as above.

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneAclUtils.java
##########
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.security.UserGroupInformation;
+
+import java.io.IOException;
+import java.net.InetAddress;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_REQUEST;
+
+/**
+ * Ozone Acl Wrapper class.
+ */
+public final class OzoneAclUtils {
+
+  private OzoneAclUtils() {
+  }
+
+  /**
+   * Check Acls of ozone object with volOwner given.

Review comment:
       ```suggestion
      * Check Acls of ozone object with given volume owner and bucket owner.
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneAclUtils.java
##########
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.security.UserGroupInformation;
+
+import java.io.IOException;
+import java.net.InetAddress;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_REQUEST;
+
+/**
+ * Ozone Acl Wrapper class.
+ */
+public final class OzoneAclUtils {
+
+  private OzoneAclUtils() {
+  }
+
+  /**
+   * Check Acls of ozone object with volOwner given.
+   * @param ozoneManager
+   * @param resType
+   * @param storeType
+   * @param aclType
+   * @param vol
+   * @param bucket
+   * @param key
+   * @param volOwner
+   * @param bucketOwner
+   * @throws IOException
+   */
+  @SuppressWarnings("parameternumber")
+  public static void checkAllAcls(OzoneManager ozoneManager,
+      OzoneObj.ResourceType resType,
+      OzoneObj.StoreType storeType, IAccessAuthorizer.ACLType aclType,
+      String vol, String bucket, String key, String volOwner,
+      String bucketOwner, UserGroupInformation user, InetAddress remoteAddress,
+      String hostName) throws IOException {
+
+    boolean isVolOwner = isOwner(user, volOwner);
+
+    IAccessAuthorizer.ACLType parentAclRight = aclType;
+
+    if(ozoneManager.isNativeAuthorizerEnabled()) {
+      if (aclType == IAccessAuthorizer.ACLType.CREATE ||
+          aclType == IAccessAuthorizer.ACLType.DELETE ||
+          aclType == IAccessAuthorizer.ACLType.WRITE_ACL) {
+        parentAclRight = IAccessAuthorizer.ACLType.WRITE;
+      } else if (aclType == IAccessAuthorizer.ACLType.READ_ACL ||
+          aclType == IAccessAuthorizer.ACLType.LIST) {
+        parentAclRight = IAccessAuthorizer.ACLType.READ;
+      }
+    } else {
+      parentAclRight =  IAccessAuthorizer.ACLType.READ;
+

Review comment:
       ```suggestion
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneAclUtils.java
##########
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.security.UserGroupInformation;
+
+import java.io.IOException;
+import java.net.InetAddress;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_REQUEST;
+
+/**
+ * Ozone Acl Wrapper class.
+ */
+public final class OzoneAclUtils {
+
+  private OzoneAclUtils() {
+  }
+
+  /**
+   * Check Acls of ozone object with volOwner given.
+   * @param ozoneManager
+   * @param resType
+   * @param storeType
+   * @param aclType
+   * @param vol
+   * @param bucket
+   * @param key
+   * @param volOwner
+   * @param bucketOwner
+   * @throws IOException
+   */
+  @SuppressWarnings("parameternumber")
+  public static void checkAllAcls(OzoneManager ozoneManager,
+      OzoneObj.ResourceType resType,
+      OzoneObj.StoreType storeType, IAccessAuthorizer.ACLType aclType,
+      String vol, String bucket, String key, String volOwner,
+      String bucketOwner, UserGroupInformation user, InetAddress remoteAddress,
+      String hostName) throws IOException {
+
+    boolean isVolOwner = isOwner(user, volOwner);
+
+    IAccessAuthorizer.ACLType parentAclRight = aclType;
+
+    if(ozoneManager.isNativeAuthorizerEnabled()) {
+      if (aclType == IAccessAuthorizer.ACLType.CREATE ||
+          aclType == IAccessAuthorizer.ACLType.DELETE ||
+          aclType == IAccessAuthorizer.ACLType.WRITE_ACL) {
+        parentAclRight = IAccessAuthorizer.ACLType.WRITE;
+      } else if (aclType == IAccessAuthorizer.ACLType.READ_ACL ||
+          aclType == IAccessAuthorizer.ACLType.LIST) {
+        parentAclRight = IAccessAuthorizer.ACLType.READ;
+      }
+    } else {
+      parentAclRight =  IAccessAuthorizer.ACLType.READ;
+
+    }
+
+    switch (resType) {
+    case VOLUME:
+      ozoneManager.checkAcls(resType, storeType, aclType, vol, bucket, key,
+          user, remoteAddress, hostName, true,
+          volOwner);
+      break;
+    case BUCKET:
+    case KEY:
+    case PREFIX:
+      ozoneManager.checkAcls(OzoneObj.ResourceType.VOLUME, storeType,
+          parentAclRight, vol, bucket, key, user,
+          remoteAddress, hostName, true,
+          volOwner);
+      if(isVolOwner){
+        ozoneManager.checkAcls(resType, storeType, aclType, vol, bucket, key,
+            user, remoteAddress, hostName, true,
+            volOwner);
+      } else {
+        ozoneManager.checkAcls(resType, storeType, aclType, vol, bucket, key,
+            user, remoteAddress, hostName, true,
+            bucketOwner);
+      }
+      break;
+    default:
+      throw new OMException("Unexpected object type:" +
+              resType, INVALID_REQUEST);
+    }
+  }
+
+  private static boolean isOwner(UserGroupInformation callerUgi,
+      String ownerName) {
+    if (ownerName == null) {
+      return false;
+    }
+    if (callerUgi.getUserName().equals(ownerName) ||
+            callerUgi.getShortUserName().equals(ownerName)) {

Review comment:
       nit: indentation
   ```suggestion
           callerUgi.getShortUserName().equals(ownerName)) {
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneAclUtils.java
##########
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.ozone.security.acl.OzoneObj;
+import org.apache.hadoop.security.UserGroupInformation;
+
+import java.io.IOException;
+import java.net.InetAddress;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.INVALID_REQUEST;
+
+/**
+ * Ozone Acl Wrapper class.
+ */
+public final class OzoneAclUtils {
+
+  private OzoneAclUtils() {
+  }
+
+  /**
+   * Check Acls of ozone object with volOwner given.
+   * @param ozoneManager
+   * @param resType
+   * @param storeType
+   * @param aclType
+   * @param vol
+   * @param bucket
+   * @param key
+   * @param volOwner
+   * @param bucketOwner
+   * @throws IOException
+   */
+  @SuppressWarnings("parameternumber")
+  public static void checkAllAcls(OzoneManager ozoneManager,
+      OzoneObj.ResourceType resType,
+      OzoneObj.StoreType storeType, IAccessAuthorizer.ACLType aclType,
+      String vol, String bucket, String key, String volOwner,
+      String bucketOwner, UserGroupInformation user, InetAddress remoteAddress,
+      String hostName) throws IOException {
+
+    boolean isVolOwner = isOwner(user, volOwner);
+
+    IAccessAuthorizer.ACLType parentAclRight = aclType;
+
+    if(ozoneManager.isNativeAuthorizerEnabled()) {
+      if (aclType == IAccessAuthorizer.ACLType.CREATE ||
+          aclType == IAccessAuthorizer.ACLType.DELETE ||
+          aclType == IAccessAuthorizer.ACLType.WRITE_ACL) {
+        parentAclRight = IAccessAuthorizer.ACLType.WRITE;
+      } else if (aclType == IAccessAuthorizer.ACLType.READ_ACL ||
+          aclType == IAccessAuthorizer.ACLType.LIST) {
+        parentAclRight = IAccessAuthorizer.ACLType.READ;
+      }
+    } else {
+      parentAclRight =  IAccessAuthorizer.ACLType.READ;
+
+    }
+
+    switch (resType) {
+    case VOLUME:
+      ozoneManager.checkAcls(resType, storeType, aclType, vol, bucket, key,
+          user, remoteAddress, hostName, true,
+          volOwner);
+      break;
+    case BUCKET:
+    case KEY:
+    case PREFIX:
+      ozoneManager.checkAcls(OzoneObj.ResourceType.VOLUME, storeType,

Review comment:
       Add comment above this line as well. e.g. For bucket/key/prefix, first check the ACL with {OWNER} tag equals parent volume owner; then ...

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
##########
@@ -2083,6 +2101,44 @@ private String getVolumeOwner(String volume) throws OMException {
     }
   }
 
+  public String getBucketOwner(String volume, String bucket, ACLType type,
+       ResourceType resType) throws OMException {
+    String bucketOwner = null;
+    if ((resType != ResourceType.VOLUME) &&
+        !(type == ACLType.CREATE && resType == ResourceType.BUCKET)) {
+      bucketOwner = getBucketOwner(volume, bucket);
+    }
+    return bucketOwner;
+  }
+
+  private String getBucketOwner(String volume, String bucket)
+      throws OMException {
+
+    Boolean lockAcquired = metadataManager.getLock().acquireReadLock(
+            BUCKET_LOCK, volume, bucket);
+    String dbBucketKey = metadataManager.getBucketKey(volume, bucket);
+    OmBucketInfo bucketInfo = null;
+    try {
+      bucketInfo = metadataManager.getBucketTable().get(dbBucketKey);
+    } catch (IOException ioe) {
+      if (ioe instanceof OMException) {
+        throw (OMException)ioe;
+      } else {
+        throw new OMException("getBucketOwner for Bucket " + volume + "/" +
+                bucket  + " failed", ResultCodes.INTERNAL_ERROR);

Review comment:
       Better include `ioe.getMessage()` here as well in the exception message to make potential troubleshooting easier.
   ```suggestion
           throw new OMException("getBucketOwner for Bucket " + volume + "/" +
                   bucket  + " failed: " + ioe.getMessage(), ResultCodes.INTERNAL_ERROR);
   ```

##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/bucket/CreateBucketHandler.java
##########
@@ -51,6 +52,10 @@
           "false/unspecified indicates otherwise")
   private Boolean isGdprEnforced;
 
+  @Option(names = {"--user", "-u"},
+          description = "Owner of the bucket")

Review comment:
       ```suggestion
             description = "Owner of the bucket. Defaults to current user if not specified")
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/OMClientRequest.java
##########
@@ -234,15 +233,66 @@ protected void checkACLs(OzoneManager ozoneManager, String volumeName,
     if (ozoneManager.getAclsEnabled()) {
       String volumeOwner = ozoneManager.getVolumeOwner(obj.getVolumeName(),
           contextBuilder.getAclRights(), obj.getResourceType());
-      contextBuilder.setClientUgi(createUGI());
+      String bucketOwner = ozoneManager.getBucketOwner(obj.getVolumeName(),
+          obj.getBucketName(), contextBuilder.getAclRights(),
+          obj.getResourceType());
+      UserGroupInformation currentUser = createUGI();
+      contextBuilder.setClientUgi(currentUser);
       contextBuilder.setIp(getRemoteAddress());
       contextBuilder.setHost(getHostName());
       contextBuilder.setAclType(IAccessAuthorizer.ACLIdentityType.USER);
-      contextBuilder.setOwnerName(volumeOwner);
+
+      boolean isVolOwner = isOwner(currentUser, volumeOwner);
+      IAccessAuthorizer.ACLType parentAclRight = aclType;
+      if(isVolOwner) {
+        contextBuilder.setOwnerName(volumeOwner);
+      } else {
+        contextBuilder.setOwnerName(bucketOwner);
+      }
+      if(ozoneManager.isNativeAuthorizerEnabled()) {

Review comment:
       ```suggestion
         if (ozoneManager.isNativeAuthorizerEnabled()) {
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/OMClientRequest.java
##########
@@ -39,10 +40,7 @@
 import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.LayoutVersion;
 import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
 import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
-import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
-import org.apache.hadoop.ozone.security.acl.OzoneObj;
-import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;
-import org.apache.hadoop.ozone.security.acl.RequestContext;
+import org.apache.hadoop.ozone.security.acl.*;

Review comment:
       Try not to allow IntelliJ to automatically use wildcard imports:
   
   https://www.jetbrains.com/help/idea/creating-and-optimizing-imports.html#disable-wildcards-for-class

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/OMClientRequest.java
##########
@@ -234,15 +233,66 @@ protected void checkACLs(OzoneManager ozoneManager, String volumeName,
     if (ozoneManager.getAclsEnabled()) {
       String volumeOwner = ozoneManager.getVolumeOwner(obj.getVolumeName(),
           contextBuilder.getAclRights(), obj.getResourceType());
-      contextBuilder.setClientUgi(createUGI());
+      String bucketOwner = ozoneManager.getBucketOwner(obj.getVolumeName(),
+          obj.getBucketName(), contextBuilder.getAclRights(),
+          obj.getResourceType());
+      UserGroupInformation currentUser = createUGI();
+      contextBuilder.setClientUgi(currentUser);
       contextBuilder.setIp(getRemoteAddress());
       contextBuilder.setHost(getHostName());
       contextBuilder.setAclType(IAccessAuthorizer.ACLIdentityType.USER);
-      contextBuilder.setOwnerName(volumeOwner);
+
+      boolean isVolOwner = isOwner(currentUser, volumeOwner);
+      IAccessAuthorizer.ACLType parentAclRight = aclType;
+      if(isVolOwner) {
+        contextBuilder.setOwnerName(volumeOwner);
+      } else {
+        contextBuilder.setOwnerName(bucketOwner);
+      }
+      if(ozoneManager.isNativeAuthorizerEnabled()) {
+        if (aclType == IAccessAuthorizer.ACLType.CREATE ||
+                aclType == IAccessAuthorizer.ACLType.DELETE ||
+                aclType == IAccessAuthorizer.ACLType.WRITE_ACL) {
+          parentAclRight = IAccessAuthorizer.ACLType.WRITE;
+        } else if (aclType == IAccessAuthorizer.ACLType.READ_ACL ||
+                aclType == IAccessAuthorizer.ACLType.LIST) {
+          parentAclRight = IAccessAuthorizer.ACLType.READ;
+        }
+      } else {
+        parentAclRight =  IAccessAuthorizer.ACLType.READ;

Review comment:
       ```suggestion
           parentAclRight = IAccessAuthorizer.ACLType.READ;
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
##########
@@ -2083,6 +2101,44 @@ private String getVolumeOwner(String volume) throws OMException {
     }
   }
 
+  public String getBucketOwner(String volume, String bucket, ACLType type,

Review comment:
       Add javadoc to this method




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org