Skip to content

[P2] A compressed SSE-C object replicates to a replica that decrypts to an S2 stream #118

Closed

Description

@Vonng

Problem

With compression allow_encryption=on, an object that is both SSE-C and compression eligible is
stored as encrypt(s2(plaintext)). Replication reads it raw, because ReplicationRequest forces
NoDecryption, and ships the ciphertext without the compression framing: putReplicationOpts
drops X-Minio-Internal-compression and X-Minio-Internal-actual-size. Even a destination that
applies no transforms of its own stores a replica with the source seal intact and no compression
marker, so a GET with the correct customer key returns HTTP 200 and the raw S2 stream instead of
the object. The source records the transfer as COMPLETED. Inherited from upstream, and a
regression against upstream's own intent: the commit that enabled SSE-C replication refused this
combination at PUT time, and a later commit removed the refusal.

allow_encryption is off by default and documented as unsafe, so only deployments that opted in
are affected. The trap is that the setting is global: a deployment that turns it on for compressed
SSE-S3 or SSE-KMS objects silently starts producing SSE-C objects that cannot be replicated. The
priority assumes #109 lands first and turns the silent corruption into a Failed replication
status; on main as it stands today this path is silent data corruption and would be P1.

Reproduction and evidence

TestReviewCompressedSSECReplicaCorruption drives the production option builder and writes the
replica the way a non-transforming destination stores it: compression off and no default encryption
at the destination, so none of the #109 destination transforms apply. It fails on main on
ErasureSD and Erasure, for a single PUT and for a multipart upload.

Stage Single PUT Multipart
Source plaintext 335872 B 335872 B
Source stored, compression=klauspost/compress/s2 288 B 288 B
Wire: compression marker carried no no
Replica stored, compression marker absent absent
Replica actual-size absent 335872 (carried as X-Minio-Replication-Actual-Object-Size)
GET with the correct key 200, 256 B 200, 256 B, Content-Length: 335872

The 256 returned bytes s2-decode exactly to the 335872 byte source plaintext, proving the body is
s2(plaintext). The single PUT is fully silent, since status, Content-Length and body agree with
each other and are all wrong; the multipart replica advertises the source's actual size and
delivers 256 bytes, so a client sees a short read. Batch replication does not reach this:
BatchJobReplicateV1.ReplicateToTarget and writeAsArchive read with a plain ObjectOptions, so
NoDecryption is never set and an SSE-C source fails at read time, compressed or not
(TestReviewBatchReplicationCannotReadSSEC).

Cause and minimal repair

On main f0bd164b9, excludeForCompression at cmd/object-api-utils.go:613 excludes encrypted
objects from compression only while allow_encryption is off. With it on, four handlers compress
an SSE-C object: PutObjectHandler (cmd/object-handlers.go:2108), NewMultipartUploadHandler
(cmd/object-multipart-handlers.go:292), CopyObjectHandler, which compresses at
cmd/object-handlers.go:1611 and only then encrypts at :1628, and PutObjectExtractHandler,
which compresses at :2564 and encrypts at :2669. A copy needs no compressed source: an SSE-C
key rotation on a null version cannot be metadata only, so it rewrites, and the rewrite turns an
uncompressed object into a compressed one. The source read sets NoDecryption at
cmd/erasure-object.go:257-259, and cmd/object-api-utils.go:820-823 then clears isCompressed
as well as isEncrypted, so the raw stored bytes go on the wire.
cmd/bucket-replication.go:786-788 drops every X-Minio-Internal- key not listed in
validSSEReplicationHeaders, which is where the compression marker and actual size are lost. The
S2 framing itself travels inside the ciphertext; only the metadata that says how to read it is
missing. The source cannot strip the framing either, since that means decrypting first.

Upstream 468a9fae8 ("Enable replication of SSE-C objects", 2024-03-28) refused this at PUT time
with crypto.ErrIncompatibleEncryptionWithCompression; a2cab0255 ("Fix SSE-C checksums",
2024-06-10) removed the guard on the reasoning that "compression will be disabled by default if
SSE-C is specified", true only for allow_encryption=off. The same commit flipped the integration
script to allow_encryption=off and commented out the assertion covering the guard, leaving the
non-default path unguarded and untested. The error constant survives, unused, at
internal/crypto/error.go:86, and upstream master still has no guard.

Minimal repair: widen that one condition to
crypto.SSEC.IsRequested(header) || (crypto.Requested(header) && !cfg.AllowEncrypted). One line
plus a comment, covering all four producers and any future caller of isCompressible.
SSEC.IsRequested ignores copy-source headers (internal/crypto/sse-c.go:47), so it targets
destination SSE-C only, and a raw SSE-C replica write is unaffected because it carries no public
SSE-C headers. allow_encryption keeps its meaning for SSE-S3 and SSE-KMS, where the server owns
the key and the source decompresses before replicating. Objects already stored compressed stay
readable on the source and are refused by the source guard #109 adds, so both changes are needed.

Restoring upstream's 400 was prototyped first and rejected: it must be repeated at every producer,
upstream's own version covered only two of the four, and it turns a previously accepted upload into
a failure. Excluding costs storage on affected SSE-C writes instead. One existing expectation
changes: TestAPICopyObjectSSECKeyRotationNullVersionCompressesRewrite asserts at
cmd/object-copy-metadata_test.go:499 that such a rewrite is compressed, pinning the creation of
the shape being removed, so it flips to uncompressed and is renamed ...SkipsCompression; the
plaintext sibling
TestAPICopyObjectMetadataOnlyNullVersionCompressesRewrite keeps the coverage that a compressed
rewrite records matching metadata. Out of scope: carrying compression state over the wire, and
repairing replicas already written. Size: S, one condition plus a comment in product code, one
renamed test expectation, and the regression tests.

