Repository navigation
feat(s3): record storage classes and honor CopyObject metadata directives (#398) - #419
Merged
Merged
Conversation
…ives (#398) x-amz-storage-class was discarded on every write and reported nowhere, so a consumer implementing lifecycle transitions could not observe the one thing a transition changes -- and the classes real S3 refuses to serve looked exactly like the ones it serves instantly. - PutObject, CopyObject and CreateMultipartUpload accept x-amz-storage-class, defaulting to STANDARD. All thirteen documented values are accepted; anything else is 400 InvalidStorageClass, raised before the write. - Reported as x-amz-storage-class on GET/HEAD (omitted for STANDARD, per the response-header reference) and as <StorageClass> in ListObjects, ListObjectsV2, ListObjectVersions and ListMultipartUploads, where unlike the header it is emitted for every class. - GetObject of a GLACIER or DEEP_ARCHIVE object is 403 InvalidObjectState, as is a CopyObject naming one as its source. The check precedes the Range step. GLACIER_IR reads normally -- it is the instant-retrieval tier. - HeadObject of an archived object is 200, not 403, departing from the issue as filed: HeadObject documents no InvalidObjectState and states that "even if the object is stored in S3 Glacier, all object metadata is still available". - CopyObject honors x-amz-metadata-directive and x-amz-tagging-directive, both defaulting to COPY, with an unrecognized value a 400 rather than a silent fall back. COPY takes the source's Content-Type, Content-Encoding, user metadata and tags; REPLACE takes only what the request restates. - The destination's storage class comes from the request, never the source. Fixes CopyObject silently dropping the source's Content-Encoding and tags, and aliasing the destination's metadata maps to the source's. Closes #398
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Jul 31, 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.
Closes #398
Reopens #409, which GitHub closed when its base branch (
feat/397-s3-conditional-requests, the #397 work now merged as #408) was deleted on merge. A closed PR cannot be retargeted, so this is the same commit rebased ontomain. The rebase was clean — #397's content is already inmainvia the squash — and the diff here is #398 only.What changed
Storage classes are recorded and reported.
PutObject,CopyObjectandCreateMultipartUploadacceptx-amz-storage-class, defaulting toSTANDARDwhen absent. All thirteen documented values are accepted; anything else — including a lowercase or whitespace-padded value — is400 InvalidStorageClass, raised before the write so a rejected class leaves no object behind. A class set atCreateMultipartUploadsurvives to the objectCompleteMultipartUploadassembles.The two report surfaces differ, and both directions are easy to get wrong:
STANDARDx-amz-storage-classresponse header on GET/HEAD<StorageClass>inListObjects,ListObjectsV2,ListObjectVersions,ListMultipartUploadsSTANDARDA
<DeleteMarker>carries none, matching S3's response shape.Archived objects are unreadable.
GetObjectof aGLACIERorDEEP_ARCHIVEobject is403 InvalidObjectState, as is aCopyObjectnaming one as its source. The check precedes theRangestep, so a ranged read of an archived object is the same403rather than a206.GLACIER_IRreads normally.CopyObjectmetadata directives.x-amz-metadata-directiveandx-amz-tagging-directiveare both honored, both defaulting toCOPY. UnderCOPYthe destination takes the source'sContent-Type,Content-Encoding, user metadata and tags; underREPLACEonly what the request restates. An unrecognized directive value is400 InvalidArgumentrather than a silent fall back to the default. The destination's storage class comes from the request, never the source.Two pre-existing
copyObjectbugs fall out of this: it had dropped the source'sContent-Encodingand object tags on every copy, and it aliased the destination's metadata maps to the source's, so retagging one object mutated the other.Three deviations from the issue text
Each is a case where the AWS reference contradicts the issue, so implementing the issue as written would have made a test pass here and fail against AWS. Full quotes are in the issue comment.
COPYpreservesContent-Encoding; the issue has it inverted. The issue asks for a test assertingContent-Encodingis dropped underCOPY. The API reference saysCOPYmeans "you can preserve all metadata (the default)" and names onlyx-amz-website-redirect-locationas not copied; the User Guide confirmsContent-Encodingis user-controlled metadata that a copy carries. The real-world loss the issue describes is reachable — viaREPLACE, which drops anything the request does not restate. Both directions are tested.HeadObjectof an archived object is200, not403.API_HeadObject.htmllists onlyNoSuchKeyunder Errors and states "even if the object is stored in S3 Glacier, all object metadata is still available".GetObject's reference does listInvalidObjectState.HEADsucceeding is what lets a consumer discover that aGETneeds a restore first, so the asymmetry is load-bearing, not an omission.A copy does not inherit the source's class. "If the
x-amz-storage-classheader is not used, the copied object will be stored in theSTANDARDStorage Class by default" — so an unqualified copy of aSTANDARD_IAobject yields aSTANDARDone.Also accepted beyond the issue's list:
OUTPOSTS,SNOW,FSX_OPENZFS,FSX_ONTAP. Rejecting a value real S3 takes is the same class of defect as accepting one it rejects.Not implemented
RestoreObject, thex-amz-restoreresponse header, and Intelligent-Tiering archive access tiers (so theInvalidObjectStatevariant carrying<StorageClass>/<AccessTier>never appears). The issue notesInvalidObjectStatealone unblocks the reporter. Restoring is modeled by copying to a non-archival class.Verification
make test(race),golangci-lint run ./...(0 issues),make e2e,make docs-reference-checkall pass. Coverage on the new files:resolveStorageClass,storageClassOf,evaluateStorageClassRead,resolveDirective,resolveCopyMetadata,copyStringMapat 100%,resolveCopyTagsat 93%.New
emulator/s3_storage_class_test.gocovers: a round-trip per storage class asserting the header and the XML element; theSTANDARDdefault;InvalidStorageClassacross four bad forms with the key asserted absent afterwards; the403gate withGLACIER_IR/STANDARD_IA/INTELLIGENT_TIERINGasserted to read normally;HEADreturning200on both archival classes; the ranged-read-of-archived case; multipart class carry-through and up-front validation;<StorageClass>in v1 and v2 listings and inListObjectVersionswith a<DeleteMarker>asserted to have none; the fourCopyObjectstorage-class transitions; the in-place transition end to end; both directives in both modes including the alias check; and the malformed-directive and malformed-x-amz-taggingrejections.docs/services.mdgains Storage classes and Copying objects sections;CHANGELOG.mdis updated under## [Unreleased].