mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): apply and check the Object Lock headers of every object creation (#5828)
CopyObject ignored its Object Lock headers, and CreateMultipartUpload ignored those and its grant headers, so the copy or the completed upload came out without the lock or the grants the request asked for. PutObject read the lock headers without checking them: a malformed retain-until date was a 500, and a mode without a date, a date without a mode or an unknown mode was accepted. PutObject, CopyObject and CreateMultipartUpload now read the lock headers through one check that refuses them as S3 does, with InvalidArgument naming the header: a mode and a date come together, checked first, and the mode is GOVERNANCE or COMPLIANCE. A date that is not an ISO 8601 timestamp is refused the same way. CopyObject applies the settings to the copy. CreateMultipartUpload keeps them and its grants, and applies them when the upload completes. Its grants are checked when the upload is created, under the bucket-owner-enforced rule PutObject uses, so a grant S3 refuses fails the creation rather than the completion. Refs #5716
This commit is contained in:
1 parent
caa606ba7d
commit
792260ed49
8 files changed
+355
-28
No files matched your search
@@ -402,4 +402,53 @@ class S3AclIntegrationTest {
|
||||
.body(containsString("<Permission>FULL_CONTROL</Permission>"))
|
||||
.body(not(containsString(ALL_USERS_GROUP_URI)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
void initiateMultipartUploadAppliesExplicitGrantReadHeaderOnComplete() {
|
||||
String uploadId = given()
|
||||
.header("x-amz-grant-read", "uri=\"" + ALL_USERS_GROUP_URI + "\"")
|
||||
.when()
|
||||
.post("/" + BUCKET + "/multipart-grant.txt?uploads")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
|
||||
String partETag = given()
|
||||
.body("part-one")
|
||||
.when()
|
||||
.put("/" + BUCKET + "/multipart-grant.txt?uploadId=" + uploadId + "&partNumber=1")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().header("ETag");
|
||||
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.body("<CompleteMultipartUpload><Part><PartNumber>1</PartNumber><ETag>" + partETag
|
||||
+ "</ETag></Part></CompleteMultipartUpload>")
|
||||
.when()
|
||||
.post("/" + BUCKET + "/multipart-grant.txt?uploadId=" + uploadId)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "/multipart-grant.txt?acl")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString(ALL_USERS_GROUP_URI))
|
||||
.body(containsString("<Permission>READ</Permission>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
void initiateMultipartUploadRejectsExplicitGrantByEmailAddress() {
|
||||
// Refused when the upload is created, as PutObject refuses it, not when it completes.
|
||||
given()
|
||||
.header("x-amz-grant-read", "emailAddress=\"someone@example.com\"")
|
||||
.when()
|
||||
.post("/" + BUCKET + "/multipart-grant-email.txt?uploads")
|
||||
.then()
|
||||
.statusCode(501)
|
||||
.body(containsString("NotImplemented"));
|
||||
}
|
||||
}
|
||||
+117
@@ -1,6 +1,9 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -390,4 +393,118 @@ class S3ObjectLockIntegrationTest {
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
}
|
||||
|
||||
// --- Object Lock headers on CopyObject and CreateMultipartUpload ---
|
||||
|
||||
@Test
|
||||
@Order(22)
|
||||
void copyObjectAppliesItsObjectLockHeaders() {
|
||||
given().body("source").when().put("/" + LOCK_BUCKET + "/copy-lock-source.txt").then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("x-amz-copy-source", "/" + LOCK_BUCKET + "/copy-lock-source.txt")
|
||||
.header("x-amz-object-lock-mode", "GOVERNANCE")
|
||||
.header("x-amz-object-lock-retain-until-date", "2099-01-01T00:00:00Z")
|
||||
.header("x-amz-object-lock-legal-hold", "ON")
|
||||
.when()
|
||||
.put("/" + LOCK_BUCKET + "/copy-lock-target.txt")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
assertLockedUntil2099("/" + LOCK_BUCKET + "/copy-lock-target.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
void multipartUploadAppliesItsObjectLockHeadersOnCompletion() {
|
||||
String path = "/" + LOCK_BUCKET + "/multipart-lock.txt";
|
||||
String uploadId = given()
|
||||
.header("x-amz-object-lock-mode", "GOVERNANCE")
|
||||
.header("x-amz-object-lock-retain-until-date", "2099-01-01T00:00:00Z")
|
||||
.header("x-amz-object-lock-legal-hold", "ON")
|
||||
.when()
|
||||
.post(path + "?uploads")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
|
||||
String partETag = given()
|
||||
.body("part-one")
|
||||
.when()
|
||||
.put(path + "?uploadId=" + uploadId + "&partNumber=1")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().header("ETag");
|
||||
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.body("<CompleteMultipartUpload><Part><PartNumber>1</PartNumber><ETag>" + partETag
|
||||
+ "</ETag></Part></CompleteMultipartUpload>")
|
||||
.when()
|
||||
.post(path + "?uploadId=" + uploadId)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
assertLockedUntil2099(path);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
void objectLockHeadersAreCheckedOnEveryObjectCreation() {
|
||||
// The errors S3 was recorded answering: a mode and a date come together, and the mode is one
|
||||
// S3 knows. The unparseable date was not recorded, and is refused the same way.
|
||||
String copySource = "/" + LOCK_BUCKET + "/copy-lock-source.txt";
|
||||
for (String[] request : new String[][] {{"put", null}, {"copy", copySource}, {"upload", null}}) {
|
||||
assertInvalidLockHeaders(request[0], request[1], "GOVERNANCE", null,
|
||||
"x-amz-object-lock-retain-until-date", null, "must both be supplied");
|
||||
assertInvalidLockHeaders(request[0], request[1], null, "2099-01-01T00:00:00Z",
|
||||
"x-amz-object-lock-mode", null, "must both be supplied");
|
||||
assertInvalidLockHeaders(request[0], request[1], "BAD-VALUE", "2099-01-01T00:00:00Z",
|
||||
"x-amz-object-lock-mode", "BAD-VALUE", "Unknown wormMode directive.");
|
||||
assertInvalidLockHeaders(request[0], request[1], "GOVERNANCE", "next-week",
|
||||
"x-amz-object-lock-retain-until-date", "next-week", "ISO 8601");
|
||||
}
|
||||
}
|
||||
|
||||
/** A PutObject, a CopyObject of {@code copySource} or a CreateMultipartUpload refused for its lock headers. */
|
||||
private static void assertInvalidLockHeaders(String operation, String copySource, String mode, String until,
|
||||
String argumentName, String argumentValue, String message) {
|
||||
RequestSpecification request = given();
|
||||
if (mode != null) {
|
||||
request = request.header("x-amz-object-lock-mode", mode);
|
||||
}
|
||||
if (until != null) {
|
||||
request = request.header("x-amz-object-lock-retain-until-date", until);
|
||||
}
|
||||
String path = "/" + LOCK_BUCKET + "/invalid-lock-" + operation + ".txt";
|
||||
Response response = switch (operation) {
|
||||
case "put" -> request.body("x").when().put(path);
|
||||
case "copy" -> request.header("x-amz-copy-source", copySource).when().put(path);
|
||||
default -> request.when().post(path + "?uploads");
|
||||
};
|
||||
ValidatableResponse then = response.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>InvalidArgument</Code>"))
|
||||
.body(containsString(message))
|
||||
.body(containsString("<ArgumentName>" + argumentName + "</ArgumentName>"));
|
||||
if (argumentValue != null) {
|
||||
then.body(containsString("<ArgumentValue>" + argumentValue + "</ArgumentValue>"));
|
||||
}
|
||||
}
|
||||
|
||||
/** The object holds the GOVERNANCE retention until 2099 and the legal hold its request set. */
|
||||
private static void assertLockedUntil2099(String path) {
|
||||
given()
|
||||
.when()
|
||||
.get(path + "?retention")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Mode>GOVERNANCE</Mode>"))
|
||||
.body(containsString("<RetainUntilDate>2099-01-01T00:00:00"));
|
||||
given()
|
||||
.when()
|
||||
.get(path + "?legal-hold")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Status>ON</Status>"));
|
||||
}
|
||||
}
|
||||
+8
@@ -166,6 +166,14 @@ class S3OwnershipControlsIntegrationTest {
|
||||
.statusCode(400)
|
||||
.body(containsString("AccessControlListNotSupported"));
|
||||
|
||||
given()
|
||||
.header("x-amz-grant-read", "uri=\"http://acs.amazonaws.com/groups/global/AllUsers\"")
|
||||
.when()
|
||||
.post("/" + BUCKET + "/rejected-multipart-grant?uploads")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("AccessControlListNotSupported"));
|
||||
|
||||
given()
|
||||
.body("new object")
|
||||
.when()
|
||||
|
||||
Reference in new issue
Block a user