mirror of
https://github.com/pgsty/minio.git
synced 2026-09-26 04:45:59 +03:00
fix(delete): honor If-Match precondition on DeleteObject (#10)
DeleteObject ignored the If-Match request header and always deleted the object (204). AWS S3 conditional deletes require that when If-Match is provided and does not match the object's current ETag, the delete is refused with 412 Precondition Failed and the object is left intact. The precondition is evaluated in erasureServerPools.DeleteObject, while the server-pool delete lock is held, before the delete-marker short-circuit and before any version is removed. It runs against the version that will actually be deleted: pinfo.ObjInfo for a normal delete, or the specifically addressed version (read under the held lock) for a version-scoped delete, since getPoolInfoExistingWithOpts strips VersionID. The check is a pure function (no ResponseWriter writes) and returns PreConditionFailed, which toAPIError maps to 412; CheckPrecondFn is cleared before lower layers run so the precondition is evaluated exactly once. Semantics: - If-Match mismatch on a live object -> 412, object preserved. - If-Match "*" requires a live object; a delete-marker-latest -> 412, and an explicitly addressed delete-marker version -> 412 (getObjectInfo returns the marker with MethodNotAllowed; the marker is the precondition target, not a 405). - SSE-C/SSE-KMS: compared against the public ETag derived without the customer key, so a satisfiable condition is never falsely rejected. - Explicit versionId -> evaluated against that version; a missing addressed version -> NoSuchVersion whether or not the key exists; a missing object (no versionId) -> NoSuchKey; no If-Match -> unchanged (including the unconditional version-scoped delete's error behavior). Scope: atomicity is guaranteed for a single erasure set (the default deployment). Multi-pool conditional-delete atomicity (concurrent writers across pools, cross-pool version selection) is tracked as a follow-up. Tests: pure-helper unit test (delete marker, "*", SSE-C without key); object-layer tests (unversioned match/mismatch/missing, versioned delete-marker-latest and addressed delete-marker version, explicit-version selection, missing version on present and absent keys, read-quorum loss); handler tests (412/204/wildcard/404) across both backends, with red/green demonstrated per guard. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L7qJqWwy8oFA6aCXWRzXQe Signed-off-by: Feng Ruohang <rh@vonng.com>
This commit is contained in:
@@ -2947,6 +2947,20 @@ func (api objectAPIHandlers) DeleteObjectHandler(w http.ResponseWriter, r *http.
|
||||
return
|
||||
}
|
||||
|
||||
// If-Match conditional delete (see AWS S3 conditional deletes). Delete the
|
||||
// object only if its current ETag matches the client-supplied value,
|
||||
// otherwise the request is refused with 412 Precondition Failed and the
|
||||
// object is left intact. The precondition is evaluated in
|
||||
// erasureServerPools.DeleteObject, against the version that will actually be
|
||||
// removed, while the delete lock is held, so the object cannot change
|
||||
// between the ETag check and the delete.
|
||||
if ifMatch := r.Header.Get(xhttp.IfMatch); ifMatch != "" {
|
||||
opts.HasIfMatch = true
|
||||
opts.CheckPrecondFn = func(oi ObjectInfo) bool {
|
||||
return deleteIfMatchPreconditionFailed(r.Header, ifMatch, oi)
|
||||
}
|
||||
}
|
||||
|
||||
rcfg, _ := globalBucketObjectLockSys.Get(bucket)
|
||||
if rcfg.LockEnabled && opts.DeletePrefix {
|
||||
apiErr := toAPIError(ctx, errInvalidArgument)
|
||||
@@ -3012,6 +3026,13 @@ func (api objectAPIHandlers) DeleteObjectHandler(w http.ResponseWriter, r *http.
|
||||
return
|
||||
}
|
||||
if isErrObjectNotFound(err) || isErrVersionNotFound(err) {
|
||||
if opts.HasIfMatch {
|
||||
// A conditional (If-Match) delete cannot satisfy its
|
||||
// precondition against a missing object, so surface the
|
||||
// not-found error instead of the idempotent 204 response.
|
||||
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL)
|
||||
return
|
||||
}
|
||||
// Send an event when the object is not found
|
||||
objInfo.Name = object
|
||||
objInfo.VersionID = opts.VersionID
|
||||
|
||||
Reference in New Issue
Block a user