Project

General

Profile

Actions

Bug #82248

open
JZ JZ

rgw/s3: POST object ignores object lock form fields on lock-enabled buckets

Bug #82248: rgw/s3: POST object ignores object lock form fields on lock-enabled buckets

Added by Jane Zhu about 1 month ago. Updated 30 days ago.

Status:
Fix Under Review
Priority:
High
Assignee:
Target version:
-
Due date:
% Done:

0%

Source:
Backport:
tentacle, umbrella
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:
Tags (freeform):
Merge Commit:
Fixed In:
Released In:
Upkeep Timestamp:

Description

On a bucket with object lock enabled, POST object (browser-based upload) ignores the x-amz-object-lock-mode, x-amz-object-lock-retain-until-date and x-amz-object-lock-legal-hold form fields. The object is stored with only the bucket's default retention, or with no protection at all if the bucket has no default, and the request still returns 204. A client that asks for a retention period or a legal hold gets an object with no or wrong protection silently.

AWS does not document object lock fields for POST object. However, RGW accepts the same values as headers on PutObject, CopyObject and CreateMultipartUpload, so silently dropping them on POST is inconsistent and unsafe for WORM use.

Proposed behavior:
  • bucket with object lock: validate the fields the same way as PutObject (mode and retain-until date together, GOVERNANCE/COMPLIANCE, a future date, ON/OFF), store them on the object, and let an explicit retention override the bucket default. Invalid values are rejected with 400 InvalidArgument;
  • bucket without object lock: keep ignoring the fields, as for any other form field that POST object doesn't define.

A related issue on CopyObject can be fixed along with the above:
PutObject and CreateMultipartUpload reject object lock headers with 400 InvalidRequest ("Bucket is missing Object Lock Configuration") when the bucket doesn't have object lock enabled. CopyObject has no such check: the copy succeeds and the headers are silently ignored, so the client believes the copy is protected.

Steps to reproduce

  1. Start a cluster:
    $ MON=1 OSD=1 MDS=0 MGR=1 RGW=1 ../src/vstart.sh -n -d --rgw_port 8000
    
  2. Client environment (vstart's default user):
    $ export AWS_ACCESS_KEY_ID=0555b35654ad1656d804
    $ export AWS_SECRET_ACCESS_KEY='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=='
    $ export ENDPOINT=http://localhost:8000
    
  3. post_obj.py sends a signed POST upload. The POST policy has an exact-match condition for every form field:
    #!/usr/bin/env python3
    import sys, os, json, base64, hmac, hashlib, datetime, requests
    
    bucket, key, *kv = sys.argv[1:]
    fields = dict(f.split('=', 1) for f in kv)
    exp = (datetime.datetime.utcnow() + datetime.timedelta(hours=1)).strftime("%Y-%m-%dT%H:%M:%SZ")
    conds = [{"bucket": bucket}, {"key": key}] + [{k: v} for k, v in fields.items()]
    policy = base64.b64encode(json.dumps({"expiration": exp, "conditions": conds}).encode())
    sig = base64.b64encode(hmac.new(os.environ["AWS_SECRET_ACCESS_KEY"].encode(), policy, hashlib.sha1).digest())
    
    form = {"key": key, "AWSAccessKeyId": os.environ["AWS_ACCESS_KEY_ID"], "policy": policy, "signature": sig}
    form.update(fields)
    form["file"] = "hello" 
    
    r = requests.post(f"http://localhost:8000/{bucket}", files=form)
    print(r.status_code, r.text.strip()[:300])
    
  4. Create buckets:
    $ echo test > /tmp/test.txt
    $ aws --endpoint-url $ENDPOINT s3api create-bucket --bucket pl-lock --object-lock-enabled-for-bucket
    $ aws --endpoint-url $ENDPOINT s3api create-bucket --bucket pl-dflt --object-lock-enabled-for-bucket
    $ aws --endpoint-url $ENDPOINT s3api put-object-lock-configuration --bucket pl-dflt \
          --object-lock-configuration '{"ObjectLockEnabled":"Enabled","Rule":{"DefaultRetention":{"Mode":"GOVERNANCE","Days":1}}}'
    
  5. Test cases:
    • Retention and legal hold are ignored:
      $ python3 ./post_obj.py pl-lock f1 x-amz-object-lock-mode=GOVERNANCE \
          x-amz-object-lock-retain-until-date=2140-01-01T00:00:00Z x-amz-object-lock-legal-hold=ON
      204
      $ aws --endpoint-url $ENDPOINT s3api head-object --bucket pl-lock --key f1
      {   
          "AcceptRanges": "bytes",
          "LastModified": "Tue, 27 Oct 2026 02:36:14 GMT",
          "ContentLength": 5,
          "ETag": "\"5d41402abc4b2a76b9719d911017c592\"",
          "VersionId": "HemE8F4bSbpV2Xi5PSmXbtZ1FXzFl1d",
          "ContentType": "binary/octet-stream",
          "Metadata": {}
      }
      

      Expected: ObjectLockMode GOVERNANCE, ObjectLockRetainUntilDate 2140-01-01, ObjectLockLegalHoldStatus ON. The same values sent as PutObject headers are applied.
    • An explicit retention doesn't override the bucket default:
      $ python3 ./post_obj.py pl-dflt f1 x-amz-object-lock-mode=GOVERNANCE \
          x-amz-object-lock-retain-until-date=2140-01-01T00:00:00Z
      204
      $ aws --endpoint-url $ENDPOINT s3api get-object-retention --bucket pl-dflt --key f1
      {   
          "Retention": {
              "Mode": "GOVERNANCE",
              "RetainUntilDate": "2026-10-28T02:46:36.953938965Z" 
          }   
      }
      

      Expected: RetainUntilDate 2140-01-01. The object got the bucket default(1 day), the same as a PutObject without lock headers
    • CopyObject with lock headers to a bucket that doesn't have object lock enabled
      $ aws --endpoint-url $ENDPOINT s3api create-bucket --bucket pl-plain
      $ aws --endpoint-url $ENDPOINT s3api put-object --bucket pl-plain --key src --body /tmp/test.txt
      $ aws --endpoint-url $ENDPOINT s3api put-object --bucket pl-plain --key p1 --body /tmp/test.txt \
          --object-lock-legal-hold-status ON
      An error occurred (InvalidRequest) when calling the PutObject operation: ...
      $ aws --endpoint-url $ENDPOINT s3api copy-object --bucket pl-plain --key c1 \
          --copy-source pl-plain/src --object-lock-legal-hold-status ON
      (succeeds)
      

JZ Updated by Jane Zhu about 1 month ago Actions #1

  • Status changed from New to Fix Under Review
  • Pull request ID set to 73214

CB Updated by Casey Bodley about 1 month ago Actions #2

  • Priority changed from Normal to High

JZ Updated by Jane Zhu 30 days ago Actions #3

  • Backport set to tentacle, umbrella
Actions

Also available in: PDF Atom