Skip to content

[P1] Empty Object Lock replication updates bypass ordering and erase newer object state #111

Closed

Description

@Vonng

Problem

Object-version retention and legal-hold metadata are removed before the replication CopyObject handler checks incoming timestamps. The check is inside the branches for nonempty values, so an empty or absent incoming value can erase newer state. A retention removal also fails to persist its source timestamp, allowing delayed older retention to reappear.

Reproduction

Both cases use the normal metadata-replication request shape: an explicit object version, replica request markers, x-amz-tagging-directive: REPLACE, source timestamps, and the default metadata directive COPY. Signed-handler tests reproduce both cases on ErasureSD and Erasure, on both releases.

  1. Store GOVERNANCE retention through 2030 and legal hold ON, both timestamped 10:00. Apply an independent replicated tag update carrying an older retention removal timestamped 09:30 and no legal-hold value. CopyObject returns 200, but the newer retention and hold disappear. They should survive.
  2. Start with retention timestamp 09:00. Apply retention removal timestamped 10:00. The target clears the value but retains timestamp 09:00. A delayed retained value timestamped 09:30 then restores GOVERNANCE. The newer removal should remain authoritative.

The normal sender reads retention/hold source timestamps independently of the current values in cmd/bucket-replication.go; this is a reachable ordinary replication sequence.

Cause and minimal repair

The retention branch and hold branch skip ordering when incoming values are empty. The old path traces to c4373ef290344fd01981864cb9feca9410cf5b21. The interval fix f4c1286c9dfd882384dad74667b639b93f66b418 repaired nonempty ordering but omitted these cases.

Compare source timestamps for each field before deciding whether to set or remove its value. Preserve newer stored values for older/unknown input, and persist the source timestamp of a newer removal even when the value is empty.

Acceptance

  • Older empty/absent replication state cannot clear newer retention or hold.
  • Newer retention removal persists its timestamp and prevents an older retained value from returning.
  • Existing nonempty ordering tests continue to pass on both object-layer backends.

Related: #77 concerns bucket-level ObjectLockConfig selection/heal, where nil has a different contract. This issue concerns per-object-version retention/legal-hold in CopyObject and needs its own focused fix.

Versions and verification

Reproduced in the 2026-09-05 functional review on the published SILO release RELEASE.2026-09-03T13-18-01Z (9b11dc9469e650815b775cb47b039610644f5da4), with RELEASE.2026-08-06T00-00-00Z (3be10fcc1a44f6620ded0bd303461f9d688cca23) as the baseline. The reviewed code remains unchanged on current main f0bd164b92d799c026fb1a31ad8e0df8ecb39388. Product fixes have not been applied.

