Implement DELETE precondition checks for If-Match header#12
Open
magicxor wants to merge 1 commit intopgsty:masterfrom
Open
Implement DELETE precondition checks for If-Match header#12magicxor wants to merge 1 commit intopgsty:masterfrom
magicxor wants to merge 1 commit intopgsty:masterfrom
Conversation
AWS S3 supports the If-Match conditional header on DeleteObject, but MinIO silently ignored it — the object was deleted regardless of ETag mismatch. Add precondition checks following the same two-tier pattern used by PutObject/GetObject: handler sets CheckPrecondFn, erasure layer evaluates it atomically after fetching fresh ObjectInfo. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Community Contribution License
All community contributions in this pull request are licensed to the project maintainers
under the terms of the Apache 2 license.
By creating this pull request I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 license.
Description
Add support for the
If-Matchconditional header on theDeleteObjectAPI operation, as specified by AWS S3. (fixes #10)When
If-Matchis provided, the object is deleted only if its ETag matches the specified value; otherwise a412 Precondition Failedresponse is returned. WhenIf-Matchis specified and the object does not exist, a404 NoSuchKeyerror is returned instead of the usual204 No Content.This follows the same two-tier precondition check pattern already used by
PutObjectandGetObject:DeleteObjectHandler) — reads theIf-Matchheader, setsopts.CheckPrecondFnclosure andopts.HasIfMatchflag.erasureObjects.DeleteObject) — evaluatesCheckPrecondFnatomically after fetching the latestObjectInfoviagetObjectInfoAndQuorum, before proceeding with the actual deletion. Non-NotFound errors (e.g.InsufficientReadQuorum) are propagated to prevent unverified deletes.Source changes across 4 files:
cmd/object-handlers-common.go— newcheckPreconditionsDELETE()function that checksIf-Matchfor DELETE requests.cmd/object-handlers.go—DeleteObjectHandlernow parses theIf-Matchheader and sets the precondition function. Error handling updated:PreConditionFailedreturns early;If-Matchon a non-existent object returnsNoSuchKeyerror instead of204 No Content.cmd/erasure-object.go—DeleteObjectevaluatesCheckPrecondFnaftergetObjectInfoAndQuorumand beforeEvalMetadataFn, with proper quorum-error propagation.cmd/object-api-interface.go— updatedCheckPrecondFnfield comment to be generic.Test changes across 3 files:
cmd/object-handlers-common_test.go—TestCheckPreconditionsDELETE: 6 unit test cases for the precondition function (non-DELETE ignored, matching/non-matching/wildcard/quoted ETags, no headers).cmd/erasure-object-conditional_test.go—TestDeleteObjectConditional: 3 erasure-layer integration tests (wrong ETag → fail, correct ETag → succeed, missing object → error).TestDeleteObjectConditionalWithReadQuorumFailure: 1 test verifying that conditional delete is blocked when read quorum is lost.cmd/object-handlers_test.go— 2 handler-level tests added toTestAPIDeleteObjectHandler(wrongIf-Match→ 412 and object remains;If-Matchon missing key → 404NoSuchKey).Motivation and Context
AWS S3 supports the
If-Matchconditional header onDeleteObjectoperations, returning412 Precondition Failedwhen the condition is not met. This enables safe concurrent delete workflows where callers can ensure they only delete a specific known version of an object (by ETag), preventing accidental deletion of an object that was updated between a read and a delete.MinIO already supports conditional headers for
GetObject,HeadObject,PutObject,CopyObject, and multipart operations — butDeleteObjectwas missingIf-Matchsupport entirely. There were no checks, no TODOs, and no code paths for conditional headers in the delete flow.How to test this PR?
Reproduce the bug (before the fix)
DeleteObjectrequest withIf-Match: "wrong-etag"(an ETag that does not match the object).204 No Contentinstead of being rejected with412 Precondition Failed.Minimal reproduction using .NET 10 + AWS SDK (save as
test-ifmatch.cs, run withdotnet run --file test-ifmatch.cs):Before fix:
BUG: object deleted even though ETag does not match!After fix:
OK: 412 Precondition Failed (expected behavior)Unit tests
Types of changes
Checklist:
commit-idorPR #here)