diff --git a/docs/services/s3.md b/docs/services/s3.md index 4d25f0e6a3..1f508587c0 100644 --- a/docs/services/s3.md +++ b/docs/services/s3.md @@ -355,3 +355,4 @@ Current limitations: - explicit ACL grant headers such as `x-amz-grant-read` and `x-amz-grant-full-control` are not modeled yet - cross-account canned ACL variants collapse to the emulator's single synthetic owner where Floci does not model a distinct second principal - `aws-exec-read` is accepted for compatibility, but Floci does not yet model a distinct EC2 bundle-reader grantee in `GetObjectAcl` +- `log-delivery-write` is accepted on `PutBucketAcl`/`PutObjectAcl` and grants the well-known S3 log-delivery group (`http://acs.amazonaws.com/groups/s3/LogDelivery`) `WRITE` and `READ_ACP`, matching AWS 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.java index 6bc80198b8..e2a01a0471 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 @@ -56,6 +56,7 @@ public class S3Service implements Resettable, ResourceProvider { private String ownerId() { return regionResolver != null ? regionResolver.getAccountId() : "000000000000"; } private static final String DEFAULT_OWNER_DISPLAY_NAME = "floci"; private static final String AUTHENTICATED_USERS_GROUP_URI = "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"; + private static final String LOG_DELIVERY_GROUP_URI = "http://acs.amazonaws.com/groups/s3/LogDelivery"; private static final String LEGACY_ACCESS_KEY_ID = "test"; private static final Set SUPPORTED_SERVER_SIDE_ENCRYPTION_VALUES = Set.of("AES256", "aws:kms", "aws:kms:dsse", "aws:fsx"); private static final String SSE_C_ALGORITHM = "AES256"; @@ -2797,6 +2798,13 @@ public class S3Service implements Resettable, ResourceProvider { case "authenticated-read" -> objectAclXml( ownerFullControlGrant(), groupGrant(AUTHENTICATED_USERS_GROUP_URI, "READ")); + // Standard canned ACL used by S3 server-access-logging (and Terraform's + // aws_s3_bucket_acl / access-logging modules) to grant the S3 log-delivery service + // group permission to write log objects into this bucket and read their own ACL. + case "log-delivery-write" -> objectAclXml( + ownerFullControlGrant(), + groupGrant(LOG_DELIVERY_GROUP_URI, "WRITE"), + groupGrant(LOG_DELIVERY_GROUP_URI, "READ_ACP")); default -> throw new AwsException("InvalidArgument", "Unsupported x-amz-acl value: " + cannedAcl, 400); }; 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.java index df877443fd..e52b6fba5c 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 @@ -17,6 +17,7 @@ class S3AclIntegrationTest { private static final String BUCKET = "acl-test-bucket"; private static final String ALL_USERS_GROUP_URI = "http://acs.amazonaws.com/groups/global/AllUsers"; private static final String AUTHENTICATED_USERS_GROUP_URI = "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"; + private static final String LOG_DELIVERY_GROUP_URI = "http://acs.amazonaws.com/groups/s3/LogDelivery"; private static String multipartUploadId; @Test @@ -374,4 +375,30 @@ class S3AclIntegrationTest { .body(not(containsString(ALL_USERS_GROUP_URI))) .body(containsString("FULL_CONTROL")); } + + // Regression coverage for floci-3wz: PutBucketAcl rejected the "log-delivery-write" canned + // ACL, the standard value Terraform's aws_s3_bucket_acl / access-logging modules send to grant + // the S3 log-delivery service group permission to write access logs into a bucket. + + @Test + @Order(17) + void putBucketAclAppliesLogDeliveryWriteCannedAcl() { + given() + .header("x-amz-acl", "log-delivery-write") + .when() + .put("/" + BUCKET + "?acl") + .then() + .statusCode(200); + + given() + .when() + .get("/" + BUCKET + "?acl") + .then() + .statusCode(200) + .body(containsString(LOG_DELIVERY_GROUP_URI)) + .body(containsString("WRITE")) + .body(containsString("READ_ACP")) + .body(containsString("FULL_CONTROL")) + .body(not(containsString(ALL_USERS_GROUP_URI))); + } }