mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): take the bucket's default encryption when a multipart upload is created (#9212)
This commit is contained in:
1 parent
bf68a01fc2
commit
c15e1e26ce
7 files changed
+209
-22
No files matched your search
+2
-2
@@ -810,8 +810,8 @@ Floci now persists and returns the following object attribute state on S3 object
|
||||
- canned object ACLs from `x-amz-acl` on `PutObject`, `CopyObject`, and multipart initiation
|
||||
- explicit ACL grant headers (`x-amz-grant-read`, `x-amz-grant-write`, `x-amz-grant-full-control`, `x-amz-grant-read-acp`, `x-amz-grant-write-acp`) with `id` and `uri` grantees on `PutObject`, `CopyObject`, and multipart initiation, where they apply when the upload completes
|
||||
- Object Lock headers (`x-amz-object-lock-mode`, `x-amz-object-lock-retain-until-date`, `x-amz-object-lock-legal-hold`) on `PutObject`, `CopyObject`, and multipart initiation, where they apply when the upload completes. A mode without a date or a date without a mode, an unknown mode, or a date that is not an ISO 8601 timestamp is refused with `400 InvalidArgument`. In a bucket without Object Lock, a mode, a date or a legal hold of `ON` is refused with `400 InvalidRequest`, "Bucket is missing Object Lock Configuration", as `PutObjectRetention`, `GetObjectRetention`, `PutObjectLegalHold` and `GetObjectLegalHold` are there. `GetObjectRetention` and `GetObjectLegalHold` of an object without a retention or a legal hold answer `404 NoSuchObjectLockConfiguration`. A `PutObjectRetention` body with a mode but no date, a date but no mode, or an unknown mode is refused with `400 MalformedXML`; one naming neither removes the retention
|
||||
- object SSE from `x-amz-server-side-encryption` on `PutObject`, `CopyObject`, and multipart initiation, and form fields on browser/presigned POST, returned by `GetObject` and `HeadObject`. An object stored with neither an SSE header nor an SSE-C key takes its bucket's default encryption (`PutBucketEncryption`), SSE-S3 (`AES256`) when the bucket has none. A multipart upload takes it when it completes, a known deviation from AWS: the [`CreateMultipartUpload` response](https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html) carries `x-amz-server-side-encryption`, so an upload's encryption is set when it is created (that it cannot change later is inferred), and an `UploadPartCopy` response reports only the encryption the upload was created with. A `CopyObject` without encryption headers takes the destination bucket's default, not the source object's encryption, as the [`CopyObject` reference](https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html) says
|
||||
- SSE-KMS key IDs from `x-amz-server-side-encryption-aws-kms-key-id` on `PutObject`, browser/presigned POST, and multipart initiation, and from `CopyObject` (only when the request names the encryption; a copy without one takes the destination bucket's default; the parts of an `UploadPartCopy` take the encryption of their upload), returned by `PutObject`, `CopyObject`, `CompleteMultipartUpload`, `GetObject`, and `HeadObject`, and by `UploadPartCopy` for an upload created with an SSE-KMS header. A bucket's default SSE-KMS key is applied as configured but not simulated: `aws:kms` with no key ID, in the request or in the bucket's default encryption, omits the header rather than returning a synthesized `aws/s3` key ARN
|
||||
- object SSE from `x-amz-server-side-encryption` on `PutObject`, `CopyObject`, and multipart initiation, and form fields on browser/presigned POST, returned by `GetObject` and `HeadObject`. An object stored with neither an SSE header nor an SSE-C key takes its bucket's default encryption (`PutBucketEncryption`), SSE-S3 (`AES256`) when the bucket has none. A multipart upload takes it when it is created, as the [`CreateMultipartUpload` reference](https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html) says of its parts ("the encryption setting of the uploaded parts is set to the default encryption configuration of the destination bucket"): a default changed afterwards does not reach an upload already created (inferred), and the responses of `CreateMultipartUpload`, `UploadPart`, `UploadPartCopy` and `CompleteMultipartUpload` report it. A `CopyObject` without encryption headers takes the destination bucket's default, not the source object's encryption, as the [`CopyObject` reference](https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html) says
|
||||
- SSE-KMS key IDs from `x-amz-server-side-encryption-aws-kms-key-id` on `PutObject`, browser/presigned POST, and multipart initiation, and from `CopyObject` (only when the request names the encryption; a copy without one takes the destination bucket's default; the parts of an `UploadPartCopy` take the encryption of their upload), returned by `PutObject`, `CopyObject`, `CreateMultipartUpload`, `UploadPart`, `UploadPartCopy`, `CompleteMultipartUpload`, `GetObject`, and `HeadObject`. A bucket's default SSE-KMS key is applied as configured but not simulated: `aws:kms` with no key ID, in the request or in the bucket's default encryption, omits the header rather than returning a synthesized `aws/s3` key ARN
|
||||
|
||||
Current limitations:
|
||||
|
||||
|
||||
@@ -949,10 +949,12 @@ public class S3Controller {
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key-MD5"));
|
||||
Response.ResponseBuilder response = Response.ok().header("ETag", part.getETag());
|
||||
// S3 echoes the part checksum only when the upload declared an algorithm.
|
||||
ChecksumAlgorithm declared = s3Service.getMultipartUpload(bucket, key, uploadId).getChecksumAlgorithm();
|
||||
MultipartUpload upload = s3Service.getMultipartUpload(bucket, key, uploadId);
|
||||
ChecksumAlgorithm declared = upload.getChecksumAlgorithm();
|
||||
if (declared != null) {
|
||||
response.header(declared.headerName(), part.getChecksum().valueFor(declared));
|
||||
}
|
||||
appendServerSideEncryptionHeaders(response, upload);
|
||||
appendSseCustomerHeaders(response,
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-algorithm"),
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key-MD5"));
|
||||
@@ -1723,6 +1725,7 @@ public class S3Controller {
|
||||
response.header("x-amz-checksum-algorithm", upload.getChecksumAlgorithm().name());
|
||||
response.header("x-amz-checksum-type", upload.getChecksumType().name());
|
||||
}
|
||||
appendServerSideEncryptionHeaders(response, upload);
|
||||
appendSseCustomerHeaders(response, upload);
|
||||
return response.build();
|
||||
}
|
||||
@@ -3260,6 +3263,15 @@ public class S3Controller {
|
||||
appendSseCustomerHeaders(resp, obj.getSseCustomerAlgorithm(), obj.getSseCustomerKeyMd5());
|
||||
}
|
||||
|
||||
private static void appendServerSideEncryptionHeaders(Response.ResponseBuilder response, MultipartUpload upload) {
|
||||
if (upload.effectiveServerSideEncryption() != null) {
|
||||
response.header("x-amz-server-side-encryption", upload.effectiveServerSideEncryption());
|
||||
}
|
||||
if (upload.effectiveSseKmsKeyId() != null) {
|
||||
response.header("x-amz-server-side-encryption-aws-kms-key-id", upload.effectiveSseKmsKeyId());
|
||||
}
|
||||
}
|
||||
|
||||
private void appendSseCustomerHeaders(Response.ResponseBuilder resp, MultipartUpload upload) {
|
||||
appendSseCustomerHeaders(resp, upload.getSseCustomerAlgorithm(), upload.getSseCustomerKeyMd5());
|
||||
}
|
||||
@@ -3411,12 +3423,7 @@ public class S3Controller {
|
||||
}
|
||||
Response.ResponseBuilder response = Response.ok(xml.end("CopyPartResult").build())
|
||||
.type(MediaType.APPLICATION_XML);
|
||||
if (destinationUpload.getServerSideEncryption() != null) {
|
||||
response.header("x-amz-server-side-encryption", destinationUpload.getServerSideEncryption());
|
||||
}
|
||||
if (destinationUpload.getSseKmsKeyId() != null) {
|
||||
response.header("x-amz-server-side-encryption-aws-kms-key-id", destinationUpload.getSseKmsKeyId());
|
||||
}
|
||||
appendServerSideEncryptionHeaders(response, destinationUpload);
|
||||
appendSseCustomerHeaders(response,
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-algorithm"),
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key-MD5"));
|
||||
|
||||
@@ -4841,7 +4841,16 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
upload.setContentEncoding(objectOptions.getContentEncoding());
|
||||
upload.setCacheControl(objectOptions.getCacheControl());
|
||||
upload.setServerSideEncryption(normalizedServerSideEncryption);
|
||||
upload.setSseKmsKeyId("aws:kms".equals(normalizedServerSideEncryption) ? sseKmsKeyId : null);
|
||||
upload.setSseKmsKeyId("aws:kms".equals(normalizedServerSideEncryption)
|
||||
|| "aws:kms:dsse".equals(normalizedServerSideEncryption) ? sseKmsKeyId : null);
|
||||
if (normalizedServerSideEncryption == null && customerKey == null) {
|
||||
ObjectEncryption encryption = defaultEncryption(destination);
|
||||
upload.setDefaultServerSideEncryption(encryption.algorithm());
|
||||
upload.setDefaultSseKmsKeyId("aws:kms".equals(encryption.algorithm())
|
||||
|| "aws:kms:dsse".equals(encryption.algorithm())
|
||||
? encryption.kmsKeyId()
|
||||
: null);
|
||||
}
|
||||
if (customerKey != null) {
|
||||
upload.setSseCustomerAlgorithm(customerKey.algorithm());
|
||||
upload.setSseCustomerKeyMd5(customerKey.keyMd5());
|
||||
@@ -5368,8 +5377,8 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
.withContentDisposition(upload.getContentDisposition())
|
||||
.withContentEncoding(upload.getContentEncoding())
|
||||
.withCacheControl(upload.getCacheControl())
|
||||
.withServerSideEncryption(upload.getServerSideEncryption())
|
||||
.withSseKmsKeyId(upload.getSseKmsKeyId())
|
||||
.withServerSideEncryption(upload.effectiveServerSideEncryption())
|
||||
.withSseKmsKeyId(upload.effectiveSseKmsKeyId())
|
||||
.withAcl(upload.getAcl())
|
||||
.withGrantRead(upload.getGrantRead())
|
||||
.withGrantWrite(upload.getGrantWrite())
|
||||
@@ -5634,7 +5643,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
/** The encryption condition keys of an upload's parts and completion: what it recorded when created. */
|
||||
public Map<String, List<String>> multipartEncryptionConditions(String bucket, String key, String uploadId) {
|
||||
MultipartUpload upload = getMultipartUpload(bucket, key, uploadId);
|
||||
return S3ObjectActions.encryptionConditions(upload.getServerSideEncryption(), upload.getSseKmsKeyId());
|
||||
return S3ObjectActions.encryptionConditions(upload.effectiveServerSideEncryption(), upload.effectiveSseKmsKeyId());
|
||||
}
|
||||
|
||||
/** Checks a part or a completion against the bucket policy by the encryption its upload recorded. */
|
||||
|
||||
@@ -21,6 +21,11 @@ public class MultipartUpload {
|
||||
private String cacheControl;
|
||||
private String serverSideEncryption;
|
||||
private String sseKmsKeyId;
|
||||
// What the bucket's default encryption gave an upload whose request named none, when it was created. The two
|
||||
// fields above hold only what the request sent: the CreateMultipartUpload request is judged by its own headers,
|
||||
// its parts and completion by the effective encryption.
|
||||
private String defaultServerSideEncryption;
|
||||
private String defaultSseKmsKeyId;
|
||||
private String sseCustomerAlgorithm;
|
||||
private String sseCustomerKeyMd5;
|
||||
private String acl;
|
||||
@@ -87,6 +92,23 @@ public class MultipartUpload {
|
||||
public String getSseKmsKeyId() { return sseKmsKeyId; }
|
||||
public void setSseKmsKeyId(String sseKmsKeyId) { this.sseKmsKeyId = sseKmsKeyId; }
|
||||
|
||||
public String getDefaultServerSideEncryption() { return defaultServerSideEncryption; }
|
||||
public void setDefaultServerSideEncryption(String defaultServerSideEncryption) {
|
||||
this.defaultServerSideEncryption = defaultServerSideEncryption;
|
||||
}
|
||||
|
||||
public String getDefaultSseKmsKeyId() { return defaultSseKmsKeyId; }
|
||||
public void setDefaultSseKmsKeyId(String defaultSseKmsKeyId) { this.defaultSseKmsKeyId = defaultSseKmsKeyId; }
|
||||
|
||||
/** The encryption the upload's parts and object take: what the request sent, else the bucket default taken at creation. */
|
||||
public String effectiveServerSideEncryption() {
|
||||
return serverSideEncryption != null ? serverSideEncryption : defaultServerSideEncryption;
|
||||
}
|
||||
|
||||
public String effectiveSseKmsKeyId() {
|
||||
return serverSideEncryption != null ? sseKmsKeyId : defaultSseKmsKeyId;
|
||||
}
|
||||
|
||||
public String getSseCustomerAlgorithm() { return sseCustomerAlgorithm; }
|
||||
public void setSseCustomerAlgorithm(String sseCustomerAlgorithm) { this.sseCustomerAlgorithm = sseCustomerAlgorithm; }
|
||||
|
||||
|
||||
+19
-6
@@ -936,11 +936,8 @@ class S3BucketPolicyEnforcementIntegrationTest {
|
||||
|
||||
/**
|
||||
* A multipart upload under the same two statements. A part sends neither header, so it is judged
|
||||
* by what its upload recorded. AWS does not document this; it was measured on S3 on 2026-10-30,
|
||||
* each case here as S3 answered it. A case whose upload is opened before the policy stands uses a
|
||||
* bucket with no default encryption: S3 records the bucket's default on an upload that asks for
|
||||
* none, where Floci records only what the request asks for, so on a bucket defaulting to
|
||||
* {@code aws:kms} such a part is admitted on S3 and refused here.
|
||||
* by what its upload recorded, the bucket's default included for an upload that asked for none.
|
||||
* AWS does not document this; it was measured on S3 on 2026-10-30, each case here as S3 answered it.
|
||||
*/
|
||||
@Test
|
||||
void anUploadOpenedWithTheBucketsKeyHasItsPartsAdmittedAndStandsUnderThatKey() {
|
||||
@@ -976,7 +973,7 @@ class S3BucketPolicyEnforcementIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPartOfAnUploadThatRecordedNoEncryptionIsRefusedAndNoObjectStands() {
|
||||
void aPartOfAnUploadThatRecordedTheSseS3DefaultIsRefusedAndNoObjectStands() {
|
||||
EncryptionFixture fixture = bucketWithoutDefaultEncryption();
|
||||
String uploadId = given().filter(fixture.user().signer()).post("/" + fixture.bucket() + "/plain.bin?uploads")
|
||||
.then().statusCode(200)
|
||||
@@ -991,6 +988,22 @@ class S3BucketPolicyEnforcementIntegrationTest {
|
||||
.then().statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPartOfAnUploadOpenedWithNoEncryptionIsJudgedByTheDefaultItRecorded() {
|
||||
String suffix = suffix();
|
||||
EncryptionFixture fixture = encryptionBucket("kms-default-" + suffix,
|
||||
encryptionUser("kms-default-user-" + suffix, ALLOW_S3_AND_KMS), suffix, true);
|
||||
String uploadId = given().filter(fixture.user().signer()).post("/" + fixture.bucket() + "/default.bin?uploads")
|
||||
.then().statusCode(200)
|
||||
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
|
||||
putKmsOnlyPolicy(fixture);
|
||||
|
||||
uploadPart(fixture.user().signer(), fixture, "default.bin", uploadId).then().statusCode(200);
|
||||
|
||||
given().filter(fixture.owner()).delete("/" + fixture.bucket() + "/default.bin?uploadId=" + uploadId)
|
||||
.then().statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPartOfAnUploadThatRecordedAnotherEncryptionIsRefused() {
|
||||
EncryptionFixture fixture = bucketWithoutDefaultEncryption();
|
||||
|
||||
@@ -8,12 +8,16 @@ import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.core.ResponseInputStream;
|
||||
import software.amazon.awssdk.core.sync.RequestBody;
|
||||
import software.amazon.awssdk.services.s3.S3Client;
|
||||
import software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse;
|
||||
import software.amazon.awssdk.services.s3.model.CompletedPart;
|
||||
import software.amazon.awssdk.services.s3.model.CopyObjectResponse;
|
||||
import software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse;
|
||||
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
|
||||
import software.amazon.awssdk.services.s3.model.HeadObjectResponse;
|
||||
import software.amazon.awssdk.services.s3.model.PutObjectResponse;
|
||||
import software.amazon.awssdk.services.s3.model.ServerSideEncryption;
|
||||
import software.amazon.awssdk.services.s3.model.UploadPartCopyResponse;
|
||||
import software.amazon.awssdk.services.s3.model.UploadPartResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -45,9 +49,12 @@ class S3DefaultEncryptionIntegrationTest {
|
||||
|
||||
@AfterEach
|
||||
void deleteBucketsAndCloseClient() {
|
||||
S3TestClients.deleteBucket(s3, bucket);
|
||||
otherBuckets.forEach(other -> S3TestClients.deleteBucket(s3, other));
|
||||
s3.close();
|
||||
try {
|
||||
S3TestClients.deleteBucket(s3, bucket);
|
||||
otherBuckets.forEach(other -> S3TestClients.deleteBucket(s3, other));
|
||||
} finally {
|
||||
s3.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,6 +96,65 @@ class S3DefaultEncryptionIntegrationTest {
|
||||
assertEquals(KMS_KEY, head.ssekmsKeyId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMultipartUploadReportsTheDefaultInEveryResponse() {
|
||||
useKmsDefault();
|
||||
s3.putObject(r -> r.bucket(bucket).key("source"), RequestBody.fromString("source"));
|
||||
|
||||
CreateMultipartUploadResponse created = s3.createMultipartUpload(r -> r.bucket(bucket).key("multipart"));
|
||||
String uploadId = created.uploadId();
|
||||
UploadPartResponse part = s3.uploadPart(r -> r.bucket(bucket).key("multipart").uploadId(uploadId)
|
||||
.partNumber(1), RequestBody.fromString("part"));
|
||||
UploadPartCopyResponse copied = s3.uploadPartCopy(r -> r.sourceBucket(bucket).sourceKey("source")
|
||||
.destinationBucket(bucket).destinationKey("multipart").uploadId(uploadId).partNumber(2));
|
||||
|
||||
assertEquals(ServerSideEncryption.AWS_KMS, created.serverSideEncryption());
|
||||
assertEquals(KMS_KEY, created.ssekmsKeyId());
|
||||
assertEquals(ServerSideEncryption.AWS_KMS, part.serverSideEncryption());
|
||||
assertEquals(KMS_KEY, part.ssekmsKeyId());
|
||||
assertEquals(ServerSideEncryption.AWS_KMS, copied.serverSideEncryption());
|
||||
assertEquals(KMS_KEY, copied.ssekmsKeyId());
|
||||
s3.abortMultipartUpload(r -> r.bucket(bucket).key("multipart").uploadId(uploadId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMultipartUploadKeepsTheDefaultItWasCreatedWith() {
|
||||
useKmsDefault();
|
||||
String uploadId = s3.createMultipartUpload(r -> r.bucket(bucket).key("multipart")).uploadId();
|
||||
s3.putBucketEncryption(r -> r.bucket(bucket).serverSideEncryptionConfiguration(c -> c.rules(rule ->
|
||||
rule.applyServerSideEncryptionByDefault(d -> d.sseAlgorithm(ServerSideEncryption.AES256)))));
|
||||
|
||||
UploadPartResponse part = s3.uploadPart(r -> r.bucket(bucket).key("multipart").uploadId(uploadId)
|
||||
.partNumber(1), RequestBody.fromString("part"));
|
||||
CompleteMultipartUploadResponse completed = s3.completeMultipartUpload(r -> r.bucket(bucket)
|
||||
.key("multipart").uploadId(uploadId).multipartUpload(m -> m.parts(
|
||||
CompletedPart.builder().partNumber(1).eTag(part.eTag()).build())));
|
||||
|
||||
assertEquals(ServerSideEncryption.AWS_KMS, part.serverSideEncryption());
|
||||
assertEquals(ServerSideEncryption.AWS_KMS, completed.serverSideEncryption());
|
||||
assertEquals(KMS_KEY, completed.ssekmsKeyId());
|
||||
HeadObjectResponse head = head("multipart");
|
||||
assertEquals(ServerSideEncryption.AWS_KMS, head.serverSideEncryption());
|
||||
assertEquals(KMS_KEY, head.ssekmsKeyId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMultipartUploadWithAnExplicitHeaderReportsIt() {
|
||||
useKmsDefault();
|
||||
|
||||
CreateMultipartUploadResponse created = s3.createMultipartUpload(r -> r.bucket(bucket).key("multipart")
|
||||
.serverSideEncryption(ServerSideEncryption.AES256));
|
||||
String uploadId = created.uploadId();
|
||||
UploadPartResponse part = s3.uploadPart(r -> r.bucket(bucket).key("multipart").uploadId(uploadId)
|
||||
.partNumber(1), RequestBody.fromString("part"));
|
||||
|
||||
assertEquals(ServerSideEncryption.AES256, created.serverSideEncryption());
|
||||
assertNull(created.ssekmsKeyId());
|
||||
assertEquals(ServerSideEncryption.AES256, part.serverSideEncryption());
|
||||
assertNull(part.ssekmsKeyId());
|
||||
s3.abortMultipartUpload(r -> r.bucket(bucket).key("multipart").uploadId(uploadId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCopyIntoAKmsDefaultBucketTakesItsKey() {
|
||||
s3.putObject(r -> r.bucket(bucket).key("source"), RequestBody.fromString("source"));
|
||||
|
||||
@@ -155,6 +155,76 @@ class S3DefaultEncryptionServiceTest {
|
||||
assertNull(s3Service.getObject(BUCKET, "multipart-sse-c.bin").getServerSideEncryption());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMultipartUploadTakesTheDefaultWhenItIsCreated() {
|
||||
s3Service.putBucketEncryption(BUCKET, configuration("aws:kms", KMS_KEY));
|
||||
MultipartUpload upload = s3Service.initiateMultipartUpload(BUCKET, "created.bin",
|
||||
"application/octet-stream", Map.of(), null, new PutObjectOptions());
|
||||
|
||||
assertEquals("aws:kms", upload.effectiveServerSideEncryption());
|
||||
assertEquals(KMS_KEY, upload.effectiveSseKmsKeyId());
|
||||
assertNull(upload.getServerSideEncryption());
|
||||
assertEquals(Map.of("s3:x-amz-server-side-encryption", List.of("aws:kms"),
|
||||
"s3:x-amz-server-side-encryption-aws-kms-key-id", List.of(KMS_KEY)),
|
||||
s3Service.multipartEncryptionConditions(BUCKET, "created.bin", upload.getUploadId()));
|
||||
|
||||
s3Service.putBucketEncryption(BUCKET, configuration("AES256", null));
|
||||
s3Service.uploadPart(BUCKET, "created.bin", upload.getUploadId(), 1, DATA);
|
||||
S3Object completed = s3Service.completeMultipartUpload(BUCKET, "created.bin", upload.getUploadId(),
|
||||
List.of(1), null, null);
|
||||
|
||||
assertEquals("aws:kms", completed.getServerSideEncryption());
|
||||
assertEquals(KMS_KEY, completed.getSseKmsKeyId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aDualLayerKmsDefaultReachesAMultipartUploadWithItsKey() {
|
||||
s3Service.putBucketEncryption(BUCKET, configuration("aws:kms:dsse", KMS_KEY));
|
||||
MultipartUpload upload = s3Service.initiateMultipartUpload(BUCKET, "dsse.bin",
|
||||
"application/octet-stream", Map.of(), null, new PutObjectOptions());
|
||||
s3Service.uploadPart(BUCKET, "dsse.bin", upload.getUploadId(), 1, DATA);
|
||||
S3Object completed = s3Service.completeMultipartUpload(BUCKET, "dsse.bin", upload.getUploadId(),
|
||||
List.of(1), null, null);
|
||||
|
||||
assertEquals("aws:kms:dsse", upload.effectiveServerSideEncryption());
|
||||
assertEquals(KMS_KEY, upload.effectiveSseKmsKeyId());
|
||||
assertEquals("aws:kms:dsse", completed.getServerSideEncryption());
|
||||
assertEquals(KMS_KEY, completed.getSseKmsKeyId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anExplicitDualLayerHeaderKeepsItsKeyId() {
|
||||
s3Service.putBucketEncryption(BUCKET, configuration("aws:kms", KMS_KEY));
|
||||
MultipartUpload upload = s3Service.initiateMultipartUpload(BUCKET, "explicit-dsse.bin",
|
||||
"application/octet-stream", Map.of(), null,
|
||||
new PutObjectOptions().withServerSideEncryption("aws:kms:dsse").withSseKmsKeyId(OTHER_KMS_KEY));
|
||||
s3Service.uploadPart(BUCKET, "explicit-dsse.bin", upload.getUploadId(), 1, DATA);
|
||||
S3Object completed = s3Service.completeMultipartUpload(BUCKET, "explicit-dsse.bin", upload.getUploadId(),
|
||||
List.of(1), null, null);
|
||||
|
||||
assertEquals("aws:kms:dsse", upload.effectiveServerSideEncryption());
|
||||
assertEquals(OTHER_KMS_KEY, upload.effectiveSseKmsKeyId());
|
||||
assertEquals("aws:kms:dsse", completed.getServerSideEncryption());
|
||||
assertEquals(OTHER_KMS_KEY, completed.getSseKmsKeyId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUploadThatSendsItsOwnEncryptionRecordsNoDefault() throws Exception {
|
||||
s3Service.putBucketEncryption(BUCKET, configuration("aws:kms", KMS_KEY));
|
||||
|
||||
MultipartUpload explicit = s3Service.initiateMultipartUpload(BUCKET, "explicit.bin",
|
||||
"application/octet-stream", Map.of(), null, new PutObjectOptions().withServerSideEncryption("AES256"));
|
||||
MultipartUpload sseC = s3Service.initiateMultipartUpload(BUCKET, "sse-c.bin",
|
||||
"application/octet-stream", Map.of(), null, customerKey(new PutObjectOptions()));
|
||||
|
||||
assertEquals("AES256", explicit.effectiveServerSideEncryption());
|
||||
assertNull(explicit.effectiveSseKmsKeyId());
|
||||
assertNull(explicit.getDefaultServerSideEncryption());
|
||||
assertNull(sseC.effectiveServerSideEncryption());
|
||||
assertNull(sseC.effectiveSseKmsKeyId());
|
||||
assertNull(sseC.getDefaultServerSideEncryption());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aConfigurationWithoutAnAlgorithmFallsBackToSseS3() {
|
||||
s3Service.putBucketEncryption(BUCKET, "<ServerSideEncryptionConfiguration/>");
|
||||
|
||||
Reference in new issue
Block a user