ivandika3 commented on code in PR #8558:
URL: https://github.com/apache/ozone/pull/8558#discussion_r2134400058


##########
hadoop-ozone/integration-test-s3/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v2/AbstractS3SDKV2Tests.java:
##########
@@ -621,4 +648,512 @@ private void completeMultipartUpload(String bucketName, 
String key, String uploa
     assertEquals(bucketName, compResponse.bucket());
     assertEquals(key, compResponse.key());
   }
+
+  @Nested
+  @TestInstance(TestInstance.Lifecycle.PER_CLASS)
+  class S3BucketVerificationConditionTests {
+
+    private static final String DEFAULT_BUCKET_NAME = "default-bucket";
+    private String correctOwner;
+    private static final String WRONG_OWNER = "wrong-owner";
+    private static final String BUCKET_VERIFICATION_TEST_KEY = "test-key";
+
+    @BeforeAll
+    public void setup() throws Exception {

Review Comment:
   Thanks for the extensive tests. 
   
   For completeness, we can try to add a ownership check on linked bucket. This 
can be done by 1) creating a bucket under volume other than `/s3v` volume and 
then 2) create a link bucket under the `/s3v` volume referring to the source 
bucket. You can take a look at `LinkBucketHandler` for the implementation. 
Since `OzoneManager#getBucketInfo` will resolve the bucket link and check the 
source bucket info (including the owner), there should not be any issues.
   
   Additionally, we can also test on the dangling bucket, This can be done by 
1) creating a bucket under volume other than `/s3v` volume and then 2) create a 
link bucket under the `/s3v` volume referring to the source bucket and 3) 
deleting the source bucket. I think for this case this will return null owner 
since the linked bucket does not contain owner field.



##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketOwnerCondition.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.s3.endpoint;
+
+import javax.ws.rs.core.HttpHeaders;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.s3.util.S3Consts;
+
+/**
+ * Bucket owner condition to verify bucket ownership.
+ * <p>
+ * See: 
https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-owner-condition.html
+ * for more details
+ */
+public final class BucketOwnerCondition {
+
+  public static final String ERROR_MESSAGE = "Expected bucket owner does not 
match";
+
+  private BucketOwnerCondition() {
+
+  }
+
+  /**
+   * Verify the bucket owner condition.
+   *
+   * @param headers       HTTP headers
+   * @param bucketOwner   bucket owner
+   * @throws OMException if the expected bucket owner does not match the actual
+   *                     bucket owner
+   */
+  public static void verify(HttpHeaders headers, String bucketOwner) throws 
OMException {
+    if (headers == null) {
+      return;
+    }
+
+    final String expectedBucketOwner = 
headers.getHeaderString(S3Consts.EXPECTED_BUCKET_OWNER_HEADER);
+    // client does not use this feature
+    if (expectedBucketOwner == null) {
+      return;
+    }
+    if (expectedBucketOwner.equals(bucketOwner)) {
+      return;
+    }
+    throw new OMException(ERROR_MESSAGE, 
OMException.ResultCodes.PERMISSION_DENIED);
+  }
+
+  /**
+   * Verify the copy operation's source and destination bucket owners.
+   *
+   * @param headers       HTTP headers
+   * @param sourceOwner   source bucket owner
+   * @param destOwner     destination bucket owner
+   * @throws OMException if the expected source or destination bucket owner 
does
+   *                     not match the actual owners
+   */
+  public static void verifyCopyOperation(HttpHeaders headers, String 
sourceOwner, String destOwner) throws OMException {

Review Comment:
   Similar to the previous comment, we also might need to handle null bucket 
owners and simply skip the verification.



##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketOwnerCondition.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.s3.endpoint;
+
+import javax.ws.rs.core.HttpHeaders;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.s3.util.S3Consts;
+
+/**
+ * Bucket owner condition to verify bucket ownership.
+ * <p>
+ * See: 
https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-owner-condition.html
+ * for more details
+ */
+public final class BucketOwnerCondition {
+
+  public static final String ERROR_MESSAGE = "Expected bucket owner does not 
match";
+
+  private BucketOwnerCondition() {
+
+  }
+
+  /**
+   * Verify the bucket owner condition.
+   *
+   * @param headers       HTTP headers
+   * @param bucketOwner   bucket owner
+   * @throws OMException if the expected bucket owner does not match the actual
+   *                     bucket owner
+   */
+  public static void verify(HttpHeaders headers, String bucketOwner) throws 
OMException {

Review Comment:
   HDDS-5903 introduced the bucket owner field from 1.3.0 version onwards. We 
might need to handle null `bucketOwner` for old buckets (before 1.3.0) by just 
skipping the bucket owner condition to prevent access denied / NPE. We can test 
this behavior if possible.



##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketOwnerCondition.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.s3.endpoint;
+
+import javax.ws.rs.core.HttpHeaders;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.s3.util.S3Consts;
+
+/**
+ * Bucket owner condition to verify bucket ownership.
+ * <p>
+ * See: 
https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-owner-condition.html
+ * for more details
+ */
+public final class BucketOwnerCondition {
+
+  public static final String ERROR_MESSAGE = "Expected bucket owner does not 
match";
+
+  private BucketOwnerCondition() {
+
+  }
+
+  /**
+   * Verify the bucket owner condition.
+   *
+   * @param headers       HTTP headers
+   * @param bucketOwner   bucket owner
+   * @throws OMException if the expected bucket owner does not match the actual
+   *                     bucket owner
+   */
+  public static void verify(HttpHeaders headers, String bucketOwner) throws 
OMException {
+    if (headers == null) {
+      return;
+    }
+
+    final String expectedBucketOwner = 
headers.getHeaderString(S3Consts.EXPECTED_BUCKET_OWNER_HEADER);
+    // client does not use this feature
+    if (expectedBucketOwner == null) {

Review Comment:
   There was some previous instances where some other S3-compatible client 
(e.g. Minio Client) uses empty string as the argument although the argument 
should not be specified (e.g. empty delimiter string in 
https://github.com/apache/ozone/pull/4410). I think we can also use 
`StringUtils#isEmpty` for this.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to