Skip to content

fix(s3): resolve x-amz-acl and x-amz-grant-* on the operations that create (#470) - #509

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/470-s3-acl-on-create
Aug 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/470-s3-acl-on-create

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #470

Follow-up to #458, which enforced BlockPublicAcls on PutBucketAcl/PutObjectAcl only. The other operations were uncoverable because none of them read x-amz-acl.

What was broken

Two defects, one of which hid the other:

  1. No create operation resolved an ACL. PutObject, CopyObject, CreateMultipartUpload and CreateBucket all discarded x-amz-acl, so GetObjectAcl/GetBucketAcl reported the owner-only default regardless of what the write asked for. A consumer asserting "my upload is publicly readable" saw the default and had no way to tell the header had been dropped.
  2. The x-amz-grant-* family was stored by no operation — including PutBucketAcl and PutObjectAcl, which is wider than the issue title suggests. s3GrantHeadersArePublic parsed the grantee lists for S3: Block Public Access settings are recorded but not enforced #458's check, but nothing persisted them.

Together those left Block Public Access covering two of six operations, because the other four had no ACL to judge. authenticated-read was the hole that mattered: it is public by BPA's own definition ("AuthenticatedUsers group gets READ access"), so a bucket with BlockPublicAcls set could be walked through with one PutObject --acl authenticated-read.

The change

The ACL model moves to a new emulator/s3_acl.go. s3RequestACL returns nil when a request names no ACL, which keeps "named none" distinguishable from "named the default" — the two report identically through GetObjectAcl, and only the distinction lets an overwrite clear a previous ACL without a parallel "was one named" flag threaded through every write path. Grant headers augment the owner's FULL_CONTROL rather than replacing it (replacing it is a lockout, not a grant) and win over a canned header when both are sent.

Six operations now resolve and store an ACL: PutObject, CopyObject, CreateMultipartUpload, CreateBucket, PutBucketAcl, PutObjectAcl.

Block Public Access refuses the three creates before any write, with a copy judged against the destination bucket's configuration. So a refusal leaves no object, no destination object and no open upload — the same all-or-nothing property #468 established on the EC2 side. A CopyObject never inherits the source's ACL; a multipart upload's ACL is fixed at create and applied at completion.

Also fixed in passing: DeleteBucket leaked the bucket_acl: key. The other six S3 per-bucket keys it also leaks are tracked separately.

The account-level question

#470's fourth criterion offers a fork, and this takes the second branch. CreateBucket with a public ACL is still accepted: a bucket-level BPA configuration cannot exist before the bucket does, so the operation is only refusable at the account level, which substrate does not model at all. Inventing one to gate CreateBucket would be modelling a control the emulator otherwise lacks.

The gap is documented in docs/services.md and pinned by a test, with an already-blocked sibling bucket present to rule out cross-bucket leakage. Adding account-level BPA later therefore changes a failing test rather than passing silently in whichever direction the new code happens to take.

Scope notes

Tests

New emulator/s3_acl_test.go (45 subtests) plus five new BPA tests in emulator/s3_publicaccess_test.go:

  • All 8 canned names × bucket and object, each row quoting its documented outcome — three of the eight differ between the two kinds, and log-delivery-write is bucket-only in the table.
  • All 5 grant headers × 4 operations; grantee forms (quoted, unquoted, uri, lists, mixed-case type, empty entries mid-list).
  • The whole-replacement rule: an overwrite naming no ACL clears a previous public grant, including one set by a separate PutObjectAcl.
  • --acl private stores an ACL while no header stores nothing — the assertion that keeps the nil-means-unnamed distinction from collapsing.
  • Every BPA refusal asserts the not-stored half: object absent, destination absent, no upload ID, and a refused overwrite leaving the prior body and ACL intact.
  • CreateMultipartUpload refusal carries a positive control (an accepted upload is listed), so the "nothing left behind" assertion cannot pass vacuously.
  • headerACLCases() filters the existing publicACLCases() rather than re-listing rows, so any case added for S3: Block Public Access settings are recorded but not enforced #458 is automatically exercised against the three creates. A new row covers a private XML body with a public grant header — the one case the standalone grant-header check still uniquely catches.
  • The S3: Block Public Access settings are recorded but not enforced #458 suite passes unchanged, which is S3: PutObject and CreateBucket ignore x-amz-acl, so BlockPublicAcls cannot be enforced on them #470's own final criterion.

Verification

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 clean.

Mutation-tested with 32 mutants: caught=32, survived=0, equivalent=0. The catches include both ordering mutants (store-before-check, drop-the-check), the source-vs-destination swap on copy, both clear-omission mutants, the multipart carry and its persistence, source-ACL inheritance on copy, the authenticated-read regression, both log-delivery-write kind mutants, and every grant-header parsing mutant.

Probed end to end against substrate server with the AWS CLI: put-object --acl public-read on a blocked bucket → AccessDenied with head-object 404; copy-object and create-multipart-upload likewise, with list-multipart-uploads empty; --acl private still accepted; grant headers reported by get-object-acl; an overwrite naming no ACL back to owner-only.

…reate (#470)

Before this change nothing read x-amz-acl on a create: PutObject, CopyObject,
CreateMultipartUpload and CreateBucket all discarded it, so GetObjectAcl and
GetBucketAcl reported the owner-only default no matter what the write asked
for. The x-amz-grant-* family was stored by no operation at all, including
PutBucketAcl and PutObjectAcl, which is wider than #470's title suggests.

That left #458's BlockPublicAcls enforcement covering only the two ACL
operations, because the other four had no ACL to judge. authenticated-read was
the hole that mattered: it is public by Block Public Access's own definition,
so a bucket with BlockPublicAcls set could be walked through with a single
PutObject.

The ACL model moves to emulator/s3_acl.go: s3RequestACL returns nil when a
request names no ACL, which keeps "named none" distinguishable from "named the
default" and is what lets an overwrite clear a previous ACL without a parallel
flag threaded through every write path. Grant headers augment the owner grant
rather than replacing it, and win over a canned header when both are sent.

Block Public Access now refuses PutObject, CopyObject and
CreateMultipartUpload before any write, with a copy judged against the
destination bucket's configuration, so a refusal leaves no object, no
destination object and no open upload. A copy never inherits the source's ACL
and a multipart upload's ACL is fixed at create.

CreateBucket with a public ACL is still accepted: a bucket-level configuration
cannot exist before the bucket does, so the operation is only refusable at the
account level, which substrate does not model. The gap is documented and
pinned by a test so adding account-level Block Public Access later changes a
failing test rather than passing silently in either direction.
@scttfrdmn scttfrdmn added type: bug Something is not working correctly area: s3 Issues relating to the s3 component labels Aug 2, 2026
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.96899% with 31 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/s3_plugin.go 42.59% 14 Missing and 17 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 6fe0f47 into main Aug 2, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/470-s3-acl-on-create 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

area: s3 Issues relating to the s3 component type: bug Something is not working correctly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

S3: PutObject and CreateBucket ignore x-amz-acl, so BlockPublicAcls cannot be enforced on them

1 participant