Repository navigation
Description
Expected Behavior
When a DeleteObject request includes an If-Match header with an ETag that does not match the current object's ETag, the server should return 412 Precondition Failed and the object should not be deleted.
This is the behavior specified by the S3 API and implemented by AWS S3.
Current Behavior
MinIO ignores the If-Match header on DeleteObject requests entirely. The object is deleted unconditionally with a 204 No Content response, regardless of the ETag value provided in If-Match.
Possible Solution
The DeleteObjectHandler in cmd/object-handlers.go does not read or evaluate the If-Match header. The existing precondition-checking functions (checkPreconditions, checkPreconditionsPUT) explicitly filter by HTTP method and exclude DELETE.
To fix this, MinIO would need to:
- Read the
If-Matchheader inDeleteObjectHandler(around line 2608, afterdelOpts()returns). - Set
opts.CheckPrecondFnwith a closure that compares the request ETag against the object's current ETag usingisETagEqual(). - Evaluate
CheckPrecondFnatomically in the erasureDeleteObjectpath (cmd/erasure-object.go) aftergetObjectInfoAndQuorum()— similar to howPutObjectdoes it atcmd/erasure-object.go:1261–1286. - Return
PreConditionFailed{}(HTTP 412) when the ETag does not match.
Steps to Reproduce
- Start MinIO server (e.g.
docker run -d -p 9000:9000 -e MINIO_ROOT_USER=minioadmin -e MINIO_ROOT_PASSWORD=minioadmin pgsty/minio:RELEASE.2026-03-14T12-00-00Z server /data) - Create a bucket and upload an object
- Send a
DeleteObjectrequest withIf-Match: "wrong-etag"(an ETag that does not match the object) - Observe that the object is deleted with
204 No Contentinstead of being rejected with412 Precondition Failed
Minimal reproduction using .NET 10 + AWS SDK (save as test-ifmatch.cs, run with dotnet run --file test-ifmatch.cs):
#!/usr/bin/env dotnet run
#:package AWSSDK.S3@4.*
using Amazon.S3;
using Amazon.S3.Model;
using Amazon.Runtime;
var config = new AmazonS3Config { ServiceURL = "http://localhost:9000", ForcePathStyle = true };
var s3 = new AmazonS3Client(new BasicAWSCredentials("minioadmin", "minioadmin"), config);
// Upload a test object
await s3.PutObjectAsync(new PutObjectRequest {
BucketName = "testbucket", Key = "test.txt", ContentBody = "hello"
});
var etag = (await s3.GetObjectMetadataAsync("testbucket", "test.txt")).ETag;
Console.WriteLine($"ETag: {etag}");
// DELETE with wrong ETag — should return 412 Precondition Failed, but MinIO returns 204
try {
await s3.DeleteObjectAsync(new DeleteObjectRequest {
BucketName = "testbucket", Key = "test.txt", IfMatch = "\"wrong-etag\""
});
Console.WriteLine("BUG: object deleted even though ETag does not match!");
} catch (AmazonS3Exception ex) when (ex.StatusCode == System.Net.HttpStatusCode.PreconditionFailed) {
Console.WriteLine("OK: 412 Precondition Failed (expected behavior)");
}Actual output: BUG: object deleted even though ETag does not match!
Context
The If-Match conditional header on DeleteObject is essential for implementing optimistic concurrency control — ensuring that a delete operation only proceeds if the caller has seen the latest version of the object. Without this, concurrent writers can silently delete objects that have been updated since the caller last read them.
MinIO already supports If-Match for GetObject, HeadObject, PutObject, CopyObject, and multipart operations. DeleteObject is the only standard S3 write operation where this header is silently ignored.
Regression
No. This has never been implemented in MinIO.
Your Environment
- Version used:
RELEASE.2026-03-14T12-00-00Z(also verified by code inspection of latestmain) - Server setup and configuration: single-node, default configuration
- Operating System and version: tested on Windows (Docker), issue is platform-independent (server-side logic)
Activity
Vonng commentedon Sep 2, 2026
20260903 release review update: the issue is valid and remains open, but conditional delete is deliberately not part of this release.
The current server still ignores HTTP
If-MatchonDeleteObject;DeleteObjectsalso ignores each per-objectETag. PR #12 addresses only part of the contract and evaluates the condition at the wrong storage layer for multi-pool state. A reviewed local experiment proves the condition must be evaluated exactly once against the logical current object under the outer pool lock; the batch API needs a separate complete contract.Shipping partial semantics would be more dangerous than documenting the inherited limitation. The design, counterexamples, and acceptance requirements are recorded at https://silo.pgsty.com/blog/design/conditional-delete/ .
Vonng commentedon Sep 6, 2026
Current-main verification, 2026-09-06: on
e7d0e62f16ed8a2373a4e9f5c4639d62886c09f2, a realDeleteObjectwith a wrongIf-Matchreturned 204 and a subsequent read confirmed the object was deleted. The issue remains valid and worth fixing for clients that rely on compare-and-delete.PR #12 is unchanged at
5b71a75e; the existing request-changes review still applies. Do not merge that per-pool callback implementation as the remedy.The previously documented safer implementation is still available locally as
codex/pr12-conditional-delete/4a1c98deaa9aa60e244d05a289d7abdebb245b12. I confirmed its source evaluates the condition once under the outer pool lock before mutation, and clears the callback before lower-pool deletion.I then applied that existing commit's patch to an isolated checkout of current main. It applies cleanly, and a fresh run of
go test -tags kqueue,dev ./cmd -count=1 -timeout=120s -run 'Conditional|CheckPreconditionsDELETE|TestAPIDeleteObjectHandler'passed 33 tests/subtests, including the cross-pool and read-quorum regressions. The patch also applies cleanly to the reviewed replication-PR integration (application check only on that integration).This local implementation has not been pushed or merged, and the targeted result is not hosted CI or release validation. The efficient next step is to bring this existing implementation forward into an updated PR and complete its current checks, rather than restart the design or call the original PR ready. Full per-object conditional batch deletion remains a separate feature; this patch rejects that unsupported request form before deleting anything.
Vonng commentedon Sep 6, 2026
Fix record — conditional DeleteObject (If-Match); PR #145
DeleteObjectignoredIf-Match; a mismatched ETag still deleted the object. Now: mismatch → 412 + preserved; match/*→ 204; missing object → NoSuchKey, missing version → NoSuchVersion.Implementation (PR #145): a pure
CheckPrecondFn(no ResponseWriter writes — avoiding PR #12's data race under concurrent multi-pool cleanup) evaluated at the server-pool layer, under the NS write lock already held, before the delete-marker short-circuit and any per-pool cleanup, against the version that will actually be removed (latest for no-versionId; a version-scoped read otherwise). Delete-marker → precondition fails (If-Match:*→ 412); SSE-C/SSE-KMS compare against the public ETag viagetDecryptedETag(keyless); read-quorum loss refuses rather than deletes.Adversarial review: Codex Astra 6 (Max), 3 rounds → PASS. R1 caught the wrong evaluation layer + the multi-pool atomicity limit; R2 confirmed the server-pool re-architecture sound (no within-set TOCTOU) and flagged two error-path edges (delete-marker version → 405; absent-key version → NoSuchKey); R3 confirmed both fixed (412 / NoSuchVersion), no regression, replication-marker distinction preserved.
Scope: atomic for a single erasure set (default deployment). Multi-pool conditional-delete atomicity → follow-up #144 (mirrors #120→#133). PR #12's approach superseded (response-writing closure = data race).
Local: gofmt/vet/build/rebrand clean; unit + object-layer + handler (both backends) + regressions green; red/green per guard. Keeping open until PR #145 merges.
Vonng commentedon Sep 7, 2026
Resolved by #145 (merged to
mainasc20114873).DeleteObjectnow honors theIf-Matchprecondition. The check is evaluated at the server-pool layer inside the held namespace write lock, against the version that will actually be deleted (latest via pool info when no version id is given; an explicit version otherwise), before the delete-marker short-circuit — so there is no within-set TOCTOU. The precondition helper is a pure closure (deleteIfMatchPreconditionFailed): a delete marker fails the match,*means existence-only, a concrete ETag compares via the sharedgetDecryptedETagsuffix. Two error-path edges were corrected: a delete-marker version returns412(not405), and an absent version id returnsNoSuchVersion(notNoSuchKey).Verified: Codex adversarial review (3 rounds; R1 rejected the initial erasure-layer placement and it was re-architected to the server-pool layer), full acceptance on merged
main.Scope narrowed to a single erasure set; multi-pool conditional-delete atomicity is tracked in #144.
fix(delete): honor If-Match precondition on DeleteObject (pgsty#10)