Skip to content

feat(s3): record the server-side-encryption headers and echo them (#492) - #506

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/492-s3-sse
Aug 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/492-s3-sse

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #492.

The three server-side-encryption headers were accepted and discarded, so an object written with encryption read back byte-identical to one written without it. A consumer could only assert on what their own request carried — which verifies the line that filled in the request and nothing about the stored object. Every one of those request assertions is now a stored-object assertion.

What changed

x-amz-server-side-encryption, x-amz-server-side-encryption-aws-kms-key-id and x-amz-server-side-encryption-bucket-key-enabled are recorded on PutObject and CreateMultipartUpload, and echoed on those two responses plus GetObject, HeadObject and CompleteMultipartUpload — all five are documented response headers in the API reference.

No cryptography is performed. The body is stored exactly as it arrived. Encryption at rest is not observable through an API call, but the encryption S3 reports for an object is, and that report is the assertion a consumer is making.

New emulator/s3_sse.go holds an S3ServerSideEncryption struct embedded in both S3Object and S3MultipartUpload, following S3SystemMetadata: one declaration, so the two write paths cannot drift the way #406's did, and CompleteMultipartUpload carries the family across in a single assignment. Echo goes through objectResponseHeaders, already the single place GetObject and HeadObject build headers.

Multipart encryption is fixed at create, because Complete's request accepts only the SSE-C headers.

Decisions worth reviewing

SSE gets its own struct rather than joining S3SystemMetadata. Both #475 and #493 flag this as a real question. That family is defined by being recorded and echoed with no rules of its own; SSE has resolution rules coming in #493 — a bucket default, a CopyObject asymmetry, four rejected combinations — so it stays out for the same reason Content-Type and the storage class did. Stated in the type's doc comment.

The KMS key ID round-trips verbatim. Real S3 resolves any of the four accepted forms (bare UUID, alias/name, key ARN, alias ARN) to the key ARN — its own response doc says the header "indicates the ID of the KMS key that was used". Substrate returns the string the caller sent, because that is what their configuration produced and therefore the assertion they are making; #475's reporter confirms their tests assert the sent form. Documented as a divergence beside the field and in docs/services.md, so modelling key resolution later has to revisit it rather than silently overtake it.

Absent stays absent, not false or empty. A write that never mentioned the bucket-key header produces no header. Verified through the real AWS CLI: ServerSideEncryption is entirely missing from an unencrypted object's head-object output, and BucketKeyEnabled is absent rather than false.

Reads use headerValueFold, not canonical-case map access — matching every other x-amz read in the plugin, because in-process requests from betty_cfn.go never pass through net/http canonicalization. Header values are not folded: an algorithm token and a KMS alias are case-sensitive identifiers, and folding either would corrupt the verbatim round-trip. The bucket-key flag is the exception, being a boolean.

Scope boundary against #493, pinned by tests

CopyObject records no encryption rather than inheriting the source's, and nothing is validated. Both are stated gaps with tests, so #493 changes them deliberately — silently inheriting is the live bug #475 found twice, and it is the easiest thing for a later change to introduce. Bucket default encryption is likewise out: adding it would erase the absent-versus-set distinction this half exists to create. SSE-C is out entirely.

Verification

14 new tests (41 with subtests) in emulator/s3_sse_test.go, including the state-round-trip read straight out of the store — a header echo alone would pass without persisting anything.

Mutation-tested with a 26-mutant harness: 26 caught, 0 survived, 0 needing an equivalence exemption. It covers resolving the key ID to an ARN, folding the algorithm or a mixed-case alias, each of the three emit conditions, each header-name typo, all four capture/carry sites, all four echo sites, dropping the JSON tags, un-embedding the struct, and both #493 behaviours (inheriting on copy, defaulting to AES256). The mixed-case-alias test row was added because the first run found a real gap: every other row was lowercase, so folding the key ID on the way in survived.

From the repo root: gofmt -l, go build ./..., go vet ./..., golangci-lint run ./... (0 issues), make test (race), make docs-reference docs-reference-check docs-versions, npm --prefix docs run build, go test -C test/e2e ./... — all green.

End-to-end through the real AWS CLI: put-object --server-side-encryption aws:kms --ssekms-key-id alias/mine --bucket-key-enabled → head-object reports aws:kms, alias/mine verbatim and BucketKeyEnabled: true; an unencrypted object reports no SSE keys at all; the multipart create → part → complete → head chain carries a key ARN through unchanged; a copy reports none.

New docs/services.md §"Server-side encryption" covers the recorded headers, the echo sites, the verbatim key-ID divergence, and what #493 owns. Cross-referenced from the six affected operation rows.

The three SSE headers were accepted and discarded, so an object written with
encryption read back byte-identical to one written without it. A consumer could
only assert on what their own request carried, which verifies the line that
filled in the request and nothing about the stored object.

Record x-amz-server-side-encryption, the KMS key ID and the bucket-key flag on
PutObject and CreateMultipartUpload; echo them on those responses plus
GetObject, HeadObject and CompleteMultipartUpload. No cryptography — encryption
at rest is not observable through an API call, but the encryption S3 reports
for an object is, and that report is the assertion a consumer is making.

The family is one embedded declaration shared by the object and upload records,
following S3SystemMetadata, so the two write paths cannot drift the way #406's
did. It stays out of that family deliberately: SSE has resolution rules coming
in #493, the way Content-Type and the storage class have their own.

The KMS key ID round-trips verbatim, as a stated divergence — real S3 resolves
any of the four accepted forms to the key ARN, and substrate returns the string
the caller sent, because that is the string their configuration produced.

An absent header stays absent rather than false or empty, so "no encryption
named" remains distinguishable from "encryption named". CopyObject records none
rather than inheriting the source's, and nothing is validated; both are pinned
by tests so #493 changes them on purpose.
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.22642% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/s3_plugin.go 94.87% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit ee413b0 into main Aug 2, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/492-s3-sse branch August 2, 2026 21:58
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.

S3: record the SSE headers on write and echo them on GetObject/HeadObject

1 participant