TransferManager losing encryption related metadata when writing with AmazonS3Encryption #2311
Labels
closed-for-staleness
guidance
Question that needs advice or information.
response-requested
Waiting on additional info or feedback. Will move to "closing-soon" in 5 days.
We need to transfer some large files to S3 and encrypt them during transfer with client-side encryption (can't use KMS for this case, which spans accounts, have a specific requirement to use client-side encryption). I'd like to use AWS
TransferManager
to take advantage of the multi-part uploads and other functionality.The
AmazonS3Encryption
client will write two meta-data fieldsx-amz-iv
(initialization vector) andx-amz-key
(content key) to the S3 location, and these two fields are needed to decrypt the file.However, the
TransferManager
loses these metadata values and does not write them to the location. I am trying to see if there is some way that I can get to them and either cause them to be written or add them to the location after the transfer is complete.I found this old issue which seems to be very closely related, it is pretty old and I think the API's have changed since then, and the suggested workarounds don't work for me because I cannot find a way to get the metadata fields from the s3 client.
#367
My understanding is that the content key is encrypted for each s3 client and the IV is provided for each file, so I would need to get to the client immediately after it has written each file.
Per the AWS docs I an creating an AmazonS3Encryption like this:
And then building the TransferManager like this:
I have tried
transferManager.upload()
and also the variants such asuploadFileList()
which allows me to provideObjectMetadataProvider
but I cannot find a way to get the metadata to write.I have found what I think is the smoking gun, the
UploadCallable
class in AWS:https://github.com/aws/aws-sdk-java/blob/ccfd63c097874e3a1e9ffda7bf171769b6bd3b21/aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/transfer/internal/UploadCallable.java#L131
The
PutObjectResult
returned froms3
contains the metadata I need, but unfortunately it is just ignored and a different result is returned.I have been digging around through the code to try to find a hook to do this without resorting to awful Java Reflection hacks. So far I have tried:
AmazonS3EncryptionClient
, which can't be done easily because its builder class is public final (could maybe use the deprecated constructors)UploadCallable
toTransferManager
, can't find any hook for thatAmazonS3EncryptionClient
instance's internal crypto classes which hold the values that I need, but they are all private and buried several levels deepetc.
At this juncture I think my only option is to either roll my own
TransferManager
or just live with a direct s3 client, but this seems like a pretty significant shortcoming in the AWS client so I am wondering if I am missing something. Thanks for any help.Your Environment
The text was updated successfully, but these errors were encountered: