Skip to content

Commit

Permalink
confluentinc#770 - Add x-amz-server-side-encryption header for SSE/AE…
Browse files Browse the repository at this point in the history
…S256 without customer key
  • Loading branch information
85danf committed Aug 8, 2024
1 parent eaa37cc commit 5435ad8
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.CompleteMultipartUploadRequest;
import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PartETag;
import com.amazonaws.services.s3.model.SSEAlgorithm;
import com.amazonaws.services.s3.model.SSEAwsKeyManagementParams;
Expand Down Expand Up @@ -205,14 +206,26 @@ private void internalClose() throws IOException {
super.close();
}

private ObjectMetadata newObjectMetadata() {
ObjectMetadata meta = new ObjectMetadata();
if (StringUtils.isNotBlank(ssea)) {
meta.setSSEAlgorithm(ssea);
}
return meta;
}

private MultipartUpload newMultipartUpload() throws IOException {
InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(
bucket,
key
).withCannedACL(cannedAcl);

if (SSEAlgorithm.KMS.toString().equalsIgnoreCase(ssea)
&& StringUtils.isNotBlank(sseKmsKeyId)) {
if (SSEAlgorithm.AES256.toString().equalsIgnoreCase(ssea)
&& sseCustomerKey == null) {
log.debug("Using SSE (AES256) without customer key");
initRequest.setObjectMetadata(newObjectMetadata());
} else if (SSEAlgorithm.KMS.toString().equalsIgnoreCase(ssea)
&& StringUtils.isNotBlank(sseKmsKeyId)) {
log.debug("Using KMS Key ID: {}", sseKmsKeyId);
initRequest.setSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(sseKmsKeyId));
} else if (sseCustomerKey != null) {
Expand Down

0 comments on commit 5435ad8

Please sign in to comment.