mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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:
1 parent
2d250ccf3c
commit
742bb8cf03
2 files changed
+131
-2
No files matched your search
+113
@@ -0,0 +1,113 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class S3EncryptionIntegrationTest {
|
||||
|
||||
private static final String BUCKET = "encryption-int-test";
|
||||
private static final String SSE_KMS_XML = """
|
||||
<ServerSideEncryptionConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Rule>
|
||||
<ApplyServerSideEncryptionByDefault>
|
||||
<SSEAlgorithm>aws:kms</SSEAlgorithm>
|
||||
<KMSMasterKeyID>arn:aws:kms:us-east-1:000000000000:key/abc</KMSMasterKeyID>
|
||||
</ApplyServerSideEncryptionByDefault>
|
||||
<BucketKeyEnabled>true</BucketKeyEnabled>
|
||||
</Rule>
|
||||
</ServerSideEncryptionConfiguration>
|
||||
""";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createBucket() {
|
||||
given()
|
||||
.when()
|
||||
.put("/" + BUCKET)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Since January 2023 AWS applies SSE-S3 (AES256) as the base level of encryption on every
|
||||
* bucket, and {@code GetBucketEncryption} returns that default configuration rather than
|
||||
* {@code 404 ServerSideEncryptionConfigurationNotFoundError}. The ACK s3-controller reads
|
||||
* {@code getEncryptionResponse.ServerSideEncryptionConfiguration.Rules} without a nil guard,
|
||||
* so a 404 here crashes it; returning the default keeps Floci AWS-faithful and unblocks ACK.
|
||||
*/
|
||||
@Test
|
||||
@Order(2)
|
||||
void getEncryptionBeforePutReturnsDefaultSseS3() {
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "?encryption")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<ServerSideEncryptionConfiguration"))
|
||||
.body(containsString("<SSEAlgorithm>AES256</SSEAlgorithm>"))
|
||||
.body(not(containsString("ServerSideEncryptionConfigurationNotFoundError")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void putEncryptionReturns200() {
|
||||
given()
|
||||
.body(SSE_KMS_XML)
|
||||
.when()
|
||||
.put("/" + BUCKET + "?encryption")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void getEncryptionReturnsStoredConfiguration() {
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "?encryption")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<SSEAlgorithm>aws:kms</SSEAlgorithm>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void getEncryptionOnMissingBucketReturns404() {
|
||||
given()
|
||||
.when()
|
||||
.get("/this-bucket-does-not-exist-enc?encryption")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("NoSuchBucket"));
|
||||
}
|
||||
|
||||
/**
|
||||
* After DeleteBucketEncryption clears the explicit config, GetBucketEncryption must fall back
|
||||
* to the AWS default SSE-S3 (AES256) — not the previously stored KMS config and not a 404.
|
||||
*/
|
||||
@Test
|
||||
@Order(6)
|
||||
void getEncryptionAfterDeleteReturnsDefaultSseS3() {
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + BUCKET + "?encryption")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "?encryption")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<SSEAlgorithm>AES256</SSEAlgorithm>"))
|
||||
.body(not(containsString("aws:kms")));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user