Skip to content

DeleteObject ignores If-Match header (no conditional delete support) #10

Closed

Description

@magicxor

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.

Reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObject.html

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:

  1. Read the If-Match header in DeleteObjectHandler (around line 2608, after delOpts() returns).
  2. Set opts.CheckPrecondFn with a closure that compares the request ETag against the object's current ETag using isETagEqual().
  3. Evaluate CheckPrecondFn atomically in the erasure DeleteObject path (cmd/erasure-object.go) after getObjectInfoAndQuorum() — similar to how PutObject does it at cmd/erasure-object.go:1261–1286.
  4. Return PreConditionFailed{} (HTTP 412) when the ETag does not match.

Steps to Reproduce

  1. 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)
  2. Create a bucket and upload an object
  3. Send a DeleteObject request with If-Match: "wrong-etag" (an ETag that does not match the object)
  4. Observe that the object is deleted with 204 No Content instead of being rejected with 412 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 latest main)
  • Server setup and configuration: single-node, default configuration
  • Operating System and version: tested on Windows (Docker), issue is platform-independent (server-side logic)

Activity

  1. added this to Siloand Siloon Aug 4, 2026
  2. moved this from Backlog to In progress in Siloon Aug 4, 2026
  3. Vonng commented on Sep 2, 2026

    @Vonng
    Member

    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-Match on DeleteObject; DeleteObjects also ignores each per-object ETag. 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/ .

  4. added
    bug
    on Sep 2, 2026
  5. Vonng commented on Sep 6, 2026

    @Vonng
    Member

    Current-main verification, 2026-09-06: on e7d0e62f16ed8a2373a4e9f5c4639d62886c09f2, a real DeleteObject with a wrong If-Match returned 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.

  6. Vonng commented on Sep 6, 2026

    @Vonng
    Member

    Fix record — conditional DeleteObject (If-Match); PR #145

    DeleteObject ignored If-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 via getDecryptedETag (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.

  7. moved this from In progress to Done in Siloon Sep 6, 2026
  8. Vonng commented on Sep 7, 2026

    @Vonng
    Member

    Resolved by #145 (merged to main as c20114873).

    DeleteObject now honors the If-Match precondition. 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 shared getDecryptedETag suffix. Two error-path edges were corrected: a delete-marker version returns 412 (not 405), and an absent version id returns NoSuchVersion (not NoSuchKey).

    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.

  9. self-assigned this
    on Sep 7, 2026
  10. added theissue type on Sep 15, 2026
  11. added this to the 20260916 milestone on Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions