Skip to content

rgw: a conditional delete that finds no object is answered 404 - #72115

Open
mmgaggle wants to merge 2 commits into
ceph:mainfrom
mmgaggle:wip-rgw-cond-delete-nokey
Open

mmgaggle wants to merge 2 commits into
ceph:mainfrom
mmgaggle:wip-rgw-cond-delete-nokey

Conversation

@mmgaggle

@mmgaggle mmgaggle commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

A DeleteObject with If-Match that finds no object is answered 204 No Content: delete_obj returns -ENOENT before it checks the condition, RGWDeleteObj_ObjStore_S3::send_response answers -ENOENT as success, and a removal that finds the head already gone ends in complete_del, whose return replaces the -ENOENT. For general purpose buckets S3 answers such a delete 404 Not Found, including one that a concurrent delete beat (S3 User Guide, "How to perform conditional deletes"). With If-Match used to release a lease, two clients releasing the same lease are both told they released it.

This answers the -ENOENT of a delete that carries If-Match as 404 NoSuchKey, on both paths, and in a versioned bucket, where check_preconditions returns -ENOENT when there is no current version. A delete without If-Match still succeeds for a missing object, and so does one with only x-amz-if-match-size or x-amz-if-match-last-modified-time, which S3 documents as 204. DeleteObjects reports a key whose ETag condition finds no object as a NoSuchKey error.

s3-tests' test_delete_object_if_match, test_delete_object_current_if_match and test_delete_object_version_if_match assert the 204; ceph/s3-tests#764 updates them.

The P model of RGW overwrites (#72110) checks this answer (S3Answers, finding 15).

Fixes: https://tracker.ceph.com/issues/80922

Validated on a single-host vstart cluster: test_delete_object_if_match_no_object (ceph/s3-tests#763) fails on main and passes with this change; with the companion s3-tests change all 12 conditional-delete tests pass, and test_s3.py as the rgw suite runs it shows no other new failures.

Versioned buckets

In a versioned or suspended bucket whose current version is a delete marker, the conditions were checked against the olh's own head: If-Match: * passed, and a second delete marker was linked. S3 answers 412 Precondition Failed for a delete marker, If-Match: * included. A new commit answers any delete condition 412 there. DeleteObjects takes the same path.

s3-tests test_delete_object_if_match_delete_marker and _suspended fail without the new commit and pass with it. test_delete_object_current_if_match must expect 412 on the delete marker, and remove the delete marker rather than the version before it retests If-Match: *; ceph/s3-tests#764 needs that change too.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)

A DeleteObject with If-Match that finds no object is answered 204 No
Content, on two paths:

- delete_obj returns -ENOENT for a key with no object before it checks
  any condition, and RGWDeleteObj_ObjStore_S3::send_response answers
  -ENOENT as success. In a versioned bucket, check_preconditions returns
  -ENOENT when there is no current version, with the same answer.
- A removal that finds the head already gone, removed by a racing
  delete, ends in complete_del, whose return replaces the -ENOENT.

S3 answers a conditional delete that finds no object 404 Not Found,
including one that a concurrent delete beat (S3 User Guide, "How to
perform conditional deletes"). With If-Match used to release a lease,
two clients releasing the same lease are both told they released it.

Answer -ENOENT as 404 NoSuchKey when the delete carries If-Match, and
return -ENOENT from delete_obj when a conditional delete's removal found
no head. A delete without If-Match still succeeds for a missing object,
and so does one with only the directory-bucket conditions,
x-amz-if-match-size and x-amz-if-match-last-modified-time, which S3
documents as 204. DeleteObjects reports a key whose ETag condition finds
no object as a NoSuchKey error, and deletes any other missing key as
before.

s3-tests' test_delete_object_if_match and
test_delete_object_current_if_match assert the 204; they date from when
S3 offered conditional deletes only for directory buckets.

Fixes: https://tracker.ceph.com/issues/80922
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Kyle Bader <[email protected]>
In a versioned bucket a DeleteObject without a version id checks its
conditions against the key's current version. When that is a delete
marker, the olh has no current version, and the conditions were checked
against the olh's own head instead: If-Match: * passed, and a second
delete marker was linked over the first. S3 answers 412 Precondition
Failed for a delete marker, If-Match: * included. Refuse any condition
there, as DeleteObjects does through the same path.

This applies to a bucket whose versioning is suspended as well, whose
delete of a key with an olh links a null delete marker.

Tested on vstart, with versioning enabled and suspended: DeleteObject
and DeleteObjects with If-Match: *, the old ETag, or another ETag, when
the current version is a delete marker. Without this change If-Match: *
is answered 204 and adds a delete marker; with it each is answered 412
and no delete marker is added. s3-tests'
test_delete_object_current_if_match expects the old answer.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Kyle Bader <[email protected]>

// a conditional delete that removed nothing found no object to delete,
// like one that found no head to begin with
if (r >= 0 && removed_nothing && params.if_match) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete_obj()'s return value r after this point is the index_op.complete_del()'s, not the head delete. if complete_del() returns -ENOENT for whatever reason, this check and the checks in RGWDeleteObj_ObjStore_S3::send_response() are skipped. so even a successful head removal gets reported as 404.

the current behaviour is to just return success for an -ENOENT https://github.com/ceph/ceph/blob/main/src/rgw/rgw_rest_s3.cc#L3905. how about we just move that up here just before this check so that complete_del()'s -ENOENT still gets ignored?

if (r == -ENOENT) {
  r = 0;
} else if (r >= 0 && removed_nothing && params.if_match) {
  r = -ENOENT;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants