diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3AuthEnforcementCompatibilityTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3AuthEnforcementCompatibilityTest.java
index 01ec8ea70a..143ec32a16 100644
--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3AuthEnforcementCompatibilityTest.java
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3AuthEnforcementCompatibilityTest.java
@@ -13,6 +13,7 @@ import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
+import software.amazon.awssdk.services.s3.model.DeletePublicAccessBlockRequest;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
@@ -46,6 +47,7 @@ class S3AuthEnforcementCompatibilityTest {
unknownCredentialS3 = s3WithCredentials("bad-key", "bad-secret");
adminS3.createBucket(CreateBucketRequest.builder().bucket(PUBLIC_BUCKET).build());
+ adminS3.deletePublicAccessBlock(DeletePublicAccessBlockRequest.builder().bucket(PUBLIC_BUCKET).build());
adminS3.putBucketPolicy(PutBucketPolicyRequest.builder()
.bucket(PUBLIC_BUCKET)
.policy(publicReadPolicy(PUBLIC_BUCKET))
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3PolicyStatusTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3PolicyStatusTest.java
index 243499a4bd..ceaeac0bfb 100644
--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3PolicyStatusTest.java
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3PolicyStatusTest.java
@@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
import software.amazon.awssdk.services.s3.model.DeleteBucketRequest;
+import software.amazon.awssdk.services.s3.model.DeletePublicAccessBlockRequest;
import software.amazon.awssdk.services.s3.model.GetBucketPolicyStatusRequest;
import software.amazon.awssdk.services.s3.model.GetBucketPolicyStatusResponse;
import software.amazon.awssdk.services.s3.model.PutBucketPolicyRequest;
@@ -25,6 +26,7 @@ class S3PolicyStatusTest {
try (S3Client s3 = TestFixtures.s3Client()) {
s3.createBucket(CreateBucketRequest.builder().bucket(bucket).build());
+ s3.deletePublicAccessBlock(DeletePublicAccessBlockRequest.builder().bucket(bucket).build());
s3.putBucketPolicy(PutBucketPolicyRequest.builder().bucket(bucket).policy(policy).build());
GetBucketPolicyStatusResponse response = s3.getBucketPolicyStatus(
diff --git a/docs/services/s3.md b/docs/services/s3.md
index 0c83279e01..11e2861c1c 100644
--- a/docs/services/s3.md
+++ b/docs/services/s3.md
@@ -475,7 +475,9 @@ With `BucketOwnerEnforced` object ownership, ACL writes are rejected and existin
The split follows AWS. The first two reject the write that would introduce public access, and AWS applies them whoever the caller is, so they need no flag: `put-public-access-block` followed by a public `put-bucket-policy` returns 403 in Floci's default configuration. The second two suppress access that an existing policy or ACL would grant, which only has meaning once anonymous authorization runs at all, so they take effect when `FLOCI_SERVICES_S3_ENFORCE_AUTH` is on. With that flag off, Floci cannot tell an anonymous caller from a signed one and every request is authorized regardless.
-When upgrading, a workflow that already sets `BlockPublicPolicy` or `BlockPublicAcls` may now receive 403 on a later public policy or ACL write, even with `enforce-auth` off. This matches AWS behavior.
+A bucket nobody configured enforces the default `GetPublicAccessBlock` reports for it: all four settings on. `DeletePublicAccessBlock` or `PutPublicAccessBlock` replaces that default.
+
+When upgrading, a workflow that already sets `BlockPublicPolicy` or `BlockPublicAcls` may now receive 403 on a later public policy or ACL write, even with `enforce-auth` off. A bucket saved by an earlier version, including one with no configuration, now refuses public policies and ACLs until its configuration is deleted or set. This matches AWS behavior.
As in AWS, enabling a setting never rewrites stored state. An existing public policy or ACL stays exactly as written, and clearing the setting makes the bucket public again.
@@ -493,7 +495,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` 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.
+- `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` also refuses a public `PutBucketAcl` with `AccessDenied` (403), because the default configuration is enforced.
- `GetBucketAcl` returns the stored ACL rather than the effective one, so it does not reflect an `IgnorePublicAcls` that is suppressing a grant.
- `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/S3Service.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java
index b7f0fbf0a0..f35c6eb502 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
@@ -6295,8 +6295,8 @@ public class S3Service implements Resettable, ResourceProvider {
/**
* What AWS reports for a bucket nobody configured: since April 2023 every new bucket starts with
- * all four Block Public Access settings on. This is only what GetPublicAccessBlock answers. The
- * bucket stores no configuration, so enforcement on the write paths is unchanged.
+ * all four Block Public Access settings on. The bucket stores no configuration; the default is
+ * applied when the configuration is read and when the write paths enforce it.
*/
static final String DEFAULT_PUBLIC_ACCESS_BLOCK_XML = new XmlBuilder()
.start("PublicAccessBlockConfiguration", AwsNamespaces.S3)
@@ -6348,8 +6348,15 @@ public class S3Service implements Resettable, ResourceProvider {
}
private S3BlockPublicAccessSettings blockPublicAccessFor(Bucket bucket, String bucketOwnerAccount) {
- return S3BlockPublicAccessSettings.parse(bucket.getPublicAccessBlockConfiguration())
- .mostRestrictive(accountBlockPublicAccess(bucketOwnerAccount));
+ return bucketBlockPublicAccess(bucket).mostRestrictive(accountBlockPublicAccess(bucketOwnerAccount));
+ }
+
+ /** A bucket nobody configured enforces the default it reports; an explicit or deleted configuration does not. */
+ private static S3BlockPublicAccessSettings bucketBlockPublicAccess(Bucket bucket) {
+ if (bucket.getPublicAccessBlockConfiguration() == null && !bucket.isPublicAccessBlockDeleted()) {
+ return S3BlockPublicAccessSettings.parse(DEFAULT_PUBLIC_ACCESS_BLOCK_XML);
+ }
+ return S3BlockPublicAccessSettings.parse(bucket.getPublicAccessBlockConfiguration());
}
private S3BlockPublicAccessSettings accountBlockPublicAccess(String accountId) {
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.java
index 4614141c55..c5f511af1e 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
@@ -153,6 +153,7 @@ class CloudFrontS3AuthServingTest {
s3Service.putObject(bucket, "index.html", body.getBytes(StandardCharsets.UTF_8),
"text/html", Map.of());
if (publicRead) {
+ s3Service.deletePublicAccessBlock(bucket);
s3Service.putBucketPolicy(bucket, publicReadPolicy(bucket));
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/ResourcePolicyPrincipalTypeEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/ResourcePolicyPrincipalTypeEnforcementIntegrationTest.java
index 8fbde35bfb..3b4fe93a71 100644
--- a/src/test/java/io/github/hectorvent/floci/services/iam/ResourcePolicyPrincipalTypeEnforcementIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/iam/ResourcePolicyPrincipalTypeEnforcementIntegrationTest.java
@@ -67,6 +67,7 @@ class ResourcePolicyPrincipalTypeEnforcementIntegrationTest {
}
private static void putBucketPolicy(String bucket, String policy) {
+ given().filter(OWNER).when().delete("/" + bucket + "?publicAccessBlock").then().statusCode(204);
given().filter(OWNER).contentType("application/json").body(policy)
.when().put("/" + bucket + "?policy").then().statusCode(200);
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/StsIssuedSessionEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/StsIssuedSessionEnforcementIntegrationTest.java
index 24cc6d818f..cf1ee4fda1 100644
--- a/src/test/java/io/github/hectorvent/floci/services/iam/StsIssuedSessionEnforcementIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/iam/StsIssuedSessionEnforcementIntegrationTest.java
@@ -181,6 +181,7 @@ class StsIssuedSessionEnforcementIntegrationTest {
iam("DeleteUserPolicy", "UserName", userName, "PolicyName", "inline");
iam("DeleteUser", "UserName", userName);
iam("CreateUser", "UserName", userName);
+ given().filter(admin).when().delete("/" + bucket + "?publicAccessBlock").then().statusCode(204);
given().filter(admin).contentType("application/json").body("""
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":"*",
"Action":"s3:GetObject","Resource":"arn:aws:s3:::%s/*"}]}""".formatted(bucket))
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 8db3a78353..2e9c5ca622 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
@@ -35,6 +35,12 @@ class S3AclIntegrationTest {
.put("/" + BUCKET + "?ownershipControls")
.then()
.statusCode(200);
+
+ given()
+ .when()
+ .delete("/" + BUCKET + "?publicAccessBlock")
+ .then()
+ .statusCode(204);
}
@Test
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3AuthEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3AuthEnforcementIntegrationTest.java
index 7c056e12c1..b9301e7a79 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
@@ -85,6 +85,15 @@ class S3AuthEnforcementIntegrationTest {
.then().statusCode(400).body(containsString("AuthorizationHeaderMalformed"));
}
+ private static void createBucketWithoutPublicAccessBlock(String bucket) {
+ given().filter(LOCAL_SIGNER).when().put("/" + bucket).then().statusCode(200);
+ deletePublicAccessBlock(bucket);
+ }
+
+ private static void deletePublicAccessBlock(String bucket) {
+ given().filter(LOCAL_SIGNER).when().delete("/" + bucket + "?publicAccessBlock").then().statusCode(204);
+ }
+
private static void enableLegacyAcls(String bucket) {
given().filter(LOCAL_SIGNER)
.body("ObjectWriter")
@@ -114,6 +123,13 @@ class S3AuthEnforcementIntegrationTest {
.then()
.statusCode(200);
+ given()
+ .filter(LOCAL_SIGNER)
+ .when()
+ .delete("/" + PUBLIC_BUCKET + "?publicAccessBlock")
+ .then()
+ .statusCode(204);
+
given()
.filter(LOCAL_SIGNER)
.contentType("application/json")
@@ -270,7 +286,7 @@ class S3AuthEnforcementIntegrationTest {
@Test
@Order(12)
void websiteRootAuthorizesIndexObjectReadNotBucketList() {
- given().filter(LOCAL_SIGNER).when().put("/" + WEBSITE_BUCKET).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(WEBSITE_BUCKET);
given()
.filter(LOCAL_SIGNER)
@@ -319,7 +335,7 @@ class S3AuthEnforcementIntegrationTest {
@Test
@Order(13)
void websiteRootUsesErrorDocumentForDeniedIndexObject() {
- given().filter(LOCAL_SIGNER).when().put("/" + WEBSITE_ERROR_BUCKET).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(WEBSITE_ERROR_BUCKET);
given()
.filter(LOCAL_SIGNER)
@@ -371,7 +387,7 @@ class S3AuthEnforcementIntegrationTest {
@Test
@Order(14)
void bucketAclPublicReadAllowsUnsignedList() {
- given().filter(LOCAL_SIGNER).when().put("/" + BUCKET_ACL_BUCKET).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(BUCKET_ACL_BUCKET);
enableLegacyAcls(BUCKET_ACL_BUCKET);
given()
@@ -402,7 +418,7 @@ class S3AuthEnforcementIntegrationTest {
@Test
@Order(15)
void explicitBucketPolicyDenyOverridesPublicObjectAcl() {
- given().filter(LOCAL_SIGNER).when().put("/" + DENY_BUCKET).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(DENY_BUCKET);
enableLegacyAcls(DENY_BUCKET);
given()
@@ -517,7 +533,7 @@ class S3AuthEnforcementIntegrationTest {
@Test
@Order(20)
void missingObjectRequiresListBucketToReturnNoSuchKey() {
- given().filter(LOCAL_SIGNER).when().put("/" + GET_ONLY_BUCKET).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(GET_ONLY_BUCKET);
given()
.filter(LOCAL_SIGNER)
@@ -546,7 +562,7 @@ class S3AuthEnforcementIntegrationTest {
@Test
@Order(21)
void versionedObjectReadRequiresGetObjectVersion() {
- given().filter(LOCAL_SIGNER).when().put("/" + VERSION_BUCKET).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(VERSION_BUCKET);
given()
.filter(LOCAL_SIGNER)
@@ -859,7 +875,7 @@ class S3AuthEnforcementIntegrationTest {
@Test
@Order(32)
void bucketPolicyCanExplicitlyAllowAnonymousWrite() {
- given().filter(LOCAL_SIGNER).when().put("/" + PUBLIC_WRITE_BUCKET).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(PUBLIC_WRITE_BUCKET);
given()
.filter(LOCAL_SIGNER)
@@ -1154,7 +1170,7 @@ class S3AuthEnforcementIntegrationTest {
// Per AWS's ACL docs, a bucket-ACL WRITE grant to a non-owner (like AllUsers) "denies
// 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);
+ createBucketWithoutPublicAccessBlock(PUBLIC_WRITE_ACL_BUCKET);
enableLegacyAcls(PUBLIC_WRITE_ACL_BUCKET);
given()
@@ -1199,7 +1215,7 @@ class S3AuthEnforcementIntegrationTest {
@Test
@Order(39)
void explicitPolicyDenyOverridesPublicWriteAcl() {
- given().filter(LOCAL_SIGNER).when().put("/" + DENY_WRITE_ACL_BUCKET).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(DENY_WRITE_ACL_BUCKET);
enableLegacyAcls(DENY_WRITE_ACL_BUCKET);
given()
@@ -1275,7 +1291,7 @@ class S3AuthEnforcementIntegrationTest {
@Test
@Order(41)
void deleteObjectPolicyGrantDoesNotAuthorizeVersionedDelete() {
- given().filter(LOCAL_SIGNER).when().put("/" + DELETE_VERSION_BUCKET).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(DELETE_VERSION_BUCKET);
given()
.filter(LOCAL_SIGNER)
@@ -1325,6 +1341,7 @@ class S3AuthEnforcementIntegrationTest {
// that's protected by governance mode", so the header alone asks for nothing more.
given().filter(LOCAL_SIGNER).header("x-amz-bucket-object-lock-enabled", "true")
.when().put("/" + BYPASS_BUCKET).then().statusCode(200);
+ deletePublicAccessBlock(BYPASS_BUCKET);
String free = given().filter(LOCAL_SIGNER).body("unlocked")
.when().put("/" + BYPASS_BUCKET + "/free.txt")
.then().statusCode(200).extract().header("x-amz-version-id");
@@ -1398,7 +1415,7 @@ class S3AuthEnforcementIntegrationTest {
// Floci has no request context to evaluate a Condition against, so a conditional Deny
// 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);
+ createBucketWithoutPublicAccessBlock(CONDITIONAL_DENY_ACL_BUCKET);
enableLegacyAcls(CONDITIONAL_DENY_ACL_BUCKET);
given()
@@ -1430,7 +1447,7 @@ class S3AuthEnforcementIntegrationTest {
@Test
@Order(44)
void batchDeleteObjectsPolicyGrantDoesNotAuthorizeVersionedDelete() {
- given().filter(LOCAL_SIGNER).when().put("/" + BATCH_DELETE_VERSION_BUCKET).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(BATCH_DELETE_VERSION_BUCKET);
given()
.filter(LOCAL_SIGNER)
@@ -1497,6 +1514,7 @@ class S3AuthEnforcementIntegrationTest {
.put("/" + bucket)
.then()
.statusCode(200);
+ deletePublicAccessBlock(bucket);
String unlockedVersion = given()
.filter(LOCAL_SIGNER)
@@ -1677,6 +1695,7 @@ class S3AuthEnforcementIntegrationTest {
.put("/" + BUCKET_CONFIG_BUCKET)
.then()
.statusCode(200);
+ deletePublicAccessBlock(BUCKET_CONFIG_BUCKET);
given()
.when()
@@ -2335,7 +2354,7 @@ class S3AuthEnforcementIntegrationTest {
@Order(56)
void conditionalDeleteByETagAlsoNeedsGetObject() {
String bucket = "auth-conditional-delete-bucket";
- given().filter(LOCAL_SIGNER).when().put("/" + bucket).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(bucket);
String eTag = given().filter(LOCAL_SIGNER).body("etag-guarded")
.when().put("/" + bucket + "/etag.txt")
.then().statusCode(200).extract().header("ETag");
@@ -2455,7 +2474,7 @@ class S3AuthEnforcementIntegrationTest {
BucketOwnerEnforced
""";
- given().filter(LOCAL_SIGNER).when().put("/" + bucket).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(bucket);
enableLegacyAcls(bucket);
given().filter(LOCAL_SIGNER).header("x-amz-acl", "public-read").body("public data")
.when().put("/" + bucket + "/data.txt")
@@ -2499,7 +2518,7 @@ class S3AuthEnforcementIntegrationTest {
@Order(59)
void anAnonymousReadNamingTheNullVersionIsCheckedAgainstThatVersionsAcl() {
String bucket = "auth-null-version-acl-bucket";
- given().filter(LOCAL_SIGNER).when().put("/" + bucket).then().statusCode(200);
+ createBucketWithoutPublicAccessBlock(bucket);
enableLegacyAcls(bucket);
given().filter(LOCAL_SIGNER).body("old").when().put("/" + bucket + "/old").then().statusCode(200);
given().filter(LOCAL_SIGNER)
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.java
index cb5d80ccdd..5322d97f72 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
@@ -117,6 +117,7 @@ class S3BlockPublicAccessEnforcementIntegrationTest {
@Test
void ignorePublicAclsWithholdsAnonymousListBucketOnAPublicBucketAcl() {
String bucket = createBucket();
+ deleteBucketPublicAccessBlock(bucket);
putObject(bucket, "object.txt");
given().filter(OWNER).header("x-amz-acl", "public-read")
.when().put("/" + bucket + "?acl")
@@ -142,6 +143,7 @@ class S3BlockPublicAccessEnforcementIntegrationTest {
private static String bucketWithPublicPolicy() {
String bucket = createBucket();
+ deleteBucketPublicAccessBlock(bucket);
putObject(bucket, "object.txt");
putBucketPolicy(bucket, PUBLIC_READ_POLICY.formatted(bucket));
return bucket;
@@ -149,6 +151,7 @@ class S3BlockPublicAccessEnforcementIntegrationTest {
private static String bucketWithPublicObjectAcl() {
String bucket = createBucket();
+ deleteBucketPublicAccessBlock(bucket);
putObject(bucket, "object.txt");
given().filter(OWNER).header("x-amz-acl", "public-read")
.when().put("/" + bucket + "/object.txt?acl")
@@ -177,6 +180,10 @@ class S3BlockPublicAccessEnforcementIntegrationTest {
.then().statusCode(200);
}
+ private static void deleteBucketPublicAccessBlock(String bucket) {
+ given().filter(OWNER).when().delete("/" + bucket + "?publicAccessBlock").then().statusCode(204);
+ }
+
private static void putBucketPublicAccessBlock(String bucket, boolean blockPublicAcls,
boolean ignorePublicAcls, boolean blockPublicPolicy,
boolean restrictPublicBuckets) {
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.java
index 7872ef041c..898c2bfc4a 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
@@ -86,9 +86,20 @@ class S3BlockPublicAccessIntegrationTest {
}
@Test
- void aPublicBucketPolicyIsAcceptedWithoutBlockPublicPolicy() {
+ void aPublicBucketPolicyIsRefusedWithoutBlockPublicPolicyConfigured() {
String bucket = createBucket();
+ given().body(PUBLIC_POLICY.formatted(bucket))
+ .when().put("/" + bucket + "?policy")
+ .then().statusCode(403)
+ .body(containsString("AccessDenied"));
+ }
+
+ @Test
+ void aPublicBucketPolicyIsAcceptedOnceBlockPublicPolicyIsDeleted() {
+ String bucket = createBucket();
+ deleteBucketPublicAccessBlock(bucket);
+
given().body(PUBLIC_POLICY.formatted(bucket))
.when().put("/" + bucket + "?policy")
.then().statusCode(200);
@@ -97,6 +108,7 @@ class S3BlockPublicAccessIntegrationTest {
@Test
void blockPublicPolicyDoesNotRemoveAPolicyStoredBeforeItWasSet() {
String bucket = createBucket();
+ deleteBucketPublicAccessBlock(bucket);
given().body(PUBLIC_POLICY.formatted(bucket))
.when().put("/" + bucket + "?policy")
.then().statusCode(200);
@@ -197,6 +209,10 @@ class S3BlockPublicAccessIntegrationTest {
return bucket;
}
+ private static void deleteBucketPublicAccessBlock(String bucket) {
+ given().when().delete("/" + bucket + "?publicAccessBlock").then().statusCode(204);
+ }
+
private static void putBucketPublicAccessBlock(String bucket, boolean blockPublicAcls,
boolean ignorePublicAcls, boolean blockPublicPolicy,
boolean restrictPublicBuckets) {
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.java
index 76d4da036c..07b6370307 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
@@ -569,6 +569,7 @@ class S3CopyObjectSourcePermissionIntegrationTest {
}
private static void putPublicObjectAsRoot(String bucket, String key, String body) {
+ deletePublicAccessBlockAsRoot(bucket, ROOT_SIGNER);
given()
.filter(ROOT_SIGNER)
.header("x-amz-acl", "public-read")
@@ -610,6 +611,7 @@ class S3CopyObjectSourcePermissionIntegrationTest {
private static void putBucketPolicyAsRoot(
String bucket, String policy, S3RequestSigner signer) {
+ deletePublicAccessBlockAsRoot(bucket, signer);
given()
.filter(signer)
.contentType("application/json")
@@ -620,6 +622,10 @@ class S3CopyObjectSourcePermissionIntegrationTest {
.statusCode(200);
}
+ private static void deletePublicAccessBlockAsRoot(String bucket, S3RequestSigner signer) {
+ given().filter(signer).when().delete("/" + bucket + "?publicAccessBlock").then().statusCode(204);
+ }
+
private static String denyGetObjectPolicy(String bucket) {
return """
{"Version":"2012-10-17","Statement":[
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3DefaultPublicAccessBlockTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3DefaultPublicAccessBlockTest.java
index 5398de57c8..b5206f789c 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3DefaultPublicAccessBlockTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3DefaultPublicAccessBlockTest.java
@@ -61,12 +61,88 @@ class S3DefaultPublicAccessBlockTest {
}
@Test
- void theDefaultIsReportedNotStoredSoEnforcementIsUnchanged() {
+ void theDefaultIsReportedNotStored() {
Bucket bucket = s3Service.createBucket("report-only", "us-east-1");
assertEquals(null, bucket.getPublicAccessBlockConfiguration());
}
+ @Test
+ void aPublicPolicyIsRefusedOnABucketNobodyConfigured() {
+ s3Service.createBucket("fresh-policy", "us-east-1");
+
+ AwsException e = assertThrows(AwsException.class,
+ () -> s3Service.putBucketPolicy("fresh-policy", publicPolicy("fresh-policy")));
+
+ assertEquals("AccessDenied", e.getErrorCode());
+ assertThrows(AwsException.class, () -> s3Service.getBucketPolicy("fresh-policy"));
+ }
+
+ @Test
+ void aPolicyLimitedToTheAccountIsAcceptedOnAFreshBucket() {
+ s3Service.createBucket("private-policy", "us-east-1");
+
+ s3Service.putBucketPolicy("private-policy", policyFor("{\"AWS\":\"arn:aws:iam::000000000000:root\"}",
+ "private-policy"));
+
+ assertEquals(true, s3Service.getBucketPolicy("private-policy").contains("root"));
+ }
+
+ @Test
+ void aPublicPolicyIsAcceptedOnceTheConfigurationIsExplicitlyOff() {
+ s3Service.createBucket("explicit-off", "us-east-1");
+ s3Service.putPublicAccessBlock("explicit-off", ""
+ + "falsefalse"
+ + "falsefalse"
+ + "");
+
+ s3Service.putBucketPolicy("explicit-off", publicPolicy("explicit-off"));
+
+ assertEquals(true, s3Service.getBucketPolicy("explicit-off").contains("GetObject"));
+ }
+
+ @Test
+ void aPublicPolicyIsAcceptedOnceTheConfigurationIsDeleted() {
+ s3Service.createBucket("deleted-policy", "us-east-1");
+ s3Service.deletePublicAccessBlock("deleted-policy");
+
+ s3Service.putBucketPolicy("deleted-policy", publicPolicy("deleted-policy"));
+
+ assertEquals(true, s3Service.getBucketPolicy("deleted-policy").contains("GetObject"));
+ }
+
+ @Test
+ void aPublicBucketAclIsRefusedOnAnObjectWriterBucketNobodyConfigured() {
+ s3Service.createBucket("object-writer", "us-east-1");
+ s3Service.putBucketOwnershipControls("object-writer",
+ "ObjectWriter");
+
+ AwsException e = assertThrows(AwsException.class, () -> s3Service.putBucketAcl("object-writer", null,
+ "public-read", null, null, null, null, null));
+
+ assertEquals("AccessDenied", e.getErrorCode());
+ assertEquals(403, e.getHttpStatus());
+ }
+
+ @Test
+ void aPublicBucketAclIsAcceptedOnceTheConfigurationIsDeleted() {
+ s3Service.createBucket("object-writer-open", "us-east-1");
+ s3Service.putBucketOwnershipControls("object-writer-open",
+ "ObjectWriter");
+ s3Service.deletePublicAccessBlock("object-writer-open");
+
+ s3Service.putBucketAcl("object-writer-open", null, "public-read", null, null, null, null, null);
+ }
+
+ private static String publicPolicy(String bucket) {
+ return policyFor("\"*\"", bucket);
+ }
+
+ private static String policyFor(String principal, String bucket) {
+ return "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":" + principal
+ + ",\"Action\":\"s3:GetObject\",\"Resource\":\"arn:aws:s3:::" + bucket + "/*\"}]}";
+ }
+
@Test
void repeatingCreateBucketKeepsAChangedConfiguration() {
s3Service.createBucket("again", "us-east-1");
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.java
index 0519979516..84e8548aa9 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
@@ -443,6 +443,7 @@ class S3GlobalBucketNamespaceTest {
caller.set(ACCOUNT_A);
globalNs.createBucket("shared-metadata-bucket", "us-east-1");
+ globalNs.deletePublicAccessBlock("shared-metadata-bucket");
globalNs.putBucketOwnershipControls("shared-metadata-bucket", ""
+ "ObjectWriter");
globalNs.putBucketVersioning("shared-metadata-bucket", "Enabled");
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3NullVersionLockPromotionTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3NullVersionLockPromotionTest.java
index c8bfb13210..5256847b46 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3NullVersionLockPromotionTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3NullVersionLockPromotionTest.java
@@ -46,8 +46,11 @@ class S3NullVersionLockPromotionTest {
case "legal-hold" -> service.putObjectLegalHold("bucket", "key", "null", "ON");
case "retention" -> service.putObjectRetention("bucket", "key", "null", "COMPLIANCE",
Instant.now().plusSeconds(3600), false);
- case "acl" -> service.putObjectAcl("bucket", "key", "null", "", "public-read",
- null, null, null, null, null);
+ case "acl" -> {
+ service.deletePublicAccessBlock("bucket");
+ service.putObjectAcl("bucket", "key", "null", "", "public-read",
+ null, null, null, null, null);
+ }
default -> throw new IllegalArgumentException(operation);
}
objects.promotion.get(5, TimeUnit.SECONDS);
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3ObjectOperationsBucketPolicyIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3ObjectOperationsBucketPolicyIntegrationTest.java
index 8c9fb9502e..b14e46650d 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3ObjectOperationsBucketPolicyIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3ObjectOperationsBucketPolicyIntegrationTest.java
@@ -156,6 +156,7 @@ class S3ObjectOperationsBucketPolicyIntegrationTest {
String bucket = bucket(false);
owner().body("ObjectWriter")
.when().put(bucket + "?ownershipControls").then().statusCode(200);
+ owner().when().delete(bucket + "?publicAccessBlock").then().statusCode(204);
owner().header("x-amz-acl", "public-read-write").when().put(bucket + "?acl").then().statusCode(200);
given().header("x-amz-acl", "bucket-owner-full-control").body("acl").when().put(bucket + "/acl")
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3OwnerIdentityIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3OwnerIdentityIntegrationTest.java
index 1aaae0440e..30643c8e10 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3OwnerIdentityIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3OwnerIdentityIntegrationTest.java
@@ -157,6 +157,10 @@ class S3OwnerIdentityIntegrationTest {
.when().put("/" + bucket + "?ownershipControls")
.then().statusCode(200);
+ given().header("Authorization", authorization(ACCOUNT_TWO))
+ .when().delete("/" + bucket + "?publicAccessBlock")
+ .then().statusCode(204);
+
given().header("Authorization", authorization(ACCOUNT_TWO))
.header("x-amz-acl", "public-read")
.when().put("/" + bucket + "/public.txt")
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3PolicyStatusIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3PolicyStatusIntegrationTest.java
index 368d5ffef2..cc437b75d9 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3PolicyStatusIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3PolicyStatusIntegrationTest.java
@@ -84,6 +84,7 @@ class S3PolicyStatusIntegrationTest {
String bucket = "policy-status-" + UUID.randomUUID();
cleanup.register(() -> EnforcementFixtures.removeBucket(baseUri.getPort(), auth("test", "s3"), bucket));
admin.createBucket(request -> request.bucket(bucket));
+ admin.deletePublicAccessBlock(request -> request.bucket(bucket));
return bucket;
}