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

Incorrect header check when uploading an object with a retention configured using object lock #8662

Open
Frank-Schmutz opened this issue Mar 7, 2025 · 0 comments
Labels

Comments

@Frank-Schmutz
Copy link

Frank-Schmutz commented Mar 7, 2025

Hi ;)

The current version of moto requires the Content-Md5 header to be provided when uploading an object with a retention configured using object lock. However the AWS documentation specifies that the x-amz-sdk-checksum-algorithm header may be provided instead (AWS doc reference). I can confirm that the documentation is accurate after having performed a couple tests including the latter header instead of the content md5 one.
This issue is relevant since botocore does not compute and include the content md5 automatically since version 1.36.0, see changelog.

To fix this issue only a couple changes are required:
First in moto/s3/exceptions.py, the InvalidContentMD5 exception can be replaced by a new more descriptive one like:

class MissingUploadObjectWithObjectLockHeaders(S3ClientError):
    code = 400

    def __init__(self) -> None:
        super().__init__("MissingUploadObjectWithObjectLockHeaders", "Content-MD5 or x-amz-sdk-checksum-algorithm header required to upload an object with a retention period configured using Object Lock")

And in moto/s3/responses.py, in the _key_response_put method, the block that checks the headers can be updated to:

if lock_mode or lock_until or legal_hold == "ON":
    if not self.headers.get("Content-Md5") and not self.headers.get("x-amz-sdk-checksum-algorithm"):
        raise MissingUploadObjectWithObjectLockHeaders
    if not lock_enabled:
        raise LockNotEnabled

elif lock_enabled and bucket.has_default_lock:
    if not self.headers.get("Content-Md5") and not self.headers.get("x-amz-sdk-checksum-algorithm"):
        raise MissingUploadObjectWithObjectLockHeaders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants