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/10 19:26:19 UTC

[GitHub] [ozone] aswinshakil opened a new pull request #2826: HDDS-5903. Add Support for Bucket Owner Acls

aswinshakil opened a new pull request #2826:
URL: https://github.com/apache/ozone/pull/2826


   ## What changes were proposed in this pull request?
   
   To add `owner` field to Buckets and support `checkAcls` for the new Bucket Owner.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-5903
   
   ## How was this patch tested?
   
   This patch was tested manually, integration tests, and CI tests.
   https://github.com/aswinshakil/ozone/actions/runs/1442975996
   


-- 
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


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

Posted by GitBox <gi...@apache.org>.
aswinshakil commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r755591111



##########
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:
       Yes we fall back to the current ugi as bucket owner. This is similar to how we do it `createVolume` 
   https://github.com/apache/ozone/blob/e658dff34fc917bfc3504332a6ed6945b28717de/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java#L313-L314




-- 
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


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

Posted by GitBox <gi...@apache.org>.
aswinshakil commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r755592773



##########
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:
       Thank you for the suggestions I will update the PR.




-- 
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


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

Posted by GitBox <gi...@apache.org>.
aswinshakil commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r758768101



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

Review comment:
       Yes, we can assign a bucket owner when we create a bucket in `CreateBucketHandler` with --user tag. This is only for bucket creation, we check bucket owner in `OzoneAclUtils.checkAllAcls` for other buckets related access.




-- 
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


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

