mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(s3): preserve SSE-KMS key ID metadata (#2145)
* fix(s3): preserve SSE-KMS key ID metadata * fix(s3): validate and copy SSE-KMS key metadata * fix(s3): return SSE headers on CopyObject and UploadPartCopy responses Both handleCopyObject and handleUploadPartCopy stored the destination's server-side-encryption settings correctly but never echoed x-amz-server-side-encryption / x-amz-server-side-encryption-aws-kms-key-id on their own response — only a follow-up GET/HEAD on the copy revealed it, which is why the existing SSE tests (checking only via HEAD) never caught this. Real S3 returns both headers on CopyObjectResult and CopyPartResult. UploadPartCopy required threading the KMS key id through CreateMultipartUpload too: MultipartUpload had no field for it, so a part's destination upload had nowhere to read it back from. * fix(s3): drop em dashes from merged UploadPartCopy comments AGENTS.md rules out em dashes anywhere in content. The two comments moved during the origin/main downmerge (handleUploadPartCopy's SSE-settings note and the relocated uploadPartCopyPreservesDestinationServerSideEncryption test) carried one each. Reworded to a period and a comma respectively. --------- Co-authored-by: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>
This commit is contained in:
1 parent
974d357f88
commit
d466ffe099
9 files changed
+265
-5
No files matched your search
@@ -349,6 +349,7 @@ Floci now persists and returns the following object attribute state on S3 object
|
||||
- multipart checksums follow the AWS checksum type: `COMPOSITE` (`<checksum of the part checksums>-<part count>`) for SHA1, SHA256 and, by default, CRC32 and CRC32C; `FULL_OBJECT` for CRC64NVME or when `x-amz-checksum-type: FULL_OBJECT` was requested on `CreateMultipartUpload`. The `-N` suffix is returned by `CompleteMultipartUpload`, `HeadObject` and `GetObject`, and omitted by `GetObjectAttributes`, which lists part-level checksums only for `COMPOSITE` objects (a `FULL_OBJECT` multipart object reports its `PartsCount` alone, a single-part object has no `ObjectParts`), as on AWS. `UploadPart` echoes the part checksum (`x-amz-checksum-<algorithm>`) when the upload declared an algorithm, and completing a `COMPOSITE` upload requires the checksum of every part in the `CompleteMultipartUpload` body (`InvalidRequest` otherwise), while `FULL_OBJECT` uploads accept a body without them
|
||||
- canned object ACLs from `x-amz-acl` on `PutObject`, `CopyObject`, and multipart initiation
|
||||
- explicit object SSE headers from `x-amz-server-side-encryption` on `PutObject`, `CopyObject`, and multipart initiation, replayed on `GetObject` and `HeadObject`
|
||||
- SSE-KMS key IDs from `x-amz-server-side-encryption-aws-kms-key-id` on `PutObject` and multipart initiation, and from `CopyObject`/`UploadPartCopy` (inherited from the source object when the request doesn't specify new SSE headers), returned by `PutObject`, `CopyObject`, `UploadPartCopy`, `CompleteMultipartUpload`, `GetObject`, and `HeadObject`. A bucket's default SSE-KMS key is not simulated: `aws:kms` with no explicit key ID omits the header rather than returning a synthesized `aws/s3` key ARN
|
||||
|
||||
Current limitations:
|
||||
|
||||
|
||||
@@ -804,6 +804,7 @@ public class S3Controller {
|
||||
String contentDisposition = httpHeaders.getHeaderString("Content-Disposition");
|
||||
String cacheControl = httpHeaders.getHeaderString("Cache-Control");
|
||||
String serverSideEncryption = httpHeaders.getHeaderString("x-amz-server-side-encryption");
|
||||
String sseKmsKeyId = httpHeaders.getHeaderString("x-amz-server-side-encryption-aws-kms-key-id");
|
||||
String sseCustomerAlgorithm = httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-algorithm");
|
||||
String sseCustomerKey = httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key");
|
||||
String sseCustomerKeyMd5 = httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key-MD5");
|
||||
@@ -819,6 +820,7 @@ public class S3Controller {
|
||||
.withContentDisposition(contentDisposition)
|
||||
.withCacheControl(cacheControl)
|
||||
.withServerSideEncryption(serverSideEncryption)
|
||||
.withSseKmsKeyId(sseKmsKeyId)
|
||||
.withSseCustomerAlgorithm(sseCustomerAlgorithm)
|
||||
.withSseCustomerKey(sseCustomerKey)
|
||||
.withSseCustomerKeyMd5(sseCustomerKeyMd5)
|
||||
@@ -1325,6 +1327,7 @@ public class S3Controller {
|
||||
httpHeaders.getHeaderString("Content-Disposition"),
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption"),
|
||||
httpHeaders.getHeaderString("x-amz-acl"),
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption-aws-kms-key-id"),
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-algorithm"),
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key"),
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key-MD5"),
|
||||
@@ -1395,6 +1398,12 @@ public class S3Controller {
|
||||
if (obj.getVersionId() != null) {
|
||||
resp.header("x-amz-version-id", obj.getVersionId());
|
||||
}
|
||||
if (obj.getServerSideEncryption() != null) {
|
||||
resp.header("x-amz-server-side-encryption", obj.getServerSideEncryption());
|
||||
}
|
||||
if (obj.getSseKmsKeyId() != null) {
|
||||
resp.header("x-amz-server-side-encryption-aws-kms-key-id", obj.getSseKmsKeyId());
|
||||
}
|
||||
appendSseCustomerHeaders(resp, obj);
|
||||
return resp.build();
|
||||
}
|
||||
@@ -2223,6 +2232,9 @@ public class S3Controller {
|
||||
if (obj.getServerSideEncryption() != null) {
|
||||
resp.header("x-amz-server-side-encryption", obj.getServerSideEncryption());
|
||||
}
|
||||
if (obj.getSseKmsKeyId() != null) {
|
||||
resp.header("x-amz-server-side-encryption-aws-kms-key-id", obj.getSseKmsKeyId());
|
||||
}
|
||||
appendSseCustomerHeaders(resp, obj);
|
||||
appendChecksumHeaders(resp, obj.getChecksum());
|
||||
appendLockHeaders(resp, obj);
|
||||
@@ -2251,6 +2263,9 @@ public class S3Controller {
|
||||
if (obj.getServerSideEncryption() != null) {
|
||||
resp.header("x-amz-server-side-encryption", obj.getServerSideEncryption());
|
||||
}
|
||||
if (obj.getSseKmsKeyId() != null) {
|
||||
resp.header("x-amz-server-side-encryption-aws-kms-key-id", obj.getSseKmsKeyId());
|
||||
}
|
||||
appendSseCustomerHeaders(resp, obj);
|
||||
if (overrides.contentLanguage() != null) {
|
||||
resp.header("Content-Language", overrides.contentLanguage());
|
||||
@@ -2311,6 +2326,7 @@ public class S3Controller {
|
||||
String copyContentDisposition = httpHeaders.getHeaderString("Content-Disposition");
|
||||
String copyCacheControl = httpHeaders.getHeaderString("Cache-Control");
|
||||
String copyServerSideEncryption = httpHeaders.getHeaderString("x-amz-server-side-encryption");
|
||||
String copySseKmsKeyId = httpHeaders.getHeaderString("x-amz-server-side-encryption-aws-kms-key-id");
|
||||
String cannedAcl = httpHeaders.getHeaderString("x-amz-acl");
|
||||
String taggingDirective = httpHeaders.getHeaderString("x-amz-tagging-directive");
|
||||
String taggingHeader = httpHeaders.getHeaderString("x-amz-tagging");
|
||||
@@ -2330,6 +2346,7 @@ public class S3Controller {
|
||||
.withContentDisposition(copyContentDisposition)
|
||||
.withCacheControl(copyCacheControl)
|
||||
.withServerSideEncryption(copyServerSideEncryption)
|
||||
.withSseKmsKeyId(copySseKmsKeyId)
|
||||
.withSseCustomerAlgorithm(httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-algorithm"))
|
||||
.withSseCustomerKey(httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key"))
|
||||
.withSseCustomerKeyMd5(httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key-MD5"))
|
||||
@@ -2351,6 +2368,12 @@ public class S3Controller {
|
||||
appendChecksumElements(xmlBuilder, copy.getChecksum());
|
||||
String xml = xmlBuilder.end("CopyObjectResult").build();
|
||||
Response.ResponseBuilder response = Response.ok(xml).type(MediaType.APPLICATION_XML);
|
||||
if (copy.getServerSideEncryption() != null) {
|
||||
response.header("x-amz-server-side-encryption", copy.getServerSideEncryption());
|
||||
}
|
||||
if (copy.getSseKmsKeyId() != null) {
|
||||
response.header("x-amz-server-side-encryption-aws-kms-key-id", copy.getSseKmsKeyId());
|
||||
}
|
||||
appendSseCustomerHeaders(response, copy);
|
||||
return response.build();
|
||||
}
|
||||
@@ -2369,6 +2392,11 @@ public class S3Controller {
|
||||
sourceBucket, sourceObject.objectKey(), sourceObject.versionId(), copySourceRange,
|
||||
copySourceSseCustomerHeaders(httpHeaders),
|
||||
sseCustomerHeaders(httpHeaders));
|
||||
// The destination multipart upload's own SSE settings (captured at
|
||||
// CreateMultipartUpload), not anything from this request's headers.
|
||||
// UploadPartCopy doesn't take server-side-encryption headers itself,
|
||||
// parts always inherit the upload they belong to.
|
||||
MultipartUpload destinationUpload = s3Service.listParts(destBucket, destKey, uploadId);
|
||||
String xml = new XmlBuilder()
|
||||
.raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
||||
.start("CopyPartResult", AwsNamespaces.S3)
|
||||
@@ -2377,6 +2405,12 @@ public class S3Controller {
|
||||
.end("CopyPartResult")
|
||||
.build();
|
||||
Response.ResponseBuilder response = Response.ok(xml).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());
|
||||
}
|
||||
appendSseCustomerHeaders(response,
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-algorithm"),
|
||||
httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key-MD5"));
|
||||
|
||||
@@ -467,6 +467,9 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
object.setContentDisposition(effectiveOptions.getContentDisposition());
|
||||
object.setCacheControl(effectiveOptions.getCacheControl());
|
||||
object.setServerSideEncryption(normalizedServerSideEncryption);
|
||||
object.setSseKmsKeyId("aws:kms".equals(normalizedServerSideEncryption)
|
||||
? effectiveOptions.getSseKmsKeyId()
|
||||
: null);
|
||||
if (sseCustomerKey != null) {
|
||||
object.setSseCustomerAlgorithm(sseCustomerKey.algorithm());
|
||||
object.setSseCustomerKeyMd5(sseCustomerKey.keyMd5());
|
||||
@@ -2306,7 +2309,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
Map<String, String> metadata, String storageClass,
|
||||
String contentDisposition, String serverSideEncryption, String acl) {
|
||||
return initiateMultipartUpload(bucket, key, contentType, metadata, storageClass, contentDisposition,
|
||||
serverSideEncryption, acl, null, null, null, null);
|
||||
serverSideEncryption, acl, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public MultipartUpload initiateMultipartUpload(String bucket, String key, String contentType,
|
||||
@@ -2315,8 +2318,8 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
String sseCustomerAlgorithm, String sseCustomerKey, String sseCustomerKeyMd5,
|
||||
String checksumAlgorithm) {
|
||||
return initiateMultipartUpload(bucket, key, contentType, metadata, storageClass, contentDisposition,
|
||||
serverSideEncryption, acl, sseCustomerAlgorithm, sseCustomerKey, sseCustomerKeyMd5,
|
||||
checksumAlgorithm, null);
|
||||
serverSideEncryption, acl, null, sseCustomerAlgorithm, sseCustomerKey, sseCustomerKeyMd5,
|
||||
checksumAlgorithm, null, null);
|
||||
}
|
||||
|
||||
public MultipartUpload initiateMultipartUpload(String bucket, String key, String contentType,
|
||||
@@ -2325,7 +2328,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
String sseCustomerAlgorithm, String sseCustomerKey, String sseCustomerKeyMd5,
|
||||
String checksumAlgorithm, Map<String, String> tagging) {
|
||||
return initiateMultipartUpload(bucket, key, contentType, metadata, storageClass, contentDisposition,
|
||||
serverSideEncryption, acl, sseCustomerAlgorithm, sseCustomerKey, sseCustomerKeyMd5,
|
||||
serverSideEncryption, acl, null, sseCustomerAlgorithm, sseCustomerKey, sseCustomerKeyMd5,
|
||||
checksumAlgorithm, null, tagging);
|
||||
}
|
||||
|
||||
@@ -2335,6 +2338,18 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
String sseCustomerAlgorithm, String sseCustomerKey, String sseCustomerKeyMd5,
|
||||
String checksumAlgorithm, String checksumType,
|
||||
Map<String, String> tagging) {
|
||||
return initiateMultipartUpload(bucket, key, contentType, metadata, storageClass, contentDisposition,
|
||||
serverSideEncryption, acl, null, sseCustomerAlgorithm, sseCustomerKey, sseCustomerKeyMd5,
|
||||
checksumAlgorithm, checksumType, tagging);
|
||||
}
|
||||
|
||||
public MultipartUpload initiateMultipartUpload(String bucket, String key, String contentType,
|
||||
Map<String, String> metadata, String storageClass,
|
||||
String contentDisposition, String serverSideEncryption, String acl,
|
||||
String sseKmsKeyId,
|
||||
String sseCustomerAlgorithm, String sseCustomerKey, String sseCustomerKeyMd5,
|
||||
String checksumAlgorithm, String checksumType,
|
||||
Map<String, String> tagging) {
|
||||
ensureBucketExists(bucket);
|
||||
if (acl != null && !acl.isBlank()) {
|
||||
cannedObjectAclXml(acl);
|
||||
@@ -2349,6 +2364,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
upload.setStorageClass(ObjectAttributeName.normalizeStorageClass(storageClass));
|
||||
upload.setContentDisposition(contentDisposition);
|
||||
upload.setServerSideEncryption(normalizedServerSideEncryption);
|
||||
upload.setSseKmsKeyId("aws:kms".equals(normalizedServerSideEncryption) ? sseKmsKeyId : null);
|
||||
if (customerKey != null) {
|
||||
upload.setSseCustomerAlgorithm(customerKey.algorithm());
|
||||
upload.setSseCustomerKeyMd5(customerKey.keyMd5());
|
||||
@@ -2523,6 +2539,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
.withStorageClass(upload.getStorageClass())
|
||||
.withContentDisposition(upload.getContentDisposition())
|
||||
.withServerSideEncryption(upload.getServerSideEncryption())
|
||||
.withSseKmsKeyId(upload.getSseKmsKeyId())
|
||||
.withAcl(upload.getAcl())
|
||||
.withTagging(upload.getTagging()));
|
||||
if (upload.getSseCustomerAlgorithm() != null) {
|
||||
@@ -3643,6 +3660,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
copy.setContentDisposition(source.getContentDisposition());
|
||||
copy.setCacheControl(source.getCacheControl());
|
||||
copy.setServerSideEncryption(source.getServerSideEncryption());
|
||||
copy.setSseKmsKeyId(source.getSseKmsKeyId());
|
||||
copy.setSseCustomerAlgorithm(source.getSseCustomerAlgorithm());
|
||||
copy.setSseCustomerKeyMd5(source.getSseCustomerKeyMd5());
|
||||
copy.setSize(source.getSize());
|
||||
@@ -4078,6 +4096,11 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
String effectiveServerSideEncryption = destinationCustomerKey != null
|
||||
? null
|
||||
: (normalizedServerSideEncryption != null ? normalizedServerSideEncryption : source.getServerSideEncryption());
|
||||
String effectiveSseKmsKeyId = "aws:kms".equals(effectiveServerSideEncryption)
|
||||
? (normalizedServerSideEncryption != null
|
||||
? effectiveOptions.getSseKmsKeyId()
|
||||
: source.getSseKmsKeyId())
|
||||
: null;
|
||||
boolean replaceTags = "REPLACE".equalsIgnoreCase(effectiveOptions.getTaggingDirective());
|
||||
Map<String, String> effectiveTags = replaceTags
|
||||
? effectiveOptions.getReplacementTagging()
|
||||
@@ -4103,6 +4126,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
.withContentDisposition(effectiveContentDisposition)
|
||||
.withCacheControl(effectiveCacheControl)
|
||||
.withServerSideEncryption(effectiveServerSideEncryption)
|
||||
.withSseKmsKeyId(effectiveSseKmsKeyId)
|
||||
.withSseCustomerAlgorithm(effectiveOptions.getSseCustomerAlgorithm())
|
||||
.withSseCustomerKey(effectiveOptions.getSseCustomerKey())
|
||||
.withSseCustomerKeyMd5(effectiveOptions.getSseCustomerKeyMd5())
|
||||
|
||||
@@ -13,6 +13,7 @@ public class CopyObjectOptions {
|
||||
private String contentDisposition;
|
||||
private String cacheControl;
|
||||
private String serverSideEncryption;
|
||||
private String sseKmsKeyId;
|
||||
private String sseCustomerAlgorithm;
|
||||
private String sseCustomerKey;
|
||||
private String sseCustomerKeyMd5;
|
||||
@@ -57,6 +58,9 @@ public class CopyObjectOptions {
|
||||
public String getServerSideEncryption() { return serverSideEncryption; }
|
||||
public CopyObjectOptions withServerSideEncryption(String serverSideEncryption) { this.serverSideEncryption = serverSideEncryption; return this; }
|
||||
|
||||
public String getSseKmsKeyId() { return sseKmsKeyId; }
|
||||
public CopyObjectOptions withSseKmsKeyId(String sseKmsKeyId) { this.sseKmsKeyId = sseKmsKeyId; return this; }
|
||||
|
||||
public String getSseCustomerAlgorithm() { return sseCustomerAlgorithm; }
|
||||
public CopyObjectOptions withSseCustomerAlgorithm(String sseCustomerAlgorithm) { this.sseCustomerAlgorithm = sseCustomerAlgorithm; return this; }
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ public class MultipartUpload {
|
||||
private String storageClass;
|
||||
private String contentDisposition;
|
||||
private String serverSideEncryption;
|
||||
private String sseKmsKeyId;
|
||||
private String sseCustomerAlgorithm;
|
||||
private String sseCustomerKeyMd5;
|
||||
private String acl;
|
||||
@@ -64,6 +65,9 @@ public class MultipartUpload {
|
||||
public String getServerSideEncryption() { return serverSideEncryption; }
|
||||
public void setServerSideEncryption(String serverSideEncryption) { this.serverSideEncryption = serverSideEncryption; }
|
||||
|
||||
public String getSseKmsKeyId() { return sseKmsKeyId; }
|
||||
public void setSseKmsKeyId(String sseKmsKeyId) { this.sseKmsKeyId = sseKmsKeyId; }
|
||||
|
||||
public String getSseCustomerAlgorithm() { return sseCustomerAlgorithm; }
|
||||
public void setSseCustomerAlgorithm(String sseCustomerAlgorithm) { this.sseCustomerAlgorithm = sseCustomerAlgorithm; }
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ public class PutObjectOptions {
|
||||
private String contentDisposition;
|
||||
private String cacheControl;
|
||||
private String serverSideEncryption;
|
||||
private String sseKmsKeyId;
|
||||
private String sseCustomerAlgorithm;
|
||||
private String sseCustomerKey;
|
||||
private String sseCustomerKeyMd5;
|
||||
@@ -50,6 +51,9 @@ public class PutObjectOptions {
|
||||
public String getServerSideEncryption() { return serverSideEncryption; }
|
||||
public PutObjectOptions withServerSideEncryption(String serverSideEncryption) { this.serverSideEncryption = serverSideEncryption; return this; }
|
||||
|
||||
public String getSseKmsKeyId() { return sseKmsKeyId; }
|
||||
public PutObjectOptions withSseKmsKeyId(String sseKmsKeyId) { this.sseKmsKeyId = sseKmsKeyId; return this; }
|
||||
|
||||
public String getSseCustomerAlgorithm() { return sseCustomerAlgorithm; }
|
||||
public PutObjectOptions withSseCustomerAlgorithm(String sseCustomerAlgorithm) { this.sseCustomerAlgorithm = sseCustomerAlgorithm; return this; }
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ public class S3Object {
|
||||
private String contentDisposition;
|
||||
private String cacheControl;
|
||||
private String serverSideEncryption;
|
||||
private String sseKmsKeyId;
|
||||
private String sseCustomerAlgorithm;
|
||||
private String sseCustomerKeyMd5;
|
||||
private long size;
|
||||
@@ -103,6 +104,9 @@ public class S3Object {
|
||||
public String getServerSideEncryption() { return serverSideEncryption; }
|
||||
public void setServerSideEncryption(String serverSideEncryption) { this.serverSideEncryption = serverSideEncryption; }
|
||||
|
||||
public String getSseKmsKeyId() { return sseKmsKeyId; }
|
||||
public void setSseKmsKeyId(String sseKmsKeyId) { this.sseKmsKeyId = sseKmsKeyId; }
|
||||
|
||||
public String getSseCustomerAlgorithm() { return sseCustomerAlgorithm; }
|
||||
public void setSseCustomerAlgorithm(String sseCustomerAlgorithm) { this.sseCustomerAlgorithm = sseCustomerAlgorithm; }
|
||||
|
||||
|
||||
@@ -1581,6 +1581,31 @@ class S3IntegrationTest {
|
||||
.statusCode(200)
|
||||
.header("ETag", notNullValue())
|
||||
.header("x-amz-server-side-encryption", equalTo("AES256"));
|
||||
|
||||
String kmsKeyId = "arn:aws:kms:us-east-1:000000000000:key/test-key";
|
||||
given()
|
||||
.contentType("text/plain")
|
||||
.header("x-amz-server-side-encryption", "aws:kms")
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", kmsKeyId)
|
||||
.body("kms-encrypted-content")
|
||||
.when()
|
||||
.put("/sse-bucket/kms-encrypted.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-server-side-encryption", equalTo("aws:kms"))
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", equalTo(kmsKeyId));
|
||||
|
||||
given()
|
||||
.contentType("text/plain")
|
||||
.header("x-amz-server-side-encryption", "AES256")
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", kmsKeyId)
|
||||
.body("aes-content")
|
||||
.when()
|
||||
.put("/sse-bucket/aes-with-kms-id.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-server-side-encryption", equalTo("AES256"))
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1592,6 +1617,23 @@ class S3IntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-server-side-encryption", equalTo("AES256"));
|
||||
|
||||
String kmsKeyId = "arn:aws:kms:us-east-1:000000000000:key/test-key";
|
||||
given()
|
||||
.when()
|
||||
.get("/sse-bucket/kms-encrypted.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-server-side-encryption", equalTo("aws:kms"))
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", equalTo(kmsKeyId));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/sse-bucket/aes-with-kms-id.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-server-side-encryption", equalTo("AES256"))
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1603,6 +1645,15 @@ class S3IntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-server-side-encryption", equalTo("AES256"));
|
||||
|
||||
String kmsKeyId = "arn:aws:kms:us-east-1:000000000000:key/test-key";
|
||||
given()
|
||||
.when()
|
||||
.head("/sse-bucket/kms-encrypted.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-server-side-encryption", equalTo("aws:kms"))
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", equalTo(kmsKeyId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1614,7 +1665,11 @@ class S3IntegrationTest {
|
||||
.put("/sse-bucket/encrypted-copy.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CopyObjectResult"));
|
||||
.body(containsString("CopyObjectResult"))
|
||||
// Asserted directly on the CopyObjectResult response itself, not
|
||||
// just via a follow-up HEAD — handleCopyObject previously never
|
||||
// emitted x-amz-server-side-encryption at all.
|
||||
.header("x-amz-server-side-encryption", equalTo("AES256"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
@@ -1622,6 +1677,25 @@ class S3IntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-server-side-encryption", equalTo("AES256"));
|
||||
|
||||
String kmsKeyId = "arn:aws:kms:us-east-1:000000000000:key/test-key";
|
||||
given()
|
||||
.header("x-amz-copy-source", "/sse-bucket/kms-encrypted.txt")
|
||||
.when()
|
||||
.put("/sse-bucket/kms-encrypted-copy.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CopyObjectResult"))
|
||||
.header("x-amz-server-side-encryption", equalTo("aws:kms"))
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", equalTo(kmsKeyId));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.head("/sse-bucket/kms-encrypted-copy.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-server-side-encryption", equalTo("aws:kms"))
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", equalTo(kmsKeyId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1855,6 +1929,9 @@ class S3IntegrationTest {
|
||||
void cleanupSseBucket() {
|
||||
given().delete("/sse-bucket/encrypted.txt");
|
||||
given().delete("/sse-bucket/encrypted-copy.txt");
|
||||
given().delete("/sse-bucket/aes-with-kms-id.txt");
|
||||
given().delete("/sse-bucket/kms-encrypted.txt");
|
||||
given().delete("/sse-bucket/kms-encrypted-copy.txt");
|
||||
given().delete("/sse-bucket/sse-c.txt");
|
||||
given().delete("/sse-bucket/sse-c-copy.txt");
|
||||
given().delete("/sse-bucket");
|
||||
|
||||
@@ -1156,6 +1156,113 @@ class S3MultipartIntegrationTest {
|
||||
.header("ETag", matchesPattern("\"[0-9a-f]{32}\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(35)
|
||||
void uploadPartCopyPreservesDestinationServerSideEncryption() {
|
||||
given()
|
||||
.body("KMS-SOURCE-DATA")
|
||||
.when()
|
||||
.put("/" + BUCKET + "/kms-source-for-copy.bin")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String kmsKeyId = "arn:aws:kms:us-east-1:000000000000:key/test-key";
|
||||
String copyUploadId = given()
|
||||
.header("x-amz-server-side-encryption", "aws:kms")
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", kmsKeyId)
|
||||
.when()
|
||||
.post("/" + BUCKET + "/kms-copy-dest.bin?uploads")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
|
||||
|
||||
// UploadPartCopy doesn't take x-amz-server-side-encryption headers
|
||||
// itself, a part always inherits the destination multipart upload's
|
||||
// own encryption settings, captured at CreateMultipartUpload above.
|
||||
// The CopyPartResult response must reflect those, not come back bare.
|
||||
given()
|
||||
.header("x-amz-copy-source", "/" + BUCKET + "/kms-source-for-copy.bin")
|
||||
.when()
|
||||
.put("/" + BUCKET + "/kms-copy-dest.bin?uploadId=" + copyUploadId + "&partNumber=1")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<CopyPartResult"))
|
||||
.header("x-amz-server-side-encryption", equalTo("aws:kms"))
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", equalTo(kmsKeyId));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + BUCKET + "/kms-copy-dest.bin?uploadId=" + copyUploadId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(36)
|
||||
void completeMultipartUploadPreservesSseKmsKeyId() {
|
||||
String key = "kms-multipart-complete.bin";
|
||||
String kmsKeyId = "arn:aws:kms:us-east-1:000000000000:key/complete-test-key";
|
||||
String completeUploadId = given()
|
||||
.header("x-amz-server-side-encryption", "aws:kms")
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", kmsKeyId)
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + key + "?uploads")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
|
||||
|
||||
String eTag = given()
|
||||
.body("KMS-COMPLETE-PART-DATA")
|
||||
.when()
|
||||
.put("/" + BUCKET + "/" + key + "?uploadId=" + completeUploadId + "&partNumber=1")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().header("ETag");
|
||||
|
||||
String completeXml = """
|
||||
<CompleteMultipartUpload>
|
||||
<Part><PartNumber>1</PartNumber><ETag>%s</ETag></Part>
|
||||
</CompleteMultipartUpload>""".formatted(eTag);
|
||||
|
||||
// The CompleteMultipartUpload response itself must reflect the upload's SSE-KMS
|
||||
// settings, captured at CreateMultipartUpload, not come back bare like the
|
||||
// CopyObject/UploadPartCopy responses did before this was fixed.
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.body(completeXml)
|
||||
.when()
|
||||
.post("/" + BUCKET + "/" + key + "?uploadId=" + completeUploadId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<CompleteMultipartUploadResult"))
|
||||
.header("x-amz-server-side-encryption", equalTo("aws:kms"))
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", equalTo(kmsKeyId));
|
||||
|
||||
// The completed object itself must carry the key id too, so a later GET/HEAD
|
||||
// (not just the completion response) reports it.
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "/" + key)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-server-side-encryption", equalTo("aws:kms"))
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", equalTo(kmsKeyId));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.head("/" + BUCKET + "/" + key)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-server-side-encryption", equalTo("aws:kms"))
|
||||
.header("x-amz-server-side-encryption-aws-kms-key-id", equalTo(kmsKeyId));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + BUCKET + "/" + key)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(40)
|
||||
void cleanUp() {
|
||||
@@ -1169,6 +1276,7 @@ class S3MultipartIntegrationTest {
|
||||
given().when().delete("/" + BUCKET + "/copy-dest.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/sse-c-multipart.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/sse-c-source-for-copy.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/kms-source-for-copy.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/checksum-match-multipart.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET + "/checksum-type-multipart.bin").then().statusCode(204);
|
||||
given().when().delete("/" + BUCKET).then().statusCode(204);
|
||||
|
||||
Reference in new issue
Block a user