Acceptance

  • With allow_encryption=on, newly written or rewritten SSE-C data is stored uncompressed
    through PutObject, NewMultipartUpload, CopyObject including key rotation, and
    PutObjectExtract. Metadata-only operations preserve the existing representation, so an
    already compressed object stays compressed (cmd/object-handlers.go:1777, and :1530 for
    in-place rotation).
  • With allow_encryption=on, plaintext, SSE-S3 and SSE-KMS objects are still compressed; with
    allow_encryption=off, behaviour is unchanged.
  • A raw SSE-C replica write is unaffected, since it carries no public SSE-C headers.
  • TestReviewCompressedSSECReplicaCorruption can no longer construct the corrupt source object
    on either backend.
  • TestAPICopyObjectSSECKeyRotationNullVersionCompressesRewrite is renamed
    ...SkipsCompression and expects an uncompressed rewrite, keeping its body, checksum,
    version and ETag assertions; no other existing test changes.
  • Multipart uploads initiated before the change keep compressing their parts, because every
    part follows the metadata saved at initiation (cmd/object-multipart-handlers.go:877); they
    are left alone and [P1] SSE-C replicas become unreadable with destination default encryption or compression #109 stays their replication backstop.
  • The rule is documented in docs/compression/README.md as "SSE-C objects are excluded from
    compression even with allow_encryption=on", and
    docs/site-replication/run-ssec-object-replication-with-compression.sh is restored to
    allow_encryption=on and asserts the SSE-C object is stored uncompressed and replicates.

Related

Parent: #109, whose fix plan adds a putReplicationOpts rejection for compressed SSE-C sources and
lists carrying the compression state as explicitly out of scope. Ordering: #109 lands first and is
the backstop for objects already stored in this shape; this issue stops new ones being created.
Neither repairs replicas already written; #109 records why a resync is not a reliable recovery.
Introducing commits: upstream 468a9fae8 added the guard, a2cab0255 removed it.

Carrying the compression state over the wire was considered and rejected as the end state. It needs
a new marker header with entries in validSSEReplicationHeaders, replicationToInternalHeaders
and the trusted-header list, a way to carry the actual size on the single PUT path, a destination
restore path, and a peer capability check. The transport gap is narrower than that list suggests,
since X-Minio-Replication-Actual-Object-Size already exists (cmd/handler-utils.go:90,
populated for multipart at cmd/bucket-replication.go:1731), but the capability check is the
blocker: without it an older destination drops the unknown header at
cmd/handler-utils.go:271-283 and silently reproduces the corruption above, which is worse than
not compressing. Decompressing on the source is impossible, since SSE-C keys are never held
server side.

Versions and verification

Found during the 2026-09-05 fix-plan triage of #109 on main f0bd164b9 (release
RELEASE.2026-09-03T13-18-01Z / 9b11dc946 for SILO, RELEASE.2026-09-03T07-13-05Z / a2ef95c0
for mcli). Verified by code reading and by five new tests on ErasureSD and Erasure. On main the
replica corruption, CopyObject and archive extraction tests fail, and the matrix fails only on its
four SSE-C rows with allow_encryption=on, its plaintext, SSE-S3, SSE-KMS and
allow_encryption=off rows passing unchanged; the batch test is an unchanged control. With the
exclusion all five pass, together with the existing compression and copy-metadata tests once the
one expectation above is updated. History confirmed with git log -S and git show. Agreed with
the Codex reviewer (gpt-6-astra) in two rounds, which converged on this fix independently from both
sides after the reviewer rejected the first, per-handler prototype.

Activity

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

    @Vonng
    MemberAuthor

    Fix record (2026-09-05)

    Status: implemented, reviewed, awaiting merge. Pull request: #126 (branch fix/issue-118-no-compressed-ssec, commit 35bd75948, based on main f0bd164b9).

    Change. cmd/object-api-utils.go excludeForCompression: the condition becomes crypto.SSEC.IsRequested(header) || (crypto.Requested(header) && !cfg.AllowEncrypted), one line plus a two-line comment, covering all four producers (PutObject, NewMultipartUpload, CopyObject destination, PutObjectExtract). docs/compression/README.md records the rule. The CI script docs/site-replication/run-ssec-object-replication-with-compression.sh is restored to allow_encryption=on and now uploads a compressible SSE-C multipart object, asserts it is stored uncompressed and that it replicates with matching ETag and size (not executed here; needs the make target before release).

    Tests. New cmd/compression-ssec_test.go (replica-corruption reproduction for single PUT and multipart, the CopyObject and snowball-extract producers, the allow_encryption matrix, batch control); red on main, green with the fix on both backends. Two existing expectations changed deliberately, both pinning the removed shape: TestAPICopyObjectSSECKeyRotationNullVersionCompressesRewrite → ...SkipsCompression, and the SSE-C compressed-encrypted variant of TestAPICopyObjectServerSideChecksumEncryption (renamed compressible-extension). gofmt, go vet, golangci-lint, shellcheck and shfmt clean.

    Adversarial Codex review (gpt-6-astra). Round 1: FAIL (a second existing test pinned compressed SSE-C storage, found by sweeping every test that touches a customer key and compression; the CI script needed a real storage-representation assertion; three misleading comments). Round 2: FAIL (the new shell assertion accepted a failed HEAD; one comment). Round 3: PASS, no findings.

    Deployment notes. #109 (PR #122) lands first as the backstop for objects already stored compressed; neither repairs replicas already written. Deployments with allow_encryption=on stop compressing new SSE-C data from this release; the public compression page should carry the same sentence.

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

    @Vonng
    MemberAuthor

    Merged — record complete (2026-09-06)

    Merged via #126 (merge commit 765757473) 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.

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