fix(s3): report the default Block Public Access settings for a new bucket (#5434)

GetPublicAccessBlock answered NoSuchPublicAccessBlockConfiguration for a
bucket nobody had configured. AWS has applied all four settings to every
new bucket since April 2023, so a fresh bucket reads back with
BlockPublicAcls, IgnorePublicAcls, BlockPublicPolicy and
RestrictPublicBuckets all true. The 404 only follows a
DeletePublicAccessBlock.

Bucket now remembers whether its configuration was deleted, and Get
returns the default when none is stored and none was deleted. The default
is reported, not stored, so enforcement on ACLs and policies is unchanged.
This commit is contained in:
Nazimuddin Tajuddin Basha authored and GitHub committed 2026-10-13 15:14:44 -04:00
1 parent daef71ca76
commit e52ce672fe
4 files changed
+109 -3

No files matched your search

@@ -4893,20 +4893,38 @@ public class S3Service implements Resettable, ResourceProvider {
bucketStore.put(bucketName, bucket);
}
/**
* 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.
*/
static final String DEFAULT_PUBLIC_ACCESS_BLOCK_XML = new XmlBuilder()
.start("PublicAccessBlockConfiguration", AwsNamespaces.S3)
.elem("BlockPublicAcls", true)
.elem("IgnorePublicAcls", true)
.elem("BlockPublicPolicy", true)
.elem("RestrictPublicBuckets", true)
.end("PublicAccessBlockConfiguration")
.build();
public String getPublicAccessBlock(String bucketName) {
Bucket bucket = bucketStore.get(bucketName)
.orElseThrow(() -> new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404));
if (bucket.getPublicAccessBlockConfiguration() == null) {
if (bucket.getPublicAccessBlockConfiguration() != null) {
return bucket.getPublicAccessBlockConfiguration();
}
if (bucket.isPublicAccessBlockDeleted()) {
throw new AwsException("NoSuchPublicAccessBlockConfiguration",
"The public access block configuration was not found", 404);
}
return bucket.getPublicAccessBlockConfiguration();
return DEFAULT_PUBLIC_ACCESS_BLOCK_XML;
}
public void putPublicAccessBlock(String bucketName, String xml) {
Bucket bucket = bucketStore.get(bucketName)
.orElseThrow(() -> new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404));
bucket.setPublicAccessBlockConfiguration(xml);
bucket.setPublicAccessBlockDeleted(false);
bucketStore.put(bucketName, bucket);
}
@@ -4914,6 +4932,7 @@ public class S3Service implements Resettable, ResourceProvider {
Bucket bucket = bucketStore.get(bucketName)
.orElseThrow(() -> new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404));
bucket.setPublicAccessBlockConfiguration(null);
bucket.setPublicAccessBlockDeleted(true);
bucketStore.put(bucketName, bucket);
}
@@ -27,6 +27,7 @@ public class Bucket {
private String encryptionConfiguration; // XML string
private String replicationConfiguration; // XML string
private String publicAccessBlockConfiguration; // XML string
private boolean publicAccessBlockDeleted;
private String ownershipControlsConfiguration; // XML string
private String requestPaymentPayer; // "BucketOwner" (default) or "Requester"; null until first PUT
private String accelerateStatus; // "Enabled" or "Suspended"; null until first PUT
@@ -113,6 +114,12 @@ public class Bucket {
this.publicAccessBlockConfiguration = publicAccessBlockConfiguration;
}
/** True once DeletePublicAccessBlock removed the configuration; a never-configured bucket is false. */
public boolean isPublicAccessBlockDeleted() { return publicAccessBlockDeleted; }
public void setPublicAccessBlockDeleted(boolean publicAccessBlockDeleted) {
this.publicAccessBlockDeleted = publicAccessBlockDeleted;
}
public String getOwnershipControlsConfiguration() { return ownershipControlsConfiguration; }
public void setOwnershipControlsConfiguration(String ownershipControlsConfiguration) {
this.ownershipControlsConfiguration = ownershipControlsConfiguration;