-
Notifications
You must be signed in to change notification settings - Fork 587
HDDS-8511. Enforce strict S3-compliant name for object store buckets #9462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
df9d920
ac35a4e
28ccd86
a7349c6
d3fcfc0
c3aad96
cad0e4a
3a62c7d
5609201
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -322,7 +322,7 @@ public void testAcceptNonS3CompliantBucketNameCreationWithStrictS3False() | |
| {"bucket_underscore", "_bucket___multi_underscore_", "bucket_"}; | ||
| when(ozoneManager.isStrictS3()).thenReturn(false); | ||
| for (String bucketName : nonS3CompliantBucketName) { | ||
| acceptBucketCreationHelper(volumeName, bucketName); | ||
| acceptFSOBucketCreationHelper(volumeName, bucketName); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -478,4 +478,28 @@ public static void addCreateVolumeToTable(String volumeName, | |
| .setOwnerName(UUID.randomUUID().toString()).build(); | ||
| OMRequestTestUtils.addVolumeToOM(omMetadataManager, omVolumeArgs); | ||
| } | ||
|
|
||
| protected OMBucketCreateRequest doPreExecute(String volumeName, | ||
| String bucketName, | ||
| OzoneManagerProtocolProtos.BucketLayoutProto layout) throws Exception { | ||
|
||
|
|
||
| OzoneManagerProtocolProtos.BucketInfo.Builder bucketInfo = | ||
| newBucketInfoBuilder(bucketName, volumeName) | ||
| .setBucketLayout(layout); | ||
|
|
||
| if (layout == OzoneManagerProtocolProtos.BucketLayoutProto.FILE_SYSTEM_OPTIMIZED) { | ||
| bucketInfo.addMetadata(OMRequestTestUtils.fsoMetadata()); | ||
| } | ||
|
|
||
| return doPreExecute(bucketInfo); | ||
| } | ||
|
|
||
| private void acceptFSOBucketCreationHelper(String volumeName, String bucketName) | ||
| throws Exception { | ||
| OMBucketCreateRequest omBucketCreateRequest = | ||
| doPreExecute(volumeName, bucketName, | ||
| OzoneManagerProtocolProtos.BucketLayoutProto.FILE_SYSTEM_OPTIMIZED); | ||
| doValidateAndUpdateCache(volumeName, bucketName, | ||
| omBucketCreateRequest.getOmRequest()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * 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.request.bucket; | ||
|
|
||
| import static org.apache.hadoop.ozone.om.request.OMRequestTestUtils.newBucketInfoBuilder; | ||
| import static org.apache.hadoop.ozone.om.request.OMRequestTestUtils.newCreateBucketRequest; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import java.util.UUID; | ||
| import org.apache.hadoop.ozone.om.OMConfigKeys; | ||
| import org.apache.hadoop.ozone.om.exceptions.OMException; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Tests bucket creation behavior for ObjectStore / Legacy bucket layouts. | ||
| */ | ||
| public class TestOMBucketCreateRequestWithObjectStore extends TestOMBucketCreateRequest { | ||
|
|
||
| @BeforeEach | ||
| public void setupWithObjectStore() { | ||
| ozoneManager.getConfiguration().set( | ||
| OMConfigKeys.OZONE_DEFAULT_BUCKET_LAYOUT, | ||
| OMConfigKeys.OZONE_BUCKET_LAYOUT_OBJECT_STORE); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNonS3BucketNameRejectedForObjectStoreWhenStrictDisabled() | ||
| throws Exception { | ||
|
|
||
| // strict mode disabled | ||
| ozoneManager.getConfiguration().setBoolean( | ||
| OMConfigKeys.OZONE_OM_NAMESPACE_STRICT_S3, false); | ||
|
|
||
| String volumeName = UUID.randomUUID().toString(); | ||
| String bucketName = "bucket_with_underscore"; // non-S3-compliant | ||
| addCreateVolumeToTable(volumeName, omMetadataManager); | ||
|
|
||
| // Explicitly set bucket layout to OBJECT_STORE so the test doesn't depend on | ||
| // defaults or mocked OM behavior. | ||
| OzoneManagerProtocolProtos.BucketInfo.Builder bucketInfo = | ||
| newBucketInfoBuilder(bucketName, volumeName) | ||
| .setBucketLayout( | ||
| OzoneManagerProtocolProtos.BucketLayoutProto.OBJECT_STORE); | ||
|
||
|
|
||
| OMRequest originalRequest = newCreateBucketRequest(bucketInfo).build(); | ||
| OMBucketCreateRequest req = new OMBucketCreateRequest(originalRequest); | ||
|
|
||
| OMException ex = assertThrows(OMException.class, | ||
| () -> req.preExecute(ozoneManager)); | ||
|
|
||
| assertEquals(OMException.ResultCodes.INVALID_BUCKET_NAME, ex.getResult()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding this logic, please mock
ozoneManager.getConfig()inTestOMClientRequestWithUserInfo:ozone/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/TestOMClientRequestWithUserInfo.java
Line 80 in 66cb1e7
like:
ozone/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/file/TestOMDirectoryCreateRequest.java
Lines 101 to 102 in 66cb1e7