Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

DEVOPS-15838: add checksum header for S3 storage #2

Open
wants to merge 1 commit into
base: CE-14395_v5.2.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/paperclip/storage/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ def flush_writes #:nodoc:
write_options[:metadata] = @s3_metadata unless @s3_metadata.empty?
write_options.merge!(@s3_headers)

sha256_checksum = Digest::SHA256.hexdigest(File.read(file.path))
encoded_sha256_checksum = Base64.encode64([sha256_checksum].pack("H*")).strip
write_options[:checksum_sha256] = encoded_sha256_checksum # Required for FIPS (SHA256) and object locking (checksum)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charchitarora isn't this already added by the aws-sdk-s3, is that what you meant by this is already being done

Copy link

@charchitarora charchitarora Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abdulchaudhrycoupa - I was referring to - https://github.com/coupa-ops/paperclip/blob/CE-14395_v5.2.0/lib/paperclip/attachment.rb#L36 - is already there. We need not add this to paperclip initializer.


s3_object(style).upload_file(file.path, write_options)
rescue ::Aws::S3::Errors::NoSuchBucket
create_bucket
Expand Down