Light, fluffy, and always free - The AWS Local Emulator alternative
fix(s3): default new buckets to BucketOwnerEnforced (#5782)
XuJiand1509c368f2b
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3BlockPublicAccessTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3BlockPublicAccessTest.javaindex 6a49e8af80..7b063b29f6 100644--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3BlockPublicAccessTest.java+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3BlockPublicAccessTest.java@@ -16,8 +16,12 @@ import software.amazon.awssdk.services.s3.model.GetBucketPolicyRequest;import software.amazon.awssdk.services.s3.model.GetPublicAccessBlockRequest;import software.amazon.awssdk.services.s3.model.GetPublicAccessBlockResponse;import software.amazon.awssdk.services.s3.model.ObjectCannedACL;+import software.amazon.awssdk.services.s3.model.ObjectOwnership;+import software.amazon.awssdk.services.s3.model.OwnershipControls;+import software.amazon.awssdk.services.s3.model.OwnershipControlsRule;import software.amazon.awssdk.services.s3.model.PublicAccessBlockConfiguration;import software.amazon.awssdk.services.s3.model.PutBucketAclRequest;+import software.amazon.awssdk.services.s3.model.PutBucketOwnershipControlsRequest;import software.amazon.awssdk.services.s3.model.PutBucketPolicyRequest;import software.amazon.awssdk.services.s3.model.PutObjectRequest;import software.amazon.awssdk.services.s3.model.PutPublicAccessBlockRequest;@@ -63,6 +67,13 @@ class S3BlockPublicAccessTest {} catch (BucketAlreadyOwnedByYouException expected) {// A previous run of this suite left the bucket behind; reuse it.}+ s3.putBucketOwnershipControls(PutBucketOwnershipControlsRequest.builder()+ .bucket(BUCKET)+ .ownershipControls(OwnershipControls.builder()+ .rules(OwnershipControlsRule.builder()+ .objectOwnership(ObjectOwnership.OBJECT_WRITER).build())+ .build())+ .build());s3.putPublicAccessBlock(PutPublicAccessBlockRequest.builder().bucket(BUCKET).publicAccessBlockConfiguration(PublicAccessBlockConfiguration.builder()diff --git a/docs/services/s3.md b/docs/services/s3.mdindex d86606670c..84b069bd83 100644--- a/docs/services/s3.md+++ b/docs/services/s3.md@@ -392,6 +392,10 @@ When a request is denied by bucket policy enforcement, Floci returns HTTP 403 wi</Error>```+## Object Ownership and ACLs++New buckets start with `BucketOwnerEnforced` ownership, matching the current S3 default. `GetBucketOwnershipControls` returns that setting immediately after `CreateBucket`. Bucket and object ACL writes are disabled, while uploads without an ACL and uploads using `bucket-owner-full-control` remain supported. To use ACL grants, set `x-amz-object-ownership` to `ObjectWriter` or `BucketOwnerPreferred` during `CreateBucket`, or change the mode later with `PutBucketOwnershipControls`. Existing stored buckets keep their previously configured ownership mode.+## Block Public AccessFloci enforces all four Block Public Access settings. A bucket's configuration is combined with the bucket owner account's and the most restrictive of the two wins, which for four independent booleans is a per-flag OR: a flag set at either level is in force.@@ -425,7 +429,7 @@ A single public statement makes the whole policy public. As on AWS, `RestrictPub- Floci does not model access points, so the access-point variants (`PutAccessPointPolicy`, the VPC-origin rule, the different `s3:DataAccessPointArn` treatment) do not apply.- AWS's organization-level Block Public Access policies are not modelled; only the bucket and account levels combine.-- `CreateBucket` does not apply an `x-amz-acl` at all in Floci, so there is no public bucket ACL at creation for the account-level `BlockPublicAcls` to reject.+- `CreateBucket` applies compatible ACL headers but rejects public ACLs with HTTP 400, including on `ObjectWriter` buckets, because new buckets start with Block Public Access enabled. After creation, an `ObjectWriter` bucket without an explicit `PutPublicAccessBlock` still accepts a public `PutBucketAcl`; default bucket-level enforcement remains a gap.- `GetBucketAcl` returns the stored ACL rather than the effective one, so it does not reflect an `IgnorePublicAcls` that is suppressing a grant.- `GetBucketPolicyStatus` has no handler.- `RestrictPublicBuckets` exempts AWS service principals on AWS. Floci reaches the signed path only for IAM principals, so there is nothing to exempt.diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.javaindex 38b09d78df..e2012ee71c 100644--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java@@ -451,7 +451,14 @@ public class S3Controller {new String(body, StandardCharsets.UTF_8), "Tag", "Key", "Value");}String region = bucketRegionForCreate(locationConstraint, regionResolver.resolveRegion(httpHeaders));- s3Service.createBucket(bucket, region);+ s3Service.createBucket(bucket, region,+ httpHeaders.getHeaderString("x-amz-object-ownership"),+ httpHeaders.getHeaderString("x-amz-acl"),+ httpHeaders.getHeaderString("x-amz-grant-read"),+ httpHeaders.getHeaderString("x-amz-grant-write"),+ httpHeaders.getHeaderString("x-amz-grant-full-control"),+ httpHeaders.getHeaderString("x-amz-grant-read-acp"),+ httpHeaders.getHeaderString("x-amz-grant-write-acp"));// CreateBucketConfiguration may carry a <Tags> array; AWS applies those tags to the// new bucket, so a follow-up GetBucketTagging / ListTagsForResource must return them.if (!creationTags.isEmpty()) {diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.javaindex 843af4db42..877a2ddddb 100644--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java@@ -120,6 +120,8 @@ public class S3Service implements Resettable, ResourceProvider {private static final String LEGACY_ACCESS_KEY_ID = "test";private static final String S3_XML_SCHEMA_ERROR ="The XML you provided was not well-formed or did not validate against our published schema.";+ private static final Set<String> OBJECT_OWNERSHIP_VALUES = Set.of(+ "BucketOwnerEnforced", "BucketOwnerPreferred", "ObjectWriter");private static final Set<String> SUPPORTED_SERVER_SIDE_ENCRYPTION_VALUES = Set.of("AES256", "aws:kms", "aws:kms:dsse", "aws:fsx");private static final String SSE_C_ALGORITHM = "AES256";private static final int SSE_C_KEY_BYTES = 32;@@ -465,7 +467,35 @@ public class S3Service implements Resettable, ResourceProvider {}public Bucket createBucket(String bucketName, String region) {+ return createBucket(bucketName, region, null, null, null, null, null, null, null);+ }++ public Bucket createBucket(String bucketName, String region, String requestedOwnership,+ String cannedAcl, String grantRead, String grantWrite,+ String grantFullControl, String grantReadAcp, String grantWriteAcp) {requirePathSafeBucketName(bucketName);+ String ownership = requestedOwnership == null ? "BucketOwnerEnforced" : requestedOwnership;+ if (!OBJECT_OWNERSHIP_VALUES.contains(ownership)) {+ throw new AwsException("InvalidArgument", "Invalid x-amz-object-ownership value: " + ownership, 400);+ }+ if (!isBlank(cannedAcl) && (!isBlank(grantRead) || !isBlank(grantWrite)+ || !isBlank(grantFullControl) || !isBlank(grantReadAcp) || !isBlank(grantWriteAcp))) {+ throw new AwsException("InvalidRequest", "Specifying both Canned ACLs and Header Grants is not allowed", 400);+ }+ String requestedAcl = resolveObjectAclXml(cannedAcl, grantRead, grantWrite,+ grantFullControl, grantReadAcp, grantWriteAcp);+ if ("BucketOwnerEnforced".equals(ownership)+ && (!isBlank(grantRead) || !isBlank(grantWrite) || !isBlank(grantReadAcp)+ || !isBlank(grantWriteAcp)+ || (!isBlank(grantFullControl) && !isOnlyOwnerFullControlGrant(ownerId(), grantFullControl))+ || S3AclPublicAccessEvaluator.aclGrantsNonOwner(requestedAcl, ownerId()))) {+ throw new AwsException("InvalidBucketAclWithObjectOwnership",+ "Bucket cannot have ACLs set with ObjectOwnership's BucketOwnerEnforced setting", 400);+ }+ if (S3AclPublicAccessEvaluator.aclIsPublic(requestedAcl)) {+ throw new AwsException("InvalidBucketAclWithBlockPublicAccessError",+ "Bucket cannot have public ACLs set with BlockPublicAccess enabled", 400);+ }var existing = bucketStore.get(bucketName);if (existing.isPresent()) {Bucket bucket = existing.get();@@ -479,11 +509,23 @@ public class S3Service implements Resettable, ResourceProvider {Bucket bucket = new Bucket(bucketName);bucket.setRegion(region);+ bucket.setOwnershipControlsConfiguration(ownershipControlsXml(ownership));+ bucket.setAcl(requestedAcl);bucketStore.put(bucketName, bucket);LOG.infov("Created bucket: {0} in region: {1}", bucketName, region);return bucket;}+ private static String ownershipControlsXml(String ownership) {+ return new XmlBuilder()+ .start("OwnershipControls", AwsNamespaces.S3)+ .start("Rule")+ .elem("ObjectOwnership", ownership)+ .end("Rule")+ .end("OwnershipControls")+ .build();+ }+private static boolean isDefaultS3Region(String region) {return region == null || region.isBlank() || "us-east-1".equalsIgnoreCase(region); // partition-literal: S3's idempotent CreateBucket rule is literally us-east-1 in every partition}@@ -5688,8 +5730,7 @@ public class S3Service implements Resettable, ResourceProvider {if (rule.count("ObjectOwnership") != 1 || ownership == null) {throw new AwsException("MalformedXML", S3_XML_SCHEMA_ERROR, 400);}- if (!Set.of("BucketOwnerPreferred", "ObjectWriter", "BucketOwnerEnforced")- .contains(ownership.text())) {+ if (!OBJECT_OWNERSHIP_VALUES.contains(ownership.text())) {throw new AwsException("MalformedXML", S3_XML_SCHEMA_ERROR, 400);}}diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontS3AuthServingTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontS3AuthServingTest.javaindex 7ac7503cac..4614141c55 100644--- a/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontS3AuthServingTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontS3AuthServingTest.java@@ -78,6 +78,8 @@ class CloudFrontS3AuthServingTest {false,null,"origin-access-identity/cloudfront/" + oai.getId());+ s3Service.putBucketOwnershipControls(bucket, "<OwnershipControls><Rule>"+ + "<ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>");s3Service.putObjectAcl(bucket,"index.html",diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3AclIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3AclIntegrationTest.javaindex 2fdd77c985..8db3a78353 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3AclIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3AclIntegrationTest.java@@ -28,6 +28,13 @@ class S3AclIntegrationTest {.put("/" + BUCKET).then().statusCode(200);++ given()+ .body("<OwnershipControls><Rule><ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>")+ .when()+ .put("/" + BUCKET + "?ownershipControls")+ .then()+ .statusCode(200);}@Testdiff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3AuthEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3AuthEnforcementIntegrationTest.javaindex aaf50d6b16..2da195cc80 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3AuthEnforcementIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3AuthEnforcementIntegrationTest.java@@ -76,11 +76,18 @@ class S3AuthEnforcementIntegrationTest {private static final S3RequestSigner BAD_KEY_SIGNER = S3RequestSigner.signedAs("bad-key", "bad-secret");private static final S3RequestSigner ACCOUNT_SHAPED_SIGNER = S3RequestSigner.signedAs("123456789012", "test");+ private static void enableLegacyAcls(String bucket) {+ given().filter(LOCAL_SIGNER)+ .body("<OwnershipControls><Rule><ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>")+ .when().put("/" + bucket + "?ownershipControls").then().statusCode(200);+ }+@Test@Order(1)void createBucketsAndObjects() {given().filter(LOCAL_SIGNER).when().put("/" + PUBLIC_BUCKET).then().statusCode(200);given().filter(LOCAL_SIGNER).when().put("/" + PRIVATE_BUCKET).then().statusCode(200);+ enableLegacyAcls(PUBLIC_BUCKET);given().filter(LOCAL_SIGNER)@@ -356,6 +363,7 @@ class S3AuthEnforcementIntegrationTest {@Order(14)void bucketAclPublicReadAllowsUnsignedList() {given().filter(LOCAL_SIGNER).when().put("/" + BUCKET_ACL_BUCKET).then().statusCode(200);+ enableLegacyAcls(BUCKET_ACL_BUCKET);given().filter(LOCAL_SIGNER)@@ -386,6 +394,7 @@ class S3AuthEnforcementIntegrationTest {@Order(15)void explicitBucketPolicyDenyOverridesPublicObjectAcl() {given().filter(LOCAL_SIGNER).when().put("/" + DENY_BUCKET).then().statusCode(200);+ enableLegacyAcls(DENY_BUCKET);given().filter(LOCAL_SIGNER)@@ -1137,6 +1146,7 @@ class S3AuthEnforcementIntegrationTest {// non-owners the ability to overwrite or delete existing objects" -- it only lets them// create new ones.given().filter(LOCAL_SIGNER).when().put("/" + PUBLIC_WRITE_ACL_BUCKET).then().statusCode(200);+ enableLegacyAcls(PUBLIC_WRITE_ACL_BUCKET);given().filter(LOCAL_SIGNER)@@ -1181,6 +1191,7 @@ class S3AuthEnforcementIntegrationTest {@Order(39)void explicitPolicyDenyOverridesPublicWriteAcl() {given().filter(LOCAL_SIGNER).when().put("/" + DENY_WRITE_ACL_BUCKET).then().statusCode(200);+ enableLegacyAcls(DENY_WRITE_ACL_BUCKET);given().filter(LOCAL_SIGNER)@@ -1366,6 +1377,7 @@ class S3AuthEnforcementIntegrationTest {// is treated as applying (fail closed) -- consistent with S3PublicAccessEvaluatorTest's// conditionalDenyFailsClosedAndOverridesAllow, this must also override the ACL fallback.given().filter(LOCAL_SIGNER).when().put("/" + CONDITIONAL_DENY_ACL_BUCKET).then().statusCode(200);+ enableLegacyAcls(CONDITIONAL_DENY_ACL_BUCKET);given().filter(LOCAL_SIGNER)@@ -2413,6 +2425,7 @@ class S3AuthEnforcementIntegrationTest {</OwnershipControls>""";given().filter(LOCAL_SIGNER).when().put("/" + bucket).then().statusCode(200);+ enableLegacyAcls(bucket);given().filter(LOCAL_SIGNER).header("x-amz-acl", "public-read").body("public data").when().put("/" + bucket + "/data.txt").then().statusCode(200);@@ -2426,7 +2439,7 @@ class S3AuthEnforcementIntegrationTest {.when().put("/" + bucket + "?ownershipControls").then().statusCode(400).body(containsString("InvalidBucketAclWithObjectOwnership"));given().filter(LOCAL_SIGNER).when().get("/" + bucket + "?ownershipControls")- .then().statusCode(404);+ .then().statusCode(200).body(containsString("<ObjectOwnership>ObjectWriter</ObjectOwnership>"));given().filter(LOCAL_SIGNER).header("x-amz-acl", "private").when().put("/" + bucket + "?acl").then().statusCode(200);diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3BlockPublicAccessEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3BlockPublicAccessEnforcementIntegrationTest.javaindex 85dccda55b..cb5d80ccdd 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3BlockPublicAccessEnforcementIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3BlockPublicAccessEnforcementIntegrationTest.java@@ -159,6 +159,9 @@ class S3BlockPublicAccessEnforcementIntegrationTest {private static String createBucket() {String bucket = "bpa-enforce-" + UUID.randomUUID();given().filter(OWNER).when().put("/" + bucket).then().statusCode(200);+ given().filter(OWNER)+ .body("<OwnershipControls><Rule><ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>")+ .when().put("/" + bucket + "?ownershipControls").then().statusCode(200);return bucket;}diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3BlockPublicAccessIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3BlockPublicAccessIntegrationTest.javaindex ad5f1da031..7872ef041c 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3BlockPublicAccessIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3BlockPublicAccessIntegrationTest.java@@ -190,6 +190,10 @@ class S3BlockPublicAccessIntegrationTest {private static String createBucket() {String bucket = "bpa-" + UUID.randomUUID();given().when().put("/" + bucket).then().statusCode(200);+ // These cases exercise ACL policy rather than the default ACL-disabled ownership mode.+ given().body("<OwnershipControls><Rule><ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>")+ .when().put("/" + bucket + "?ownershipControls")+ .then().statusCode(200);return bucket;}diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3CopyObjectSourcePermissionIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3CopyObjectSourcePermissionIntegrationTest.javaindex 1af2ec2d0a..a6ab6a2df1 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3CopyObjectSourcePermissionIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3CopyObjectSourcePermissionIntegrationTest.java@@ -372,6 +372,9 @@ class S3CopyObjectSourcePermissionIntegrationTest {createBucketAsRoot(sourceBucket);createBucketAsRoot(destBucket);+ given().filter(ROOT_SIGNER)+ .body("<OwnershipControls><Rule><ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>")+ .when().put("/" + sourceBucket + "?ownershipControls").then().statusCode(200);putPublicObjectAsRoot(sourceBucket, "public.txt", "public source");putBucketPolicyAsRoot(destBucket, allowPublicPutObjectPolicy(destBucket));diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3GlobalBucketNamespaceTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3GlobalBucketNamespaceTest.javaindex 1cd8e9627e..e96640b21b 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3GlobalBucketNamespaceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3GlobalBucketNamespaceTest.java@@ -249,6 +249,8 @@ class S3GlobalBucketNamespaceTest {caller.set(ACCOUNT_A);globalNs.createBucket("shared-metadata-bucket", "us-east-1");+ globalNs.putBucketOwnershipControls("shared-metadata-bucket", "<OwnershipControls><Rule>"+ + "<ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>");globalNs.putBucketVersioning("shared-metadata-bucket", "Enabled");S3Object created = globalNs.putObject("shared-metadata-bucket", "object.txt", "payload".getBytes(UTF_8),diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3MultipartDiskAssemblyTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3MultipartDiskAssemblyTest.javaindex e2543de226..cda70d9486 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3MultipartDiskAssemblyTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3MultipartDiskAssemblyTest.java@@ -150,6 +150,8 @@ class S3MultipartDiskAssemblyTest {@Testvoid failedStoreRemovesTheAssembledFileAndKeepsThePartsForARetry() throws Exception {byte[] firstPart = new byte[5 * 1024 * 1024];+ s3Service.putBucketOwnershipControls("test-bucket", "<OwnershipControls><Rule>"+ + "<ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>");MultipartUpload upload = s3Service.initiateMultipartUpload("test-bucket", "public.bin", null,null, null, null, null, "public-read");s3Service.uploadPart("test-bucket", "public.bin", upload.getUploadId(), 1, firstPart);diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3OwnershipControlsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3OwnershipControlsIntegrationTest.javaindex 839f089009..66d48a7275 100644--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3OwnershipControlsIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3OwnershipControlsIntegrationTest.java@@ -1,6 +1,7 @@package io.github.hectorvent.floci.services.s3;import io.quarkus.test.junit.QuarkusTest;+import jakarta.inject.Inject;import org.junit.jupiter.api.MethodOrderer;import org.junit.jupiter.api.Order;import org.junit.jupiter.api.Test;@@ -24,6 +25,9 @@ class S3OwnershipControlsIntegrationTest {private static final String SCHEMA_MESSAGE ="The XML you provided was not well-formed or did not validate against our published schema.";+ @Inject+ S3Service s3Service;+@Test@Order(1)void createBucket() {@@ -36,13 +40,136 @@ class S3OwnershipControlsIntegrationTest {@Test@Order(2)- void getOwnershipControlsBeforePutReturns404() {+ void newBucketDefaultsToEnforcedOwnershipAndRejectsAclWrites() {+ String bucket = BUCKET + "-default";+ given().when().put("/" + bucket).then().statusCode(200);+given().when()- .get("/" + BUCKET + "?ownershipControls")+ .get("/" + bucket + "?ownershipControls").then()- .statusCode(404)- .body(containsString("OwnershipControlsNotFoundError"));+ .statusCode(200)+ .body(containsString("<ObjectOwnership>BucketOwnerEnforced</ObjectOwnership>"));++ given()+ .header("x-amz-acl", "public-read")+ .when()+ .put("/" + bucket + "?acl")+ .then()+ .statusCode(400)+ .body(containsString("AccessControlListNotSupported"));+ }++ @Test+ @Order(2)+ void createBucketHonorsExplicitOwnershipAndRejectsIncompatibleAcl() {+ String legacyBucket = BUCKET + "-explicit-writer";+ given()+ .header("x-amz-object-ownership", "ObjectWriter")+ .when()+ .put("/" + legacyBucket)+ .then()+ .statusCode(200);++ given().when().get("/" + legacyBucket + "?ownershipControls")+ .then().statusCode(200).body(containsString("<ObjectOwnership>ObjectWriter</ObjectOwnership>"));+ String grantedBucket = BUCKET + "-explicit-grant";+ given().header("x-amz-object-ownership", "ObjectWriter")+ .header("x-amz-grant-read", "id=\"123456789012\"")+ .when().put("/" + grantedBucket)+ .then().statusCode(200);+ given().when().get("/" + grantedBucket + "?acl")+ .then().statusCode(200).body(containsString("123456789012"));+ given().header("x-amz-acl", "public-read")+ .when().put("/" + BUCKET + "-invalid-acl")+ .then().statusCode(400).body(containsString("InvalidBucketAclWithObjectOwnership"));+ given().header("x-amz-grant-read", "id=\"123456789012\"")+ .when().put("/" + BUCKET + "-invalid-grant")+ .then().statusCode(400).body(containsString("InvalidBucketAclWithObjectOwnership"));+ given().header("x-amz-object-ownership", "InvalidOwnership")+ .when().put("/" + BUCKET + "-invalid-mode")+ .then().statusCode(400).body(containsString("InvalidArgument"));+ }++ @Test+ @Order(2)+ void createBucketAcceptsCannedAclsAndRejectsConflictingGrants() {+ for (String cannedAcl : new String[] {+ "log-delivery-write", "aws-exec-read", "bucket-owner-read", "bucket-owner-full-control"}) {+ given().header("x-amz-object-ownership", "ObjectWriter")+ .header("x-amz-acl", cannedAcl)+ .when().put("/" + BUCKET + "-canned-" + cannedAcl)+ .then().statusCode(200);+ }+ given().header("x-amz-object-ownership", "ObjectWriter")+ .header("x-amz-acl", "private")+ .header("x-amz-grant-read", "id=\"123456789012\"")+ .when().put("/" + BUCKET + "-conflicting-acl")+ .then().statusCode(400)+ .body(containsString("<Code>InvalidRequest</Code>"))+ .body(containsString("Specifying both Canned ACLs and Header Grants is not allowed"));+ }++ @Test+ @Order(2)+ void createBucketRejectsPublicAclRegardlessOfAccountBlockSetting() {+ given().header("x-amz-object-ownership", "ObjectWriter")+ .header("x-amz-acl", "public-read")+ .when().put("/" + BUCKET + "-public-unblocked")+ .then().statusCode(400)+ .body(containsString("<Code>InvalidBucketAclWithBlockPublicAccessError</Code>"));++ s3Service.putAccountPublicAccessBlock("000000000000", """+ <PublicAccessBlockConfiguration>+ <BlockPublicAcls>true</BlockPublicAcls>+ </PublicAccessBlockConfiguration>+ """);+ try {+ given().header("x-amz-object-ownership", "ObjectWriter")+ .header("x-amz-acl", "public-read")+ .when().put("/" + BUCKET + "-public-blocked")+ .then().statusCode(400)+ .body(containsString("<Code>InvalidBucketAclWithBlockPublicAccessError</Code>"));+ } finally {+ s3Service.deleteAccountPublicAccessBlock("000000000000");+ }+ }++ @Test+ @Order(2)+ void multipartInitiationRejectsGrantsOnEnforcedBucket() {+ String bucket = BUCKET + "-multipart-grants";+ given().when().put("/" + bucket).then().statusCode(200);++ given().header("x-amz-grant-read", "id=\"123456789012\"")+ .when().post("/" + bucket + "/rejected?uploads")+ .then().statusCode(400).body(containsString("AccessControlListNotSupported"));+ given().header("x-amz-grant-full-control", "id=\"000000000000\"")+ .when().post("/" + bucket + "/accepted?uploads")+ .then().statusCode(200).body(containsString("<UploadId>"));+ }++ @Test+ @Order(2)+ void multipartGrantSurvivesCompletionOnObjectWriterBucket() {+ String bucket = BUCKET + "-multipart-writer";+ String key = "granted-object";+ given().header("x-amz-object-ownership", "ObjectWriter")+ .when().put("/" + bucket).then().statusCode(200);+ String uploadId = given().header("x-amz-grant-read", "id=\"123456789012\"")+ .when().post("/" + bucket + "/" + key + "?uploads")+ .then().statusCode(200)+ .extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");+ String partETag = given().body("part-one")+ .when().put("/" + bucket + "/" + key + "?uploadId=" + uploadId + "&partNumber=1")+ .then().statusCode(200).extract().header("ETag");+ String completeXml = "<CompleteMultipartUpload><Part><PartNumber>1</PartNumber><ETag>"+ + partETag + "</ETag></Part></CompleteMultipartUpload>";+ given().contentType("application/xml").body(completeXml)+ .when().post("/" + bucket + "/" + key + "?uploadId=" + uploadId)+ .then().statusCode(200);+ given().when().get("/" + bucket + "/" + key + "?acl")+ .then().statusCode(200).body(containsString("123456789012"));}@Test@@ -227,11 +354,14 @@ class S3OwnershipControlsIntegrationTest {String enforced = OWNERSHIP_CONTROLS_XML.replace("BucketOwnerPreferred", "BucketOwnerEnforced");given().when().put("/" + bucket).then().statusCode(200);+ given().body(OWNERSHIP_CONTROLS_XML.replace("BucketOwnerPreferred", "ObjectWriter"))+ .when().put("/" + bucket + "?ownershipControls").then().statusCode(200);given().body(acl).when().put("/" + bucket + "?acl").then().statusCode(200);given().body(enforced).when().put("/" + bucket + "?ownershipControls").then().statusCode(400).body(containsString("InvalidBucketAclWithObjectOwnership"));given().when().get("/" + bucket + "?ownershipControls")- .then().statusCode(404);+ .then().statusCode(200)+ .body(containsString("<ObjectOwnership>ObjectWriter</ObjectOwnership>"));given().header("x-amz-acl", "private").when().put("/" + bucket + "?acl").then().statusCode(200);