Repository navigation
feat(s3): record the server-side-encryption headers and echo them (#492) - #506
Merged
Merged
Conversation
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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
6 tasks
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.
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-idandx-amz-server-side-encryption-bucket-key-enabledare recorded onPutObjectandCreateMultipartUpload, and echoed on those two responses plusGetObject,HeadObjectandCompleteMultipartUpload— 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.goholds anS3ServerSideEncryptionstruct embedded in bothS3ObjectandS3MultipartUpload, followingS3SystemMetadata: one declaration, so the two write paths cannot drift the way #406's did, andCompleteMultipartUploadcarries the family across in a single assignment. Echo goes throughobjectResponseHeaders, already the single placeGetObjectandHeadObjectbuild 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, aCopyObjectasymmetry, four rejected combinations — so it stays out for the same reasonContent-Typeand 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 indocs/services.md, so modelling key resolution later has to revisit it rather than silently overtake it.Absent stays absent, not
falseor empty. A write that never mentioned the bucket-key header produces no header. Verified through the real AWS CLI:ServerSideEncryptionis entirely missing from an unencrypted object'shead-objectoutput, andBucketKeyEnabledis absent rather thanfalse.Reads use
headerValueFold, not canonical-case map access — matching every otherx-amzread in the plugin, because in-process requests frombetty_cfn.gonever 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
CopyObjectrecords 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-objectreportsaws:kms,alias/mineverbatim andBucketKeyEnabled: 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.