fix(s3): enforce the default Block Public Access on buckets nobody configured (#7036)

This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-10-31 05:20:19 -04:00
1 parent ebdac90574
commit 76b7eed371
18 files changed
+181 -25

No files matched your search

@@ -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))
@@ -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(
+4 -2
View File
@@ -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.
@@ -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) {
@@ -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));
}
@@ -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);
}
@@ -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))
@@ -35,6 +35,12 @@ class S3AclIntegrationTest {
.put("/" + BUCKET + "?ownershipControls")
.then()
.statusCode(200);
given()
.when()
.delete("/" + BUCKET + "?publicAccessBlock")
.then()
.statusCode(204);
}
@Test
@@ -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("<OwnershipControls><Rule><ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>")
@@ -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 {
<Rule><ObjectOwnership>BucketOwnerEnforced</ObjectOwnership></Rule>
</OwnershipControls>
""";
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)
@@ -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) {
@@ -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) {
@@ -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":[
@@ -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", "<PublicAccessBlockConfiguration>"
+ "<BlockPublicAcls>false</BlockPublicAcls><IgnorePublicAcls>false</IgnorePublicAcls>"
+ "<BlockPublicPolicy>false</BlockPublicPolicy><RestrictPublicBuckets>false</RestrictPublicBuckets>"
+ "</PublicAccessBlockConfiguration>");
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",
"<OwnershipControls><Rule><ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>");
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",
"<OwnershipControls><Rule><ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>");
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");
@@ -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", "<OwnershipControls><Rule>"
+ "<ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>");
globalNs.putBucketVersioning("shared-metadata-bucket", "Enabled");
@@ -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);
@@ -156,6 +156,7 @@ class S3ObjectOperationsBucketPolicyIntegrationTest {
String bucket = bucket(false);
owner().body("<OwnershipControls><Rule><ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>")
.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")
@@ -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")
@@ -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;
}