Skip to content

fix: forward plaintext on federated CopyObject of SSE objects (#158) - #163

Merged
Vonng merged 3 commits into
mainfrom
fix/issue-158-federated-copy-sse
Sep 9, 2026
Merged

Vonng merged 3 commits into
mainfrom
fix/issue-158-federated-copy-sse

Conversation

@Vonng

@Vonng Vonng commented Sep 9, 2026

Copy link
Copy Markdown
Member

Fixes #158.

Problem

In a legacy etcd bucket-federation deployment (MINIO_ETCD_ENDPOINTS set, no MINIO_ETCD_PATH_PREFIX, so globalBucketFederation is true), a whole-object CopyObject whose destination bucket lives on another deployment takes the federation branch of CopyObjectHandler and forwards the write as a core.PutObject to that deployment.

That branch reads the source through getObjectNInfo, which yields the decrypted, decompressed bytes, but it then:

  1. ran the destination encryption locally (newEncryptReader / WithEncryption), exactly as the local path does, and
  2. forwarded that stream with srcInfo.Size, the source's stored size, and with dstOpts.ServerSideEncryption, so the remote encrypted again.

Reproduced through the in-process federation fixture against d1105bbb3 (single-part "abc", SSE-S3 ciphertext = 35 bytes):

Copy Forwarded bytes / declared length Result
SSE → plain 3 plaintext / 35 ContentLength=35 with Body length 3, HTTP 500
plain → SSE 35 local ciphertext / 3 ContentLength=3 with Body length 35, HTTP 500
SSE → SSE 35 local ciphertext / 35 HTTP 200, silent corruption: the remote stores a 67-byte double encryption, a destination GET returns the 35-byte inner ciphertext, and the returned CRC-64NVME covers that ciphertext

The same holds for SSE-C and SSE-KMS, for compressed sources, and for multipart sources. The source object is never modified. Federated copies of unencrypted objects were not affected. Ordinary CopyObject, bucket replication and site replication do not use this branch.

The pipeline is inherited from upstream (6ce7265c8, 2018, "Add double encryption at S3 gateway"; 778e9c864 only renamed the minio-go v6 calls to v7). Before #157 the forwarded reserved metadata made the remote reject most of these requests with 400, which masked the corruption; #157 fixed that rejection and made the 200-but-wrong path reachable.

Fix

cmd/object-handlers.go (commit 1): the remote write owns the destination's storage transformations, so hand it the logical bytes at their logical size and let it encrypt once. Compression was already excluded on this branch (isDstCompressed && !isRemoteCopyRequired); this applies the same rule to encryption:

  • hoist remoteCallRequired to where isDstCompressed already needs it (one lookup instead of two),
  • targetSize = actualSize on the remote path,
  • skip the two local isTargetEncrypted steps when remoteCallRequired,
  • declare actualSize (not srcInfo.Size) on the forwarded PutObject and in the empty-body checksum special case.

Fixing only the declared length is insufficient (verified as a negative control): SSE → SSE still stores double-encrypted bytes. Both halves are needed.

cmd/object-api-options.go (commit 2): once the stream was correct, every federated copy to an SSE-KMS destination still failed with InvalidArgument (ReadMapCB: expect { or n, but found "). putOptsFromReq passed the parsed kms.Context straight to encrypt.NewSSEKMS(keyID, interface{}). kms.Context implements encoding.TextMarshaler, so the SDK serialized it as a JSON string, and a request without a context still produced one because the nil Context is a typed nil inside the interface and marshals to "{}". The receiving ParseHTTP rejects both. Pass a plain map[string]string, or nothing when no context was requested. dstOpts.ServerSideEncryption is consumed only by the federated CopyObject and CopyObjectPart forwards, so this has no effect on the local path.

Deliberately not changed: sseConfig.Apply (local bucket SSE default / auto-encryption) still runs before the branch. On the remote path it only decides which SSE header is forwarded, which is the existing behaviour; removing it would change semantics and is not needed for the fix.

Tests

TestAPIFederatedCopyObjectSSE (commit 1 → 3) drives the real CopyObjectHandler federation branch through minio-go into a second in-process endpoint over TLS, with a builtin KMS:

  • bodies: 3 bytes, 64 KiB + 1 (two DARE packages), 64 KiB + 1 compressed source;
  • pairs: plain/SSE-S3/SSE-C/SSE-KMS in every corrupting direction, SSE-KMS with an explicit encryption context, distinct SSE-C keys for source and destination;
  • a two-part multipart SSE-S3 source;
  • asserts: copy 200, the returned CRC-64NVME equals the plaintext's, a destination GET returns the exact plaintext and Content-Length, the destination is stored under the requested SSE kind at the single-encryption size, and the source's size/ETag/mtime are unchanged.

On the unpatched baseline every SSE combination fails (500, 400, or 200 with a ciphertext checksum); with the fix all 76 subtests pass on both backends.

setupCopyObjectFederation was refactored into a shared helper with a TLS variant; the existing callers are unchanged.

Verification

  • go build ./..., go vet, golangci-lint run ./cmd/... clean
  • go test -race ./cmd -run '^(TestAPIFederated|TestAPICopyObject|TestAPISSEC|TestAPIPutObject|TestAPIGetObject|TestAPIHeadObject|TestAPINewMultipart|TestAPICompleteMultipart|TestAPIPutObjectPart|TestSSE|TestKMS|TestEncrypt|TestCompress|TestCopyObject)' passes

Operational note

Until this is deployed, any SSE object copied across a federation with HTTP 200 should be treated as suspect: a destination GET that returns the wrong length (e.g. 35 bytes for a 3-byte object) is the double-encryption symptom, and the source is intact and can be re-copied after the upgrade.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FodsDpa6VkghaeRE6WjmEe

Vonng and others added 3 commits September 9, 2026 17:51
The legacy etcd bucket-federation branch of CopyObjectHandler reads its
source through getObjectNInfo, which yields the decrypted and
decompressed bytes, but it also ran the destination encryption locally
and then forwarded that stream to the remote PutObject with the source's
stored size and the destination SSE option. SSE to plain and plain to
SSE therefore failed on a Content-Length mismatch, while SSE to SSE
matched by coincidence: the remote encrypted the ciphertext a second
time and stored an unreadable object, and a destination GET returned
the inner ciphertext with HTTP 200.

The remote write owns the destination's storage transformations, so
hand it the logical bytes at their logical size and let it encrypt
exactly once. Compression was already excluded on this branch; apply
the same rule to encryption, size the forwarded reader by actualSize,
and declare that size on the forwarded PutObject.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FodsDpa6VkghaeRE6WjmEe
Signed-off-by: Feng Ruohang <[email protected]>
putOptsFromReq handed the parsed kms.Context straight to
encrypt.NewSSEKMS. kms.Context implements encoding.TextMarshaler, so the
SDK serialized it as a JSON string, and a request without a context
still produced one because the nil Context is a typed nil inside the
interface value and marshals to "{}". The receiving ParseHTTP rejects
both forms, so every federated CopyObject to an SSE-KMS destination
failed with InvalidArgument once the forwarded stream was correct.

Pass a plain map, or nothing when no context was requested, and cover
SSE-KMS destinations with and without an explicit context.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FodsDpa6VkghaeRE6WjmEe
Signed-off-by: Feng Ruohang <[email protected]>
A multipart SSE-S3 source is encrypted per part, so its logical size is
the sum of the parts' decrypted sizes and the decrypting reader crosses
a part boundary. Copy such a source across the federation to a plain
and to an SSE-S3 destination and check the destination plaintext and
single-encryption size.

The test router registers routes in endpoint order and the plain
PutObject route has no query matcher, so the multipart endpoints are
listed first.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FodsDpa6VkghaeRE6WjmEe
Signed-off-by: Feng Ruohang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Federated CopyObject mishandles SSE-encrypted sources (wrong bytes/length, possible corruption)

1 participant