Skip to content

feat(s3): record storage classes and honor CopyObject metadata directives (#398) - #409

Closed
scttfrdmn wants to merge 1 commit into
feat/397-s3-conditional-requestsfrom
feat/398-s3-storage-class
Closed

scttfrdmn wants to merge 1 commit into
feat/397-s3-conditional-requestsfrom
feat/398-s3-storage-class

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #398

Stacked on #408 (#397) — its copyObject precondition work is the insertion point this builds on, so the base is feat/397-s3-conditional-requests. GitHub will retarget this to main when #408 merges; the diff here is #398 only.

What changed

Storage classes are recorded and reported. PutObject, CopyObject and CreateMultipartUpload accept x-amz-storage-class, defaulting to STANDARD when absent. All thirteen documented values are accepted; anything else — including a lowercase or whitespace-padded value — is 400 InvalidStorageClass, raised before the write so a rejected class leaves no object behind. A class set at CreateMultipartUpload survives to the object CompleteMultipartUpload assembles.

The two report surfaces differ, and both directions are easy to get wrong:

Surface STANDARD Every other class
x-amz-storage-class response header on GET/HEAD Omitted Present
<StorageClass> in ListObjects, ListObjectsV2, ListObjectVersions, ListMultipartUploads STANDARD The class

A <DeleteMarker> carries none, matching S3's response shape.

Archived objects are unreadable. 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, so a ranged read of an archived object is the same 403 rather than a 206. GLACIER_IR reads normally.

CopyObject metadata directives. x-amz-metadata-directive and x-amz-tagging-directive are both honored, both defaulting to COPY. Under COPY the destination takes the source's Content-Type, Content-Encoding, user metadata and tags; under REPLACE only what the request restates. An unrecognized directive value is 400 InvalidArgument rather than a silent fall back to the default. The destination's storage class comes from the request, never the source.

Two pre-existing copyObject bugs fall out of this: it had dropped the source's Content-Encoding and 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.

  1. COPY preserves Content-Encoding; the issue has it inverted. The issue asks for a test asserting Content-Encoding is dropped under COPY. The API reference says COPY means "you can preserve all metadata (the default)" and names only x-amz-website-redirect-location as not copied; the User Guide confirms Content-Encoding is user-controlled metadata that a copy carries. The real-world loss the issue describes is reachable — via REPLACE, which drops anything the request does not restate. Both directions are tested.

  2. HeadObject of an archived object is 200, not 403. API_HeadObject.html lists only NoSuchKey under Errors and states "even if the object is stored in S3 Glacier, all object metadata is still available". GetObject's reference does list InvalidObjectState. HEAD succeeding is what lets a consumer discover that a GET needs a restore first, so the asymmetry is load-bearing, not an omission.

  3. A copy does not inherit the source's class. "If the x-amz-storage-class header is not used, the copied object will be stored in the STANDARD Storage Class by default" — so an unqualified copy of a STANDARD_IA object yields a STANDARD one.

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, the x-amz-restore response header, and Intelligent-Tiering archive access tiers (so the InvalidObjectState variant carrying <StorageClass>/<AccessTier> never appears). The issue notes InvalidObjectState alone 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-check all pass. Coverage on the new files: resolveStorageClass, storageClassOf, evaluateStorageClassRead, resolveDirective, resolveCopyMetadata, copyStringMap at 100%, resolveCopyTags at 93%.

New emulator/s3_storage_class_test.go covers: a round-trip per storage class asserting the header and the XML element; the STANDARD default; InvalidStorageClass across four bad forms with the key asserted absent afterwards; the 403 gate with GLACIER_IR/STANDARD_IA/INTELLIGENT_TIERING asserted to read normally; HEAD returning 200 on both archival classes; the ranged-read-of-archived case; multipart class carry-through and up-front validation; <StorageClass> in v1 and v2 listings and in ListObjectVersions with a <DeleteMarker> asserted to have none; the four CopyObject storage-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-tagging rejections.

docs/services.md gains Storage classes and Copying objects sections; CHANGELOG.md is updated under ## [Unreleased].

…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
@scttfrdmn

Copy link
Copy Markdown
Owner Author

Superseded by #419. This PR was closed automatically when its base branch feat/397-s3-conditional-requests was deleted as part of merging #408 — GitHub closes a PR whose base ref disappears rather than retargeting it, and a closed PR cannot have its base changed.

#419 is the same commit rebased onto main. The rebase was clean: #397's content is already in main via #408's squash, so no conflict resolution was involved and the diff is #398 only. Verified after the rebase: gofmt clean, go build, go vet, golangci-lint run ./... 0 issues, make test (race) green, test/e2e green, make docs-reference-check green.

@scttfrdmn
scttfrdmn deleted the feat/398-s3-storage-class branch August 1, 2026 01:13
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.

1 participant