Izeren commented on code in PR #27187:
URL: https://github.com/apache/flink/pull/27187#discussion_r2783130295


##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/writer/NativeS3AccessHelper.java:
##########
@@ -0,0 +1,415 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.fs.s3native.writer;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.fs.s3native.S3EncryptionConfig;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.core.sync.RequestBody;
+import software.amazon.awssdk.core.sync.ResponseTransformer;
+import software.amazon.awssdk.services.s3.S3AsyncClient;
+import software.amazon.awssdk.services.s3.S3Client;
+import software.amazon.awssdk.services.s3.model.AbortMultipartUploadRequest;
+import software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest;
+import 
software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse;
+import software.amazon.awssdk.services.s3.model.CompletedMultipartUpload;
+import software.amazon.awssdk.services.s3.model.CompletedPart;
+import software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest;
+import software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse;
+import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
+import software.amazon.awssdk.services.s3.model.GetObjectRequest;
+import software.amazon.awssdk.services.s3.model.GetObjectResponse;
+import software.amazon.awssdk.services.s3.model.HeadObjectRequest;
+import software.amazon.awssdk.services.s3.model.HeadObjectResponse;
+import software.amazon.awssdk.services.s3.model.NoSuchUploadException;
+import software.amazon.awssdk.services.s3.model.PutObjectRequest;
+import software.amazon.awssdk.services.s3.model.PutObjectResponse;
+import software.amazon.awssdk.services.s3.model.S3Exception;
+import software.amazon.awssdk.services.s3.model.UploadPartRequest;
+import software.amazon.awssdk.services.s3.model.UploadPartResponse;
+import software.amazon.awssdk.transfer.s3.S3TransferManager;
+import software.amazon.awssdk.transfer.s3.model.CompletedFileUpload;
+import software.amazon.awssdk.transfer.s3.model.FileUpload;
+import software.amazon.awssdk.transfer.s3.model.UploadFileRequest;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+
+@Internal
+public class NativeS3AccessHelper {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(NativeS3AccessHelper.class);
+
+    private final S3Client s3Client;
+    private final S3AsyncClient s3AsyncClient;
+    private final S3TransferManager transferManager;
+    private final String bucketName;
+    private final boolean useAsyncOperations;
+    private final S3EncryptionConfig encryptionConfig;
+
+    public NativeS3AccessHelper(S3Client s3Client, String bucketName) {
+        this(s3Client, null, null, bucketName, false, null);
+    }
+
+    public NativeS3AccessHelper(
+            S3Client s3Client,
+            S3AsyncClient s3AsyncClient,
+            S3TransferManager transferManager,
+            String bucketName,
+            boolean useAsyncOperations) {
+        this(s3Client, s3AsyncClient, transferManager, bucketName, 
useAsyncOperations, null);
+    }
+
+    public NativeS3AccessHelper(
+            S3Client s3Client,
+            S3AsyncClient s3AsyncClient,
+            S3TransferManager transferManager,
+            String bucketName,
+            boolean useAsyncOperations,
+            S3EncryptionConfig encryptionConfig) {
+        this.s3Client = s3Client;
+        this.s3AsyncClient = s3AsyncClient;
+        this.transferManager = transferManager;
+        this.bucketName = bucketName;
+        this.useAsyncOperations = useAsyncOperations && transferManager != 
null;
+        this.encryptionConfig =
+                encryptionConfig != null ? encryptionConfig : 
S3EncryptionConfig.none();
+    }
+
+    public String startMultiPartUpload(String key) throws IOException {
+        try {
+            CreateMultipartUploadRequest.Builder requestBuilder =
+                    
CreateMultipartUploadRequest.builder().bucket(bucketName).key(key);
+            applyEncryption(requestBuilder);

Review Comment:
   I was experimenting with encryption in my Azure PoC and I think it is not 
that simple for anything outside SSE-KMS. 
   For example SSE-C with KeyProvider would require you to know key version to 
request correct key and inject corresponding header. In this case naive 
approach with doing `applyEncryption` pass would only work if flink already 
hardcodes the key version in the file path itself, which will be not 
straightforward (especially for _metadata file). Otherwise, it would require 
storing key metadata as part of file metadata which would require additional 
SDK call, which won't be modelled in `applyEncryption`. 
   
   For Client Side encryption approach may need to be somewhat different as 
encryption/decryption would probably best added to the stream. 
   
   Given the 2, I think that it is fine to only provide SSE-KMS in initial PoC 
as it is. I will think through best ways to support other encryption modes in 
the meantime. 
   
   Will mark this thread as resolved



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to