Posted by GitBox <gi...@apache.org>.
prashantpogde commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r758653619



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneAclUtils.java
##########
@@ -0,0 +1,126 @@
+/**
+ * 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 volume owner and bucket owner.
+   * @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;
+
+    //OzoneNativeAuthorizer differs from Ranger Authorizer as Ranger requires
+    // only READ access on parent level access. OzoneNativeAuthorizer has
+    // different parent level access based on the child level access type
+    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:
       Simplify If conditions ?

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

Review comment:
       Can I assign someone else as bucket owner when I create a bucket ? where do we check that bucketArgs.owner is same as the person making the call ?




-- 
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


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

Posted by GitBox <gi...@apache.org>.
aswinshakil commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r755592935



##########
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:
       Sure, will add them.




-- 
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


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

Posted by GitBox <gi...@apache.org>.
aswinshakil commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r755589814



##########
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:
       The test doesn't use `OzoneNativeAuthorizer`. The test has its own authorizer `OzoneAccessAuthorizerTest`. Apart from `OzoneNativeAuthorizer`, other Authorizers which implements `IAccessAuthorizer` the parent level access required is READ, i.e similar to Ranger. Should this be changed?




-- 
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


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

Posted by GitBox <gi...@apache.org>.
prashantpogde commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r763305893



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneAclUtils.java
##########
@@ -0,0 +1,126 @@
+/**
+ * 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 volume owner and bucket owner.
+   * @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;
+
+    //OzoneNativeAuthorizer differs from Ranger Authorizer as Ranger requires
+    // only READ access on parent level access. OzoneNativeAuthorizer has
+    // different parent level access based on the child level access type
+    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:
       ??
   if(ozoneManager.isNativeAuthorizerEnabled()) {
         if (aclType == IAccessAuthorizer.ACLType.CREATE ||
             aclType == IAccessAuthorizer.ACLType.DELETE ||
             aclType == IAccessAuthorizer.ACLType.WRITE_ACL) {
           parentAclRight = IAccessAuthorizer.ACLType.WRITE;
       } else {
         parentAclRight =  IAccessAuthorizer.ACLType.READ;
       }




-- 
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


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

Posted by GitBox <gi...@apache.org>.
aswinshakil commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r755593264



##########
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:
       Noted. I will update the PR.




-- 
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


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

Posted by GitBox <gi...@apache.org>.
prashantpogde commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r763305893



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneAclUtils.java
##########
@@ -0,0 +1,126 @@
+/**
+ * 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 volume owner and bucket owner.
+   * @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;
+
+    //OzoneNativeAuthorizer differs from Ranger Authorizer as Ranger requires
+    // only READ access on parent level access. OzoneNativeAuthorizer has
+    // different parent level access based on the child level access type
+    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:
       ??
   if(ozoneManager.isNativeAuthorizerEnabled()) {
         if (aclType == IAccessAuthorizer.ACLType.CREATE ||
             aclType == IAccessAuthorizer.ACLType.DELETE ||
             aclType == IAccessAuthorizer.ACLType.WRITE_ACL) {
           parentAclRight = IAccessAuthorizer.ACLType.WRITE;
        }
       } else {
         parentAclRight =  IAccessAuthorizer.ACLType.READ;
       }




-- 
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


[GitHub] [ozone] prashantpogde merged pull request #2826: HDDS-5903. Add Support for Bucket Owner Acls

Posted by GitBox <gi...@apache.org>.
prashantpogde merged pull request #2826:
URL: https://github.com/apache/ozone/pull/2826


   


-- 
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


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

Posted by GitBox <gi...@apache.org>.
aswinshakil commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r755591111



##########
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:
       Yes we fall back to the current ugi as bucket owner. This is similar to how we do it  in`createVolume` 
   https://github.com/apache/ozone/blob/e658dff34fc917bfc3504332a6ed6945b28717de/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java#L313-L314




-- 
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


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

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r754838545



##########
File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestBucketOwner.java
##########
@@ -0,0 +1,196 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.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.*;
+import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
+import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
+import org.apache.hadoop.ozone.om.request.TestOMRequestUtils;
+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.*;
+import org.junit.rules.Timeout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.UUID;
+
+import static org.apache.hadoop.ozone.OzoneConfigKeys.*;
+import static org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType.OZONE;
+import static org.junit.Assert.fail;
+
+/**
+ * Test for Ozone Bucket Owner.
+ */
+public class TestBucketOwner {
+  @Rule public Timeout timeout = Timeout.seconds(120);
+
+  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  UserGroupInformation user1 = UserGroupInformation
+          .createUserForTesting("user1", new String[] {"test1"});
+  private static UserGroupInformation user2 = UserGroupInformation
+          .createUserForTesting("user2", new String[] {"test2"});
+  private static UserGroupInformation user3 = UserGroupInformation
+          .createUserForTesting("user3", new String[] {"test3"});
+  private static OzoneClient client;
+  private static ObjectStore objectStore;
+
+  @BeforeClass
+  public static void init() throws Exception {
+    // loginUser is the user running this test.
+    UserGroupInformation.setLoginUser(adminUser);
+    OzoneConfiguration conf = new OzoneConfiguration();
+    String clusterId = UUID.randomUUID().toString();
+    String scmId = UUID.randomUUID().toString();
+    String omId = UUID.randomUUID().toString();
+    conf.set(OZONE_ACL_AUTHORIZER_CLASS, OZONE_ACL_AUTHORIZER_CLASS_NATIVE);
+    conf.setBoolean(OZONE_ACL_ENABLED, true);
+    TestOMRequestUtils.configureFSOptimizedPaths(conf, true,
+            OMConfigKeys.OZONE_OM_METADATA_LAYOUT_PREFIX);
+    cluster = MiniOzoneCluster.newBuilder(conf).setClusterId(clusterId)
+            .setScmId(scmId).setOmId(omId).build();
+    cluster.waitForClusterToBeReady();
+    client = cluster.getClient();
+    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);
+    UserGroupInformation.setLoginUser(user1);
+    client = cluster.getClient();
+    objectStore = client.getObjectStore();
+    OzoneVolume volume = objectStore.getVolume("volume1");
+    BucketArgs omBucketArgs = BucketArgs.newBuilder()
+            .setStorageType(StorageType.DISK).setOwner("user1").build();
+    volume.createBucket("bucket1", omBucketArgs);
+    volume.createBucket("bucket2", omBucketArgs);
+    volume.createBucket("bucket3", omBucketArgs);
+  }
+
+  @AfterClass
+  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);
+    OzoneVolume volume = cluster.getClient().getObjectStore()
+            .getVolume("volume1");
+    OzoneBucket ozoneBucket = volume.getBucket("bucket1");
+    //Key Create
+    createKey(ozoneBucket, "key1", 10, new byte[10]);
+    createKey(ozoneBucket, "key2", 10, new byte[10]);
+    //Key Delete
+    ozoneBucket.deleteKey("key1");
+    //Bucket Delete
+    volume.deleteBucket("bucket3");
+  }
+
+  @Test
+  public void testNonBucketNonVolumeOwner() throws Exception {
+    // Test Key Operations Non-Bucket Owner, Non-Volume Owner
+    //Key Create
+    UserGroupInformation.setLoginUser(user3);
+    OzoneBucket ozoneBucket;
+    try {
+      OzoneVolume volume = cluster.getClient().getObjectStore()
+              .getVolume("volume1");
+      ozoneBucket = volume.getBucket("bucket1");
+      createKey(ozoneBucket, "key3", 10, new byte[10]);
+      fail();
+    } catch (Exception ex) {
+      LOG.info(ex.getMessage());
+    }
+    //Key Delete - should fail
+    try {
+      OzoneVolume volume = cluster.getClient().getObjectStore()
+              .getVolume("volume1");
+      ozoneBucket = volume.getBucket("bucket1");
+      ozoneBucket.deleteKey("key2");
+      fail();

Review comment:
       ```suggestion
         fail("Delete key as non-volume and non-bucket owner should fail");
   ```

##########
File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestBucketOwner.java
##########
@@ -0,0 +1,196 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.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.*;
+import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
+import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
+import org.apache.hadoop.ozone.om.request.TestOMRequestUtils;
+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.*;
+import org.junit.rules.Timeout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.UUID;
+
+import static org.apache.hadoop.ozone.OzoneConfigKeys.*;
+import static org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType.OZONE;
+import static org.junit.Assert.fail;
+
+/**
+ * Test for Ozone Bucket Owner.
+ */
+public class TestBucketOwner {
+  @Rule public Timeout timeout = Timeout.seconds(120);
+
+  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  UserGroupInformation user1 = UserGroupInformation
+          .createUserForTesting("user1", new String[] {"test1"});
+  private static UserGroupInformation user2 = UserGroupInformation
+          .createUserForTesting("user2", new String[] {"test2"});
+  private static UserGroupInformation user3 = UserGroupInformation
+          .createUserForTesting("user3", new String[] {"test3"});
+  private static OzoneClient client;
+  private static ObjectStore objectStore;
+
+  @BeforeClass
+  public static void init() throws Exception {
+    // loginUser is the user running this test.
+    UserGroupInformation.setLoginUser(adminUser);
+    OzoneConfiguration conf = new OzoneConfiguration();
+    String clusterId = UUID.randomUUID().toString();
+    String scmId = UUID.randomUUID().toString();
+    String omId = UUID.randomUUID().toString();
+    conf.set(OZONE_ACL_AUTHORIZER_CLASS, OZONE_ACL_AUTHORIZER_CLASS_NATIVE);
+    conf.setBoolean(OZONE_ACL_ENABLED, true);
+    TestOMRequestUtils.configureFSOptimizedPaths(conf, true,
+            OMConfigKeys.OZONE_OM_METADATA_LAYOUT_PREFIX);
+    cluster = MiniOzoneCluster.newBuilder(conf).setClusterId(clusterId)
+            .setScmId(scmId).setOmId(omId).build();
+    cluster.waitForClusterToBeReady();
+    client = cluster.getClient();
+    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);
+    UserGroupInformation.setLoginUser(user1);
+    client = cluster.getClient();
+    objectStore = client.getObjectStore();
+    OzoneVolume volume = objectStore.getVolume("volume1");
+    BucketArgs omBucketArgs = BucketArgs.newBuilder()
+            .setStorageType(StorageType.DISK).setOwner("user1").build();
+    volume.createBucket("bucket1", omBucketArgs);
+    volume.createBucket("bucket2", omBucketArgs);
+    volume.createBucket("bucket3", omBucketArgs);
+  }
+
+  @AfterClass
+  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);
+    OzoneVolume volume = cluster.getClient().getObjectStore()
+            .getVolume("volume1");
+    OzoneBucket ozoneBucket = volume.getBucket("bucket1");
+    //Key Create
+    createKey(ozoneBucket, "key1", 10, new byte[10]);
+    createKey(ozoneBucket, "key2", 10, new byte[10]);
+    //Key Delete
+    ozoneBucket.deleteKey("key1");
+    //Bucket Delete
+    volume.deleteBucket("bucket3");
+  }
+
+  @Test
+  public void testNonBucketNonVolumeOwner() throws Exception {
+    // Test Key Operations Non-Bucket Owner, Non-Volume Owner
+    //Key Create
+    UserGroupInformation.setLoginUser(user3);
+    OzoneBucket ozoneBucket;
+    try {
+      OzoneVolume volume = cluster.getClient().getObjectStore()
+              .getVolume("volume1");
+      ozoneBucket = volume.getBucket("bucket1");
+      createKey(ozoneBucket, "key3", 10, new byte[10]);
+      fail();

Review comment:
       ```suggestion
         fail("Create key as non-volume and non-bucket owner should fail");
   ```

##########
File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestBucketOwner.java
##########
@@ -0,0 +1,196 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.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.*;
+import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
+import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
+import org.apache.hadoop.ozone.om.request.TestOMRequestUtils;
+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.*;
+import org.junit.rules.Timeout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.UUID;
+
+import static org.apache.hadoop.ozone.OzoneConfigKeys.*;
+import static org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType.OZONE;
+import static org.junit.Assert.fail;
+
+/**
+ * Test for Ozone Bucket Owner.
+ */
+public class TestBucketOwner {
+  @Rule public Timeout timeout = Timeout.seconds(120);
+
+  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  UserGroupInformation user1 = UserGroupInformation
+          .createUserForTesting("user1", new String[] {"test1"});
+  private static UserGroupInformation user2 = UserGroupInformation
+          .createUserForTesting("user2", new String[] {"test2"});
+  private static UserGroupInformation user3 = UserGroupInformation
+          .createUserForTesting("user3", new String[] {"test3"});
+  private static OzoneClient client;
+  private static ObjectStore objectStore;
+
+  @BeforeClass
+  public static void init() throws Exception {
+    // loginUser is the user running this test.
+    UserGroupInformation.setLoginUser(adminUser);
+    OzoneConfiguration conf = new OzoneConfiguration();
+    String clusterId = UUID.randomUUID().toString();
+    String scmId = UUID.randomUUID().toString();
+    String omId = UUID.randomUUID().toString();
+    conf.set(OZONE_ACL_AUTHORIZER_CLASS, OZONE_ACL_AUTHORIZER_CLASS_NATIVE);
+    conf.setBoolean(OZONE_ACL_ENABLED, true);
+    TestOMRequestUtils.configureFSOptimizedPaths(conf, true,
+            OMConfigKeys.OZONE_OM_METADATA_LAYOUT_PREFIX);
+    cluster = MiniOzoneCluster.newBuilder(conf).setClusterId(clusterId)
+            .setScmId(scmId).setOmId(omId).build();
+    cluster.waitForClusterToBeReady();
+    client = cluster.getClient();
+    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);
+    UserGroupInformation.setLoginUser(user1);
+    client = cluster.getClient();
+    objectStore = client.getObjectStore();
+    OzoneVolume volume = objectStore.getVolume("volume1");
+    BucketArgs omBucketArgs = BucketArgs.newBuilder()
+            .setStorageType(StorageType.DISK).setOwner("user1").build();
+    volume.createBucket("bucket1", omBucketArgs);
+    volume.createBucket("bucket2", omBucketArgs);
+    volume.createBucket("bucket3", omBucketArgs);
+  }
+
+  @AfterClass
+  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);
+    OzoneVolume volume = cluster.getClient().getObjectStore()
+            .getVolume("volume1");
+    OzoneBucket ozoneBucket = volume.getBucket("bucket1");
+    //Key Create
+    createKey(ozoneBucket, "key1", 10, new byte[10]);
+    createKey(ozoneBucket, "key2", 10, new byte[10]);
+    //Key Delete
+    ozoneBucket.deleteKey("key1");
+    //Bucket Delete
+    volume.deleteBucket("bucket3");
+  }
+
+  @Test
+  public void testNonBucketNonVolumeOwner() throws Exception {
+    // Test Key Operations Non-Bucket Owner, Non-Volume Owner
+    //Key Create
+    UserGroupInformation.setLoginUser(user3);
+    OzoneBucket ozoneBucket;
+    try {
+      OzoneVolume volume = cluster.getClient().getObjectStore()
+              .getVolume("volume1");
+      ozoneBucket = volume.getBucket("bucket1");
+      createKey(ozoneBucket, "key3", 10, new byte[10]);
+      fail();
+    } catch (Exception ex) {
+      LOG.info(ex.getMessage());
+    }
+    //Key Delete - should fail
+    try {
+      OzoneVolume volume = cluster.getClient().getObjectStore()
+              .getVolume("volume1");
+      ozoneBucket = volume.getBucket("bucket1");
+      ozoneBucket.deleteKey("key2");
+      fail();
+    } catch (Exception ex) {
+      LOG.info(ex.getMessage());
+    }
+    //Key Rename - should fail
+    try {
+      OzoneVolume volume = cluster.getClient().getObjectStore()
+              .getVolume("volume1");
+      ozoneBucket = volume.getBucket("bucket1");
+      ozoneBucket.renameKey("key2", "key4");
+      fail();

Review comment:
       ```suggestion
         fail("Rename key as non-volume and non-bucket owner should fail");
   ```




-- 
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


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

Posted by GitBox <gi...@apache.org>.
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


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

Posted by GitBox <gi...@apache.org>.
aswinshakil commented on pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#issuecomment-977297067


   Thank you for the review. I will update the PR with the suggested changes. For the above questions,
   
   1. Yes, I will resolve the Merge Conflict. 
   2. All the `checkAcls` call is already navigated to `OzoneAclUtils.checkAllAcls()`
   3. The comments for the previous PR have been addressed.


-- 
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


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

Posted by GitBox <gi...@apache.org>.
smengcl commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r755699681



##########
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:
       Ah okay, nvm, I thought the test was using `OzoneNativeAuthorizer`. It is fine in this case then.




-- 
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


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

Posted by GitBox <gi...@apache.org>.
prashantpogde commented on a change in pull request #2826:
URL: https://github.com/apache/ozone/pull/2826#discussion_r758658736



##########
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:
       if/else can be simplified.




-- 
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