Repository navigation
fix: forward plaintext on federated CopyObject of SSE objects (#158) - #163
Merged
Merged
Conversation
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]>
Vonng
force-pushed
the
fix/issue-158-federated-copy-sse
branch
from
September 9, 2026 09:51
a458b33 to
25cb351
Compare
This was referenced Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #158.
Problem
In a legacy etcd bucket-federation deployment (
MINIO_ETCD_ENDPOINTSset, noMINIO_ETCD_PATH_PREFIX, soglobalBucketFederationis true), a whole-objectCopyObjectwhose destination bucket lives on another deployment takes the federation branch ofCopyObjectHandlerand forwards the write as acore.PutObjectto that deployment.That branch reads the source through
getObjectNInfo, which yields the decrypted, decompressed bytes, but it then:newEncryptReader/WithEncryption), exactly as the local path does, andsrcInfo.Size, the source's stored size, and withdstOpts.ServerSideEncryption, so the remote encrypted again.Reproduced through the in-process federation fixture against
d1105bbb3(single-part"abc", SSE-S3 ciphertext = 35 bytes):ContentLength=35 with Body length 3, HTTP 500ContentLength=3 with Body length 35, HTTP 500The 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";778e9c864only 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:remoteCallRequiredto whereisDstCompressedalready needs it (one lookup instead of two),targetSize = actualSizeon the remote path,isTargetEncryptedsteps whenremoteCallRequired,actualSize(notsrcInfo.Size) on the forwardedPutObjectand 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 withInvalidArgument (ReadMapCB: expect { or n, but found ").putOptsFromReqpassed the parsedkms.Contextstraight toencrypt.NewSSEKMS(keyID, interface{}).kms.Contextimplementsencoding.TextMarshaler, so the SDK serialized it as a JSON string, and a request without a context still produced one because the nilContextis a typed nil inside the interface and marshals to"{}". The receivingParseHTTPrejects both. Pass a plainmap[string]string, or nothing when no context was requested.dstOpts.ServerSideEncryptionis consumed only by the federatedCopyObjectandCopyObjectPartforwards, 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 realCopyObjectHandlerfederation branch through minio-go into a second in-process endpoint over TLS, with a builtin KMS: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.
setupCopyObjectFederationwas refactored into a shared helper with a TLS variant; the existing callers are unchanged.Verification
go build ./...,go vet,golangci-lint run ./cmd/...cleango test -race ./cmd -run '^(TestAPIFederated|TestAPICopyObject|TestAPISSEC|TestAPIPutObject|TestAPIGetObject|TestAPIHeadObject|TestAPINewMultipart|TestAPICompleteMultipart|TestAPIPutObjectPart|TestSSE|TestKMS|TestEncrypt|TestCompress|TestCopyObject)'passesOperational 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