Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s3: fix S3 Object Lock header issue for lock file writes #36120

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

bschaatsbergen
Copy link
Member

@bschaatsbergen bschaatsbergen commented Nov 27, 2024

Fixes #36113

When S3 Object Lock is enabled on a bucket with a retention period, Amazon S3 requires the Content-MD5 or x-amz-sdk-checksum-algorithm header to be present in object uploads (PutObject). See Uploading objects to an Object Lock enabled bucket.

It seems we overlooked maintaining the default behavior of the skip_checksum flag for the lock file when writing to S3 Object Lock-enabled buckets.

To clarify the default behavior of skip_checksum: by default, if this argument is not set in the backend, we set the S3 checksum algorithm behavior to SHA256. This causes the underlying S3 AWS SDK V2 serializers to automatically append that required x-amz-sdk-checksum-algorithm header. For more details, see the relevant code in the AWS SDK v2 serializers.

This PR updates the lock file implementation to use the same "uploader" that we rely on for writing Terraform state to S3, and preserving the default skip_checksum behavior for the lock file. To ensure a consistent and compatible experience with S3 Object Lock-enabled buckets between the two mechanisms writing data to S3.

$  go test -v
...
PASS
ok      github.com/hashicorp/terraform/internal/backend/remote-state/s3 445.979s

When S3 Object Lock is enabled on a bucket with a retention period, S3 requires the Content-MD5 or x-amz-sdk-checksum-algorithm header for object uploads (via PutObject) to ensure data integrity during the upload process.

Terraform’s state writes to the S3 bucket relied on the “uploader” from aws-sdk-go-v2, which automatically appends these required headers. However, the lock file implementation did not use the “uploader,” resulting in missing headers for PutObject requests and conflicts with Object Lock requirements.

This commit updates the lock file implementation to use the “uploader,” ensuring the necessary headers are included in the requests, maintaining compatibility with Object Lock-enabled buckets.
@bschaatsbergen bschaatsbergen marked this pull request as ready for review November 27, 2024 17:24
@bschaatsbergen bschaatsbergen requested review from a team as code owners November 27, 2024 17:24
@bschaatsbergen bschaatsbergen added the 1.10-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Nov 27, 2024
@bschaatsbergen bschaatsbergen changed the title s3: fix S3 Object Lock header issue by using s3manager for lock file writes s3: fix S3 Object Lock header issue for lock file writes Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.10-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged backend/s3 bug
Projects
None yet
1 participant