Skip to content

fix: compute Content-MD5 for all S3 write paths on Object Lock buckets - #19

Open
swatiganesh wants to merge 5 commits into
automate_miniofrom
fix/complete-multipart-upload-object-lock-md5
Open

fix: compute Content-MD5 for all S3 write paths on Object Lock buckets#19
swatiganesh wants to merge 5 commits into
automate_miniofrom
fix/complete-multipart-upload-object-lock-md5

Conversation

@swatiganesh

@swatiganesh swatiganesh commented Aug 25, 2026

Copy link
Copy Markdown

Problem

Chef Automate backups fail when the target S3 bucket has Object Lock enabled.

AWS S3 Object Lock buckets require a Content-MD5 header on every write. OpenSearch uses the AWS Java SDK with streaming SigV4, which never sends Content-MD5. The gateway was forwarding these requests to AWS as-is, causing AWS to reject them.

Three write paths were all affected:

  • PutObjectCore.PutObject ignores SendContentMd5: true; when MD5 is missing the gateway was forwarding an empty value to AWS
  • PutObjectPart — same issue for each part of a multipart upload
  • CompleteMultipartUpload — was called with empty PutObjectOptions{}

The 2021 fix (50a68a1) only patched the surface of PutObject but none of these three paths were actually sending Content-MD5 to AWS.

Fix

  • PutObject + PutObjectPart: When MD5Base64String() returns "" (streaming SigV4), buffer the body/part and compute MD5 ourselves before forwarding to AWS.
  • CompleteMultipartUpload: Pass PutObjectOptions{SendContentMd5: true}.

Testing

Verified on EC2 against a real AWS S3 Object Lock (COMPLIANCE) bucket (ap-south-1):

  • chef-automate backup create completes successfully for all services
  • 140MB compliance DB file uploaded as 27 multipart parts — confirming all three code paths exercised
  • Manual multipart test (upload-part × 2 → complete-multipart-upload) succeeded on Object Lock bucket

Related

Fixes: CHEF-37621


without this changes backup was not getting created for S3 bucket with Object Lock enabled-

image image image image

with this changes backup is getting created for S3 bucket with Object Lock enabled

image image image image

…pport

In the 2021 fix, SendContentMd5 was added to PutObject to support
Object Lock enabled S3 buckets. However, CompleteMultipartUpload was
passing an empty PutObjectOptions{} struct, so no Content-MD5 header
was sent to AWS. AWS requires this header for Object Lock buckets and
rejects the request without it, causing backups to fail for large
objects that go through multipart upload.

Fix: pass PutObjectOptions{SendContentMd5: true} in CompleteMultipartUpload,
identical to how PutObject already handles it.

Fixes: CHEF-37621
Signed-off-by: swatign <SwatiGanesh.Naik@Progress.com>
…r Object Lock buckets

Core.PutObject bypasses SendContentMd5:true and passes md5Base64 directly.
When OpenSearch sends PUT requests via streaming SigV4 (no Content-MD5 header),
md5Base64 is empty and AWS rejects with 400 InvalidRequest.

Using Client.Client.PutObject (high-level API) ensures the SDK buffers
the data and computes MD5 itself when SendContentMd5:true is set.

Signed-off-by: swatign <SwatiGanesh.Naik@Progress.com>
…ckets

When callers use streaming SigV4 chunked transfer (e.g. OpenSearch Java SDK),
no Content-MD5 header is sent so MD5Base64String() returns empty string.
AWS S3 requires Content-MD5 on Object Lock buckets (400 InvalidRequest).

Buffer the body and compute MD5 ourselves when missing, pass it explicitly
to Core.PutObject. Keeps Core API (no validate() side-effects on UserMetadata)
while ensuring Content-MD5 is always present for Object Lock buckets.

Signed-off-by: swatign <SwatiGanesh.Naik@Progress.com>
@swatiganesh swatiganesh self-assigned this Aug 27, 2026
AWS S3 requires Content-MD5 on every UploadPart request for Object Lock
buckets. When the caller uses streaming SigV4 (no Content-MD5 header),
MD5Base64String() returns empty. Buffer the part and compute MD5 ourselves
when missing, same pattern as the PutObject fix.

Signed-off-by: swatign <SwatiGanesh.Naik@Progress.com>
Signed-off-by: swatign <SwatiGanesh.Naik@Progress.com>
@swatiganesh swatiganesh changed the title fix: add SendContentMd5 to CompleteMultipartUpload for Object Lock support fix: compute Content-MD5 for all S3 write paths on Object Lock buckets Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant