fix(s3): return default SSE-S3 from GetBucketEncryption instead of 404 (#1838)

* fix(s3): return default SSE-S3 from GetBucketEncryption instead of 404

Real S3 no longer 404s GetBucketEncryption for a bucket with no explicit
config: since 2023-01-05 every bucket has SSE-S3 (AES256) default encryption,
so GetBucketEncryption returns that config rather than
ServerSideEncryptionConfigurationNotFoundError.

  https://docs.aws.amazon.com/AmazonS3/latest/userguide/default-bucket-encryption.html
  "Amazon S3 now applies server-side encryption with Amazon S3 managed keys
   (SSE-S3) as the base level of encryption for every bucket in Amazon S3.
   Starting January 5, 2023, all new object uploads to Amazon S3 are
   automatically encrypted."

Floci still emulated the pre-2023 404-when-unset behavior.

Some software relies on the new behavior, such as AWS's AWS Controllers for K8s
s3-controller: its Bucket read-back catches the NotFound code but does not
return, then dereferences ServerSideEncryptionConfiguration.Rules on a nil
response (nil-pointer panic that loops the controller). ACK code for reference:

  https://github.com/aws-controllers-k8s/s3-controller/blob/v1.6.0/pkg/resource/bucket/hook.go

Return the AWS default SSE-S3 config when none is set; an explicit
PutBucketEncryption config is still echoed back, and a missing bucket still
404s NoSuchBucket. Mirrors GetBucketRequestPayment's existing default.

Closes #1836

* test(s3): cover GetBucketEncryption default after DeleteBucketEncryption

Greptile flagged the delete-then-get path was uncovered: after
DeleteBucketEncryption nulls the stored config, GetBucketEncryption must
fall back to the default SSE-S3 (AES256) rather than the prior KMS config
or a 404. Adds an ordered case exercising the ?encryption DELETE handler
plus the null-after-delete branch.
This commit is contained in:
Marius Volkhart authored and GitHub committed 2026-07-11 15:19:27 -05:00
1 parent 2d250ccf3c
commit 742bb8cf03
2 files changed
+131 -2

No files matched your search

@@ -1757,12 +1757,28 @@ public class S3Service implements Resettable {
objectStore.put(storeKey, obj);
}
/**
* Returns the bucket's server-side encryption configuration as XML.
* <p>
* Buckets that have
* never been configured return the AWS default (SSE-S3 / {@code AES256});
* since January 2023 AWS applies SSE-S3 as the base level of encryption on
* every bucket and never returns 404 for {@code GetBucketEncryption}.
*/
public String getBucketEncryption(String bucketName) {
Bucket bucket = bucketStore.get(bucketName)
.orElseThrow(() -> new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404));
if (bucket.getEncryptionConfiguration() == null) {
throw new AwsException("ServerSideEncryptionConfigurationNotFoundError",
"The server side encryption configuration was not found", 404);
return new XmlBuilder()
.start("ServerSideEncryptionConfiguration", AwsNamespaces.S3)
.start("Rule")
.start("ApplyServerSideEncryptionByDefault")
.elem("SSEAlgorithm", "AES256")
.end("ApplyServerSideEncryptionByDefault")
.elem("BucketKeyEnabled", "false")
.end("Rule")
.end("ServerSideEncryptionConfiguration")
.build();
}
return bucket.getEncryptionConfiguration();
}