Skip to content

fix(mcp): confirm a bucket's Object Lock state instead of matching error messages - #65

Merged
houseme merged 1 commit into
rustfs:mainfrom
zhi22915:fix/object-lock-unlocked-bucket-reads
Nov 27, 2026
Merged

houseme merged 1 commit into
rustfs:mainfrom
zhi22915:fix/object-lock-unlocked-bucket-reads

Conversation

@zhi22915

Copy link
Copy Markdown
Contributor

Follow-up to #60. Part of a series of three follow-ups to #60/#61/#62 (this PR, then the replication one, then the request payment one). The branches are stacked, so they merge cleanly in any order.

What was wrong in #60

#60 treated an InvalidRequest on an object-level lock read as "nothing applies" only when its message contained ObjectLockConfiguration. Checked against the backends' sources and documentation, that matched one of the answers that matter:

Backend Answer of GetObjectRetention / GetObjectLegalHold for a bucket with Object Lock disabled
AWS S3 400 InvalidRequest — Bucket is missing Object Lock Configuration
MinIO 400 InvalidRequest — Bucket is missing ObjectLockConfiguration
RustFS (rustfs/rustfs#9654) 400 InvalidRequest — Bucket is missing ObjectLockConfiguration, or Object Lock is not enabled for this bucket for a stored configuration that is not enabled
  • The AWS S3 wording was never matched, and neither was RustFS's second one, so the read still failed there.
  • MinIO answers a missing bucket with the same InvalidRequest, before it looks the object up, so a read of an object in a bucket that does not exist was reported as "no retention".
  • The docs of fix(mcp): align object lock reads with S3-standard error codes #60 claimed AWS S3 and MinIO answer NoSuchObjectLockConfiguration for the bucket-level read. They answer ObjectLockConfigurationNotFoundError, the code v0.9.0 already handled.

What changes

  • Decide by error code, confirm with the bucket. On InvalidRequest the reads now fetch the bucket's Object Lock configuration, and only a bucket confirmed to have Object Lock disabled turns the refusal into "nothing applies". A bucket that has Object Lock leaves the refusal an error, and so does one whose configuration cannot be read — with the failed read as part of the message. No message text is matched any more.
  • The note says why nothing applies. get_object_retention and get_object_legal_hold report whether the version or the bucket is the reason, so a model knows that put_object_retention cannot help before it tries.
  • get_bucket_lock_configuration keeps accepting NoSuchObjectLockConfiguration as a second spelling, and the README and CHANGELOG no longer claim it is what AWS S3 and MinIO answer.

Test harness

The data layer had no test that went through the SDK's error parsing — which is how the wrong codes and wordings went unnoticed. This PR adds an in-process S3 endpoint for tests (src/s3_client/fake_s3.rs, std::net only, no new dependency): it answers scripted responses and records what the client sent. The lock reads now run against it with the answers of the three backends.

With the #60 logic put back in place temporarily, the matrix fails for exactly the three cases above:

test_retention_read_reports_a_bucket_without_object_lock_for_every_wording ... FAILED
  Err: Failed to get the retention of s3://plain/aws
test_legal_hold_read_reports_what_each_backend_answers ... FAILED
  Err: Failed to get the legal hold of s3://plain/aws
test_retention_read_of_a_missing_bucket_stays_an_error ... FAILED
  unwrap_err() on Ok: ObjectRetentionInfo { bucket: "absent", retention: None, unset_reason: Some(BucketNotEnabled) }

Verification

  • cargo fmt --all -- --check, cargo clippy --all-targets --locked -- -D warnings (default and --features io-uring), cargo test --locked --all-targets — 295 passed
  • The full suite was run 30 times in a row without a failure (the endpoint uses real sockets and threads)

…ror messages

The object lock reads treated an InvalidRequest as "nothing applies"
only when its message contained "ObjectLockConfiguration". Checked
against the backends' sources, that matched one of the answers that
matter:

- AWS S3 words the refusal of a bucket without Object Lock "Bucket is
  missing Object Lock Configuration", which the check never matched
- RustFS answers two InvalidRequest messages for two bucket states
  (rustfs/rustfs#9654); "Object Lock is not enabled for this bucket"
  was not matched either
- MinIO answers a missing bucket with the same InvalidRequest it uses
  for a bucket without Object Lock, so a read of an object in a bucket
  that does not exist was reported as "no retention"

- Decide by error code and confirm with the bucket: on InvalidRequest
  the reads now get the bucket's Object Lock configuration, and only a
  bucket confirmed to have Object Lock disabled turns the refusal into
  "nothing applies". A bucket that has Object Lock leaves the refusal
  an error, and so does one whose configuration cannot be read - with
  the failed read as part of the message
- get_object_retention and get_object_legal_hold report why nothing
  applies, version or bucket, and their note says so: a model then
  knows that put_object_retention cannot help before it tries
- get_bucket_lock_configuration: AWS S3, MinIO, and RustFS all answer
  ObjectLockConfigurationNotFoundError for a bucket without Object
  Lock; NoSuchObjectLockConfiguration is kept as a second accepted
  spelling only, and the README and CHANGELOG no longer claim it is
  what AWS S3 and MinIO answer
- An in-process S3 endpoint (std::net, tests only) scripts the answers
  of the three backends, so the lock reads run through the real SDK
  error parsing. Its matrix fails on the previous logic for exactly the
  three cases above
@houseme
houseme merged commit 40059ae into rustfs:main Nov 27, 2026
6 checks passed
zhi22915 added a commit to zhi22915/mcp that referenced this pull request Nov 27, 2026
- Bump crate version to 0.9.1
- Set the release date of the 0.9.1 changelog section, which the
  feature PRs (rustfs#60-rustfs#63, rustfs#65-rustfs#67) assemble and keep current
houseme pushed a commit that referenced this pull request Nov 27, 2026
- Bump crate version to 0.9.1
- Set the release date of the 0.9.1 changelog section, which the
  feature PRs (#60-#63, #65-#67) assemble and keep current
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.

2 participants