Skip to content

Commit fc63710

Browse files
authored
HDDS-11833. Return NotImplemented for S3 put-object-acl request. (apache#7531)
1 parent e8ad7ad commit fc63710

File tree

18 files changed

+164
-85
lines changed

18 files changed

+164
-85
lines changed

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestMultipartObjectGet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private CompleteMultipartUploadRequest.Part uploadPart(String uploadID,
139139
ByteArrayInputStream body =
140140
new ByteArrayInputStream(content.getBytes(UTF_8));
141141
Response response = REST.put(BUCKET, KEY, content.length(),
142-
partNumber, uploadID, null, body);
142+
partNumber, uploadID, null, null, body);
143143
assertEquals(200, response.getStatus());
144144
assertNotNull(response.getHeaderString(OzoneConsts.ETAG));
145145

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v1/AbstractS3SDKV1Tests.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.amazonaws.services.s3.model.S3Object;
5151
import com.amazonaws.services.s3.model.S3ObjectInputStream;
5252
import com.amazonaws.services.s3.model.S3ObjectSummary;
53+
import com.amazonaws.services.s3.model.SetObjectAclRequest;
5354
import com.amazonaws.services.s3.model.Tag;
5455
import com.amazonaws.services.s3.model.UploadPartRequest;
5556
import com.amazonaws.services.s3.model.UploadPartResult;
@@ -375,6 +376,50 @@ public void testPutObjectEmpty() {
375376
assertEquals("d41d8cd98f00b204e9800998ecf8427e", putObjectResult.getETag());
376377
}
377378

379+
@Test
380+
public void testPutObjectACL() throws Exception {
381+
final String bucketName = getBucketName();
382+
final String keyName = getKeyName();
383+
final String content = "bar";
384+
final byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
385+
s3Client.createBucket(bucketName);
386+
387+
InputStream is = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
388+
389+
PutObjectResult putObjectResult = s3Client.putObject(bucketName, keyName, is, new ObjectMetadata());
390+
String originalObjectETag = putObjectResult.getETag();
391+
assertTrue(s3Client.doesObjectExist(bucketName, keyName));
392+
393+
AccessControlList aclList = new AccessControlList();
394+
Owner owner = new Owner("owner", "owner");
395+
aclList.withOwner(owner);
396+
Grantee grantee = new CanonicalGrantee("testGrantee");
397+
aclList.grantPermission(grantee, Permission.Read);
398+
399+
SetObjectAclRequest setObjectAclRequest = new SetObjectAclRequest(bucketName, keyName, aclList);
400+
401+
AmazonServiceException ase = assertThrows(AmazonServiceException.class,
402+
() -> s3Client.setObjectAcl(setObjectAclRequest));
403+
assertEquals("NotImplemented", ase.getErrorCode());
404+
assertEquals(501, ase.getStatusCode());
405+
assertEquals(ErrorType.Service, ase.getErrorType());
406+
407+
// Ensure that the object content remains unchanged
408+
ObjectMetadata updatedObjectMetadata = s3Client.getObjectMetadata(bucketName, keyName);
409+
assertEquals(originalObjectETag, updatedObjectMetadata.getETag());
410+
S3Object updatedObject = s3Client.getObject(bucketName, keyName);
411+
412+
try (S3ObjectInputStream s3is = updatedObject.getObjectContent();
413+
ByteArrayOutputStream bos = new ByteArrayOutputStream(contentBytes.length)) {
414+
byte[] readBuf = new byte[1024];
415+
int readLen = 0;
416+
while ((readLen = s3is.read(readBuf)) > 0) {
417+
bos.write(readBuf, 0, readLen);
418+
}
419+
assertEquals(content, bos.toString("UTF-8"));
420+
}
421+
}
422+
378423
@Test
379424
public void testGetObject() throws Exception {
380425
final String bucketName = getBucketName();

hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public enum S3GAction implements AuditAction {
5151
REVOKE_SECRET,
5252
GET_OBJECT_TAGGING,
5353
PUT_OBJECT_TAGGING,
54-
DELETE_OBJECT_TAGGING;
54+
DELETE_OBJECT_TAGGING,
55+
PUT_OBJECT_ACL;
5556

5657
@Override
5758
public String getAction() {

hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.ENTITY_TOO_SMALL;
122122
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INVALID_ARGUMENT;
123123
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INVALID_REQUEST;
124+
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.NOT_IMPLEMENTED;
124125
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.NO_SUCH_UPLOAD;
125126
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.PRECOND_FAILED;
126127
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError;
@@ -222,6 +223,7 @@ public Response put(
222223
@QueryParam("partNumber") int partNumber,
223224
@QueryParam("uploadId") @DefaultValue("") String uploadID,
224225
@QueryParam("tagging") String taggingMarker,
226+
@QueryParam("acl") String aclMarker,
225227
final InputStream body) throws IOException, OS3Exception {
226228
long startNanos = Time.monotonicNowNanos();
227229
S3GAction s3GAction = S3GAction.CREATE_KEY;
@@ -231,6 +233,10 @@ public Response put(
231233
String copyHeader = null, storageType = null;
232234
DigestInputStream digestInputStream = null;
233235
try {
236+
if (aclMarker != null) {
237+
s3GAction = S3GAction.PUT_OBJECT_ACL;
238+
throw newError(NOT_IMPLEMENTED, keyPath);
239+
}
234240
OzoneVolume volume = getVolume();
235241
if (taggingMarker != null) {
236242
s3GAction = S3GAction.PUT_OBJECT_TAGGING;
@@ -369,7 +375,9 @@ public Response put(
369375
} catch (Exception ex) {
370376
auditSuccess = false;
371377
auditWriteFailure(s3GAction, ex);
372-
if (taggingMarker != null) {
378+
if (aclMarker != null) {
379+
getMetrics().updatePutObjectAclFailureStats(startNanos);
380+
} else if (taggingMarker != null) {
373381
getMetrics().updatePutObjectTaggingFailureStats(startNanos);
374382
} else if (copyHeader != null) {
375383
getMetrics().updateCopyObjectFailureStats(startNanos);

hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/metrics/S3GatewayMetrics.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public final class S3GatewayMetrics implements Closeable, MetricsSource {
101101
private @Metric MutableCounterLong putObjectTaggingFailure;
102102
private @Metric MutableCounterLong deleteObjectTaggingSuccess;
103103
private @Metric MutableCounterLong deleteObjectTaggingFailure;
104+
private @Metric MutableCounterLong putObjectAclSuccess;
105+
private @Metric MutableCounterLong putObjectAclFailure;
104106

105107
// S3 Gateway Latency Metrics
106108
// BucketEndpoint
@@ -270,6 +272,14 @@ public final class S3GatewayMetrics implements Closeable, MetricsSource {
270272
@Metric(about = "Latency for failing to delete object tagging of a key in nanoseconds")
271273
private PerformanceMetrics deleteObjectTaggingFailureLatencyNs;
272274

275+
@Metric(about = "Latency for successfully setting an S3 object ACL " +
276+
"in nanoseconds")
277+
private PerformanceMetrics putObjectAclSuccessLatencyNs;
278+
279+
@Metric(about = "Latency for failing to set an S3 object ACL " +
280+
"in nanoseconds")
281+
private PerformanceMetrics putObjectAclFailureLatencyNs;
282+
273283
private final Map<String, PerformanceMetrics> performanceMetrics;
274284

275285
/**
@@ -411,6 +421,8 @@ public void getMetrics(MetricsCollector collector, boolean all) {
411421
deleteObjectTaggingSuccessLatencyNs.snapshot(recordBuilder, true);
412422
deleteObjectTaggingFailure.snapshot(recordBuilder, true);
413423
deleteObjectTaggingFailureLatencyNs.snapshot(recordBuilder, true);
424+
putObjectAclSuccess.snapshot(recordBuilder, true);
425+
putObjectAclFailure.snapshot(recordBuilder, true);
414426
}
415427

416428
// INC and UPDATE
@@ -662,6 +674,16 @@ public void updateDeleteObjectTaggingFailureStats(long startNanos) {
662674
this.deleteObjectTaggingFailureLatencyNs.add(Time.monotonicNowNanos() - startNanos);
663675
}
664676

677+
public void updatePutObjectAclSuccessStats(long startNanos) {
678+
this.putObjectAclSuccess.incr();
679+
this.putObjectAclSuccessLatencyNs.add(Time.monotonicNowNanos() - startNanos);
680+
}
681+
682+
public void updatePutObjectAclFailureStats(long startNanos) {
683+
this.putObjectAclFailure.incr();
684+
this.putObjectAclFailureLatencyNs.add(Time.monotonicNowNanos() - startNanos);
685+
}
686+
665687
// GET
666688
public long getListS3BucketsSuccess() {
667689
return listS3BucketsSuccess.value();

hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestListParts.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ public static void setUp() throws Exception {
7777
ByteArrayInputStream body =
7878
new ByteArrayInputStream(content.getBytes(UTF_8));
7979
response = REST.put(OzoneConsts.S3_BUCKET, OzoneConsts.KEY,
80-
content.length(), 1, uploadID, null, body);
80+
content.length(), 1, uploadID, null, null, body);
8181

8282
assertNotNull(response.getHeaderString(OzoneConsts.ETAG));
8383

8484
response = REST.put(OzoneConsts.S3_BUCKET, OzoneConsts.KEY,
85-
content.length(), 2, uploadID, null, body);
85+
content.length(), 2, uploadID, null, null, body);
8686

8787
assertNotNull(response.getHeaderString(OzoneConsts.ETAG));
8888

8989
response = REST.put(OzoneConsts.S3_BUCKET, OzoneConsts.KEY,
90-
content.length(), 3, uploadID, null, body);
90+
content.length(), 3, uploadID, null, null, body);
9191

9292
assertNotNull(response.getHeaderString(OzoneConsts.ETAG));
9393
}

hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestMultipartUploadComplete.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private Part uploadPart(String key, String uploadID, int partNumber, String
109109
ByteArrayInputStream body =
110110
new ByteArrayInputStream(content.getBytes(UTF_8));
111111
Response response = REST.put(OzoneConsts.S3_BUCKET, key, content.length(),
112-
partNumber, uploadID, null, body);
112+
partNumber, uploadID, null, null, body);
113113
assertEquals(200, response.getStatus());
114114
assertNotNull(response.getHeaderString(OzoneConsts.ETAG));
115115
Part part = new Part();

hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestMultipartUploadWithCopy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ private Part uploadPart(String key, String uploadID, int partNumber, String
330330
ByteArrayInputStream body =
331331
new ByteArrayInputStream(content.getBytes(UTF_8));
332332
Response response = REST.put(OzoneConsts.S3_BUCKET, key, content.length(),
333-
partNumber, uploadID, null, body);
333+
partNumber, uploadID, null, null, body);
334334
assertEquals(200, response.getStatus());
335335
assertNotNull(response.getHeaderString(OzoneConsts.ETAG));
336336
Part part = new Part();
@@ -375,7 +375,7 @@ private Part uploadPartWithCopy(String key, String uploadID, int partNumber,
375375

376376
ByteArrayInputStream body = new ByteArrayInputStream("".getBytes(UTF_8));
377377
Response response = REST.put(OzoneConsts.S3_BUCKET, key, 0, partNumber,
378-
uploadID, null, body);
378+
uploadID, null, null, body);
379379
assertEquals(200, response.getStatus());
380380

381381
CopyPartResult result = (CopyPartResult) response.getEntity();
@@ -402,7 +402,7 @@ public void testUploadWithRangeCopyContentLength()
402402
OzoneConsts.S3_BUCKET + "/" + EXISTING_KEY);
403403
additionalHeaders.put(COPY_SOURCE_HEADER_RANGE, "bytes=0-3");
404404
setHeaders(additionalHeaders);
405-
REST.put(OzoneConsts.S3_BUCKET, KEY, 0, 1, uploadID, null, body);
405+
REST.put(OzoneConsts.S3_BUCKET, KEY, 0, 1, uploadID, null, null, body);
406406
OzoneMultipartUploadPartListParts parts =
407407
CLIENT.getObjectStore().getS3Bucket(OzoneConsts.S3_BUCKET)
408408
.listParts(KEY, uploadID, 0, 100);

hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectGet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ public void init() throws OS3Exception, IOException {
9595

9696
ByteArrayInputStream body = new ByteArrayInputStream(CONTENT.getBytes(UTF_8));
9797
rest.put(BUCKET_NAME, KEY_NAME, CONTENT.length(),
98-
1, null, null, body);
98+
1, null, null, null, body);
9999
// Create a key with object tags
100100
when(headers.getHeaderString(TAG_HEADER)).thenReturn("tag1=value1&tag2=value2");
101101
rest.put(BUCKET_NAME, KEY_WITH_TAG, CONTENT.length(),
102-
1, null, null, body);
102+
1, null, null, null, body);
103103

104104
context = mock(ContainerRequestContext.class);
105105
when(context.getUriInfo()).thenReturn(mock(UriInfo.class));

0 commit comments

Comments
 (0)