Activity

  1. added
    bug
    on Sep 5, 2026
  2. Vonng commented on Sep 5, 2026

    @Vonng
    MemberAuthor

    Fix plan prepared 2026-09-05 by Claude (Fable 5.1) and reviewed in 2 round(s) of dialogue with the Codex reviewer (gpt-6-astra) that filed this issue. Local paths under /Users/vonng/pgsty/silo-codex-triage-20260905/silo-111 (plan, prototype diff, tests, Codex transcripts) and /private/tmp/silo-mcli-review-20260905.MfP8W9 (review evidence) live on the maintainer's machine, not in the repository.

    Fix plan — #111 (Claude ⨯ Codex consensus, 2026-09-05)

    1. Verdict

    Confirmed. Both reported cases reproduce on current main f0bd164b9; git diff 9b11dc946..f0bd164b9 over cmd/object-handlers.go, cmd/bucket-object-lock.go, cmd/bucket-replication.go, internal/bucket/object/lock/lock.go and internal/http/headers.go is empty, so the reviewed code is unchanged. I ran the Codex repro in a detached worktree at main: TestReviewReplicaAbsentLockFieldsPreserveNewerState and TestReviewReplicaRetentionRemovalKeepsOrderingTimestamp fail on ErasureSD and Erasure, reporting the stored GOVERNANCE, retain-until date and hold ON as "", and the removal keeping the stale 09:00 timestamp. I also wrote a third probe using the exact shape a real sender emits after a retention removal, headers present with empty values rather than absent, and it fails on main the same way, so both wire shapes are affected. One refinement to the issue text: the empty-value blind spot is older than c4373ef29. That commit added the replica timestamp path, but the enclosing retentionMode.Valid() / legalHold.Status.Valid() gate came in with upstream 43a3778b4 (minio#9259); c4373ef29 and the SILO interval fix f4c1286c9 both stayed inside that gate.

    2. Root cause

    cmd/object-handlers.go:1708 deletes the three public Object Lock value keys from the rebuilt metadata (FilterObjectLockMetadata(..., true, true) at internal/bucket/object/lock/lock.go:606-613, which touches only the value keys and leaves the internal timestamps alone), and cmd/object-handlers.go:1715 and :1732 only put a value back inside retentionMode.Valid() and legalHold.Status.Valid(). A replica request whose source no longer carries a value therefore never reaches the ordering comparison: the stored state stays stripped and is lost, whatever the timestamps say. checkPutObjectLockAllowed returns an invalid mode with ErrNone for both shapes a replication sender produces for "no retention": headers absent (cmd/bucket-object-lock.go:322, the replicaTrusted early return) and headers present but empty (cmd/bucket-object-lock.go:313-317, where the ErrObjectLockInvalidHeaders from ParseObjectLockRetentionHeaders is deliberately swallowed for a trusted replica). Both shapes are ordinary: cmd/object-handlers.go:3208-3216 records a retention removal as empty mode plus empty date plus a fresh timestamp, getCopyObjMetadata at cmd/bucket-replication.go:715-754 copies those empty values into the CopyObject metadata map, and minio-go api-compose-object.go copyObjectDo does headers.Set(k, v) for every entry, so the empty header goes on the wire. Second defect: when the removal does win, no timestamp is written either, so cmd/bucket-object-lock.go:370 olderThan later sees an unparseable stored timestamp and lets any older retained value back in.

    3. Minimal fix

    • Change: cmd/object-handlers.go CopyObjectHandler, the two blocks at :1715 and :1732, plus the two restore helpers at cmd/bucket-object-lock.go:388 and :399. Decide each field on the source timestamp first and the incoming value second, and move the timestamp restore in each helper ahead of its early return on an empty stored value. The non-replica path is untouched. ~35 changed lines of product code, S.
    • Behaviour after the fix. Retention: dstOpts.ReplicationSourceRetentionTimestamp decides the winner. A stale or timestamp-less update restores the stored state, so absent-and-unordered means unknown rather than removed; olderThan at cmd/bucket-object-lock.go:370-377 already refuses to let a zero source timestamp win. A newer update applies, and a removal is simply a newer update with no value: the value stays cleared and the source timestamp is persisted, so a delayed older retained value can no longer resurrect. Legal hold uses the same ordering but only a valid incoming ON/OFF can win; anything else restores the stored hold. That asymmetry is deliberate and is the one place the two fields must differ. S3 has no legal-hold removal: an explicitly empty hold header is already rejected as an invalid status (internal/bucket/object/lock/lock.go:515-517, surfaced at cmd/bucket-object-lock.go:298-302), so the only value-less shape that reaches the branch is an absent one, and an absent status conveys no legal-hold change even when an orphaned timestamp arrives with it. PutObjectLegalHoldHandler at cmd/object-handlers.go:3044 always writes a validated ON/OFF together with its timestamp, so an object damaged by this bug is the one thing that carries a hold timestamp with no status, and a uniform rule would let that damage clear a healthy hold elsewhere. The restore helpers now put the stored timestamp back even when the stored value is empty, which matters under the REPLACE metadata directive: replicationToInternalHeaders at cmd/handler-utils.go:106 does not map the reserved lock timestamps, so under REPLACE the helper is the only thing that can carry a stored removal timestamp forward. This matches upstream MinIO's per-field last-writer-wins model on X-Minio-Source-Replication-Retention-Timestamp and X-Minio-Source-Replication-LegalHold-Timestamp, and it matches S3, where PutObjectRetention with an empty mode is the documented way to drop retention on a GOVERNANCE object.
    • Explicitly out of scope. Bucket-level ObjectLockConfig selection and heal, which is Audit site-replication source timestamps, tombstones, and per-site counters #77 and has a different nil contract. PutObjectHandler at cmd/object-handlers.go:2186, which writes a whole new version from the request and records no lock timestamps at all, so ordering between a full-object replica PUT and a metadata CopyObject stays as inherited from upstream. PutObjectExtract at :2646, which only creates new objects. The pre-existing asymmetry in getReplicationAction at cmd/bucket-replication.go:977-1024, where a source holding an empty x-amz-object-lock-mode never compares equal to a target that has the key deleted, so a removed-retention object is re-sent on every replication evaluation; that is unchanged by this fix and belongs to its own issue. The fact that storedObjectLockState reads the source object's metadata, which is correct for replication because the sender copies an object onto itself at cmd/bucket-replication.go:1582 but would be the wrong object for a hand-made cross-object copy carrying replication headers. And any change to the sender or to the wire format.

    4. Tests

    • Regression tests: adopt both Codex repro tests into cmd/replication-trust_test.go next to TestAPICopyObjectReplicaLegalHoldTimestamp, renamed off the TestReview prefix (suggest TestAPICopyObjectReplicaAbsentLockFieldsPreserveNewerState and TestAPICopyObjectReplicaRetentionRemovalKeepsOrderingTimestamp). They run under ExecObjectLayerAPITest on ErasureSD and Erasure and use signed V4 requests with the production replica shape. Add three cases they do not cover, all written and measured in the prototype (/Users/vonng/pgsty/silo-codex-triage-20260905/silo-111/tests/review_object_lock_replication_probe_test.go):
      1. a present-empty x-amz-object-lock-mode / x-amz-object-lock-retain-until-date pair, once newer and once stale, since that is what a real sender emits after PutObjectRetention removal;
      2. the same scenario under the REPLACE metadata directive, asserting that a stored removal timestamp survives a rejected update, because the Codex removal test uses the default COPY directive under which the reserved timestamp carries through on its own and the restore-helper change is therefore untested;
      3. an orphaned newer legal-hold timestamp with no hold value, under both directives, asserting that the stored ON and its timestamp are preserved.
        Every case asserts mode, retain-until date and retention timestamp together, and the Codex removal test should be extended the same way: it currently checks only the mode after the stale retained update is rejected.
    • Existing tests that must stay green: TestAPICopyObjectReplicaLegalHoldTimestamp, TestAPICopyObjectHandler, TestAPICopyObjectPartHandler, TestAPICopyObjectReplicationHeaderPoisoning, TestAPICopyObjectMetadataOnlyNullVersion, TestAPICopyObjectMarkerOnlyDoesNotCopyCiphertext, TestAPIPutObjectReplicationTrust.
    • No live or integration check is required. The wire shape is fully covered by the signed-handler tests, and the sender is unchanged.

    5. Compatibility, risk, rollout

    No API, wire or configuration change: the same headers are read, none is added, and no stored field changes meaning. The source timestamps are read only for a trusted replication peer (cmd/object-api-options.go:372-376) and an unparseable one is already a 400 rather than a silent zero (:387-399), so no new client-reachable surface appears. Mixed-version replication is safe in the direction that matters. A 0806 peer runs the same sender: the metadata replication branch from applyAction: to the c.CopyObject call in cmd/bucket-replication.go is byte-identical between main and the silo-state-baseline 0806 worktree, so it emits the same timestamps; and a field that arrives with no source timestamp is unordered, so it now preserves whatever the destination holds, which is exactly what protects a destination carrying its own retention or hold. During a rolling upgrade an un-upgraded receiver keeps the old erasing behaviour until it restarts, so the fix converges node by node with no coordination. Objects already damaged by the bug are not repaired: a hold or retention already dropped on a replica must be re-applied at the source, which then replicates normally, and mc replicate resync is the existing tool for that. One deliberate side effect: when a newer replica retention update carries no value, the destination now stores the ordering timestamp with no value, the same shape a local PutObjectRetention removal already leaves behind.

    6. Cost

    S: ~35 changed product lines across two files, ~290 test lines (113 for the two adopted Codex tests, ~180 for the three added probes; the probes can be trimmed and merged into one table-driven test if the reviewer prefers). No dependency on other issues; #77 is separate and must not be bundled. Server-side only, no mcli or SDK work. One engineer, well under a day including review.

    7. Consensus with Codex

    Rounds used: 2/3. CONSENSUS: YES in round 2, on all five dimensions.
    Agreed: validity, root cause, fix approach, test plan, scope and minimality. Codex confirmed my reading of its own repro, that absent and present-empty retention must have equivalent semantics after validation, and that no live integration gate is needed.
    Amendments accepted from Codex, all four: (1) the asymmetric legal-hold rule, on its orphaned-timestamp argument, which I verified and had independently reached; (2) test coverage under the REPLACE metadata directive plus an absent-legal-hold-with-newer-timestamp case, since the Codex repros use COPY and therefore never exercise the restore helpers; (3) two wording corrections, that FilterObjectLockMetadata deletes only the public value keys and that a timestamp-less incoming field preserves destination state rather than there being "nothing to erase"; (4) assert the retain-until date alongside the mode and the stored legal-hold timestamp under REPLACE, and drop the claim that a value-less hold update is "only ever the residue of this bug" since ordinary absence also exists.
    Rejected suggestions: none. Codex proposed no scope creep.
    Open disagreements: none. Codex notes, correctly, that it verified the prototype by reading it and did not rerun the tests itself; every test result quoted here is from my runs in a detached worktree at f0bd164b9.

    Appendix A — prototype diff

    Product code only; the review tests are not part of it. Full file: /Users/vonng/pgsty/silo-codex-triage-20260905/silo-111/plan.diff.

    diff --git a/cmd/bucket-object-lock.go b/cmd/bucket-object-lock.go
    index df801969b..e8cb31114 100644
    --- a/cmd/bucket-object-lock.go
    +++ b/cmd/bucket-object-lock.go
    @@ -386,22 +386,24 @@ func (s objectLockState) legalHoldIsOlderThan(src time.Time) bool {
     // restoreRetention and restoreLegalHold put the stored state back into
     // metadata that was rebuilt from a request whose update was not applied.
     func (s objectLockState) restoreRetention(metadata map[string]string) {
    +	// The stored timestamp orders the next update and must survive even when
    +	// the stored value is empty, which is how a removal is recorded.
    +	if s.retentionTimestamp != "" {
    +		metadata[ReservedMetadataPrefixLower+ObjectLockRetentionTimestamp] = s.retentionTimestamp
    +	}
     	if s.mode == "" {
     		return
     	}
     	metadata[strings.ToLower(xhttp.AmzObjectLockMode)] = s.mode
     	metadata[strings.ToLower(xhttp.AmzObjectLockRetainUntilDate)] = s.retainUntil
    -	if s.retentionTimestamp != "" {
    -		metadata[ReservedMetadataPrefixLower+ObjectLockRetentionTimestamp] = s.retentionTimestamp
    -	}
     }
     
     func (s objectLockState) restoreLegalHold(metadata map[string]string) {
    +	if s.legalHoldTimestamp != "" {
    +		metadata[ReservedMetadataPrefixLower+ObjectLockLegalHoldTimestamp] = s.legalHoldTimestamp
    +	}
     	if s.legalHold == "" {
     		return
     	}
     	metadata[strings.ToLower(xhttp.AmzObjectLockLegalHold)] = s.legalHold
    -	if s.legalHoldTimestamp != "" {
    -		metadata[ReservedMetadataPrefixLower+ObjectLockLegalHoldTimestamp] = s.legalHoldTimestamp
    -	}
     }
    diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go
    index bb2782816..0ee3eb4cc 100644
    --- a/cmd/object-handlers.go
    +++ b/cmd/object-handlers.go
    @@ -1712,35 +1712,44 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re
     
     	// apply default bucket configuration/governance headers for dest side.
     	retentionMode, retentionDate, legalHold, s3Err := checkPutObjectLockAllowed(ctx, r, dstBucket, dstObject, getObjectInfo, retPerms, holdPerms, replicaTrusted)
    -	if s3Err == ErrNone && retentionMode.Valid() {
    -		if dstOpts.ReplicationRequest {
    -			srcTimestamp := dstOpts.ReplicationSourceRetentionTimestamp
    -			if storedLock.retentionIsOlderThan(srcTimestamp) {
    +	if s3Err == ErrNone {
    +		// A replica update is ordered by its source timestamp alone, whether or
    +		// not it still carries a value: an update newer than the stored state
    +		// applies, and a removal is just an update with no value. An update that
    +		// is stale, or that carries no source timestamp at all and is therefore
    +		// unordered, leaves the stored state in place instead of erasing it.
    +		switch {
    +		case !dstOpts.ReplicationRequest:
    +			if retentionMode.Valid() {
     				srcInfo.UserDefined[strings.ToLower(xhttp.AmzObjectLockMode)] = string(retentionMode)
     				srcInfo.UserDefined[strings.ToLower(xhttp.AmzObjectLockRetainUntilDate)] = amztime.ISO8601Format(retentionDate.UTC())
    -				srcInfo.UserDefined[ReservedMetadataPrefixLower+ObjectLockRetentionTimestamp] = srcTimestamp.UTC().Format(time.RFC3339Nano)
    -			} else {
    -				storedLock.restoreRetention(srcInfo.UserDefined)
    +				srcInfo.UserDefined[ReservedMetadataPrefixLower+ObjectLockRetentionTimestamp] = UTCNow().Format(time.RFC3339Nano)
     			}
    -		} else {
    -			srcInfo.UserDefined[strings.ToLower(xhttp.AmzObjectLockMode)] = string(retentionMode)
    -			srcInfo.UserDefined[strings.ToLower(xhttp.AmzObjectLockRetainUntilDate)] = amztime.ISO8601Format(retentionDate.UTC())
    -			srcInfo.UserDefined[ReservedMetadataPrefixLower+ObjectLockRetentionTimestamp] = UTCNow().Format(time.RFC3339Nano)
    +		case !storedLock.retentionIsOlderThan(dstOpts.ReplicationSourceRetentionTimestamp):
    +			storedLock.restoreRetention(srcInfo.UserDefined)
    +		default:
    +			if retentionMode.Valid() {
    +				srcInfo.UserDefined[strings.ToLower(xhttp.AmzObjectLockMode)] = string(retentionMode)
    +				srcInfo.UserDefined[strings.ToLower(xhttp.AmzObjectLockRetainUntilDate)] = amztime.ISO8601Format(retentionDate.UTC())
    +			}
    +			srcInfo.UserDefined[ReservedMetadataPrefixLower+ObjectLockRetentionTimestamp] = dstOpts.ReplicationSourceRetentionTimestamp.UTC().Format(time.RFC3339Nano)
     		}
    -	}
     
    -	if s3Err == ErrNone && legalHold.Status.Valid() {
    -		if dstOpts.ReplicationRequest {
    -			srcTimestamp := dstOpts.ReplicationSourceLegalholdTimestamp
    -			if storedLock.legalHoldIsOlderThan(srcTimestamp) {
    +		// Legal hold has no removal in S3: an explicitly empty header is already
    +		// rejected as an invalid status, so the only value-less shape that gets
    +		// here is an absent one, and that conveys no legal-hold change even when
    +		// an orphaned timestamp comes with it. Only a valid status can win.
    +		switch {
    +		case !dstOpts.ReplicationRequest:
    +			if legalHold.Status.Valid() {
     				srcInfo.UserDefined[strings.ToLower(xhttp.AmzObjectLockLegalHold)] = string(legalHold.Status)
    -				srcInfo.UserDefined[ReservedMetadataPrefixLower+ObjectLockLegalHoldTimestamp] = srcTimestamp.UTC().Format(time.RFC3339Nano)
    -			} else {
    -				storedLock.restoreLegalHold(srcInfo.UserDefined)
    +				srcInfo.UserDefined[ReservedMetadataPrefixLower+ObjectLockLegalHoldTimestamp] = UTCNow().Format(time.RFC3339Nano)
     			}
    -		} else {
    +		case legalHold.Status.Valid() && storedLock.legalHoldIsOlderThan(dstOpts.ReplicationSourceLegalholdTimestamp):
     			srcInfo.UserDefined[strings.ToLower(xhttp.AmzObjectLockLegalHold)] = string(legalHold.Status)
    -			srcInfo.UserDefined[ReservedMetadataPrefixLower+ObjectLockLegalHoldTimestamp] = UTCNow().Format(time.RFC3339Nano)
    +			srcInfo.UserDefined[ReservedMetadataPrefixLower+ObjectLockLegalHoldTimestamp] = dstOpts.ReplicationSourceLegalholdTimestamp.UTC().Format(time.RFC3339Nano)
    +		default:
    +			storedLock.restoreLegalHold(srcInfo.UserDefined)
     		}
     	}
     	if s3Err != ErrNone {

    Measured on ErasureSD and Erasure in a detached worktree at f0bd164b9, single go test invocation, -count=1:

    • Before: TestReviewReplicaAbsentLockFieldsPreserveNewerState FAIL, TestReviewReplicaRetentionRemovalKeepsOrderingTimestamp FAIL, present-empty probe FAIL on both backends.
    • After: those three PASS, plus the REPLACE-directive and COPY-directive probes, TestAPICopyObjectReplicaLegalHoldTimestamp, and the six neighbouring CopyObject and replication-trust tests from §4. ok github.com/minio/minio/cmd 5.523s.
  3. Vonng commented on Sep 5, 2026

    @Vonng
    MemberAuthor

    Fix record (2026-09-05)

    Status: implemented, reviewed, awaiting merge. Pull request: #129 (branch fix/issue-111-object-lock-replica-ordering, commit b2dca43fd, based on main f0bd164b9).

    Change (cmd/object-handlers.go, cmd/bucket-object-lock.go, cmd/object-api-options.go). The retention and legal-hold blocks in CopyObjectHandler become switches keyed on the per-field source timestamp: newer update applies; newer removal clears the value and persists its timestamp; stale or unordered update restores the stored state; legal hold requires a valid incoming status. The restore helpers write the stored timestamp before their early return.

    Three deviations from the plan's prototype, each required by the adversarial review and each with a regression test: (1) putOptsFromHeaders now carries the parsed lock timestamps on the SSE-KMS branch, which had dropped them, so replicated updates are ordered on an SSE-KMS-default destination; (2) for a trusted replica an SSE-C key rotation's reserved-metadata snapshot is reconciled with the lock decision so the merge cannot reinstate the old timestamp; (3) the new value-less handling applies only to actual trusted replicas, not to marker-only authenticated requests, which keep their previous behaviour.

    Tests. The two adopted Codex repros plus probes for present-empty removals, the REPLACE directive, an orphaned legal-hold timestamp, the SSE-KMS destination and the marker-only request; red on main, green with the fix on both backends; TestAPICopyObjectReplicaLegalHoldTimestamp and neighbouring CopyObject tests stay green; gofmt, go vet and golangci-lint clean.

    Adversarial Codex review (gpt-6-astra). Round 1: FAIL, three MAJOR (SSE-KMS timestamps dropped; SSE-C rotation merge reinstating the old timestamp; marker-only requests inheriting source lock state). All three fixed with regressions. Round 2: PASS, one optional NIT on a test comment, applied.

    This branch is the base for #120 (SSE-C replica retransmit), whose PUT/multipart path reuses this lock-ordering semantics.

  4. moved this from Backlog to In progress in Siloon Sep 5, 2026
  5. moved this from In progress to Done in Siloon Sep 6, 2026
  6. Vonng commented on Sep 6, 2026

    @Vonng
    MemberAuthor

    Merged — record complete (2026-09-06)

    Merged via #129 (merge commit 885ca604a) into main. Supersedes the "awaiting merge" status above: main is green — silo e7d0e62f1, Go CI (Test cmd/, Test internal/, Race + S3 Select, Format/Build/Vet, Lint/Generated Files, Cross Compile) and VulnCheck all pass.

    Issue closed; fix record complete.

  7. added a commit that references this issue on Sep 6, 2026
    b2dca43
  8. self-assigned this
    on Sep 15, 2026
  9. added theissue type on Sep 15, 2026
  10. 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