Repository navigation
fix(s3): resolve x-amz-acl and x-amz-grant-* on the operations that create (#470) - #509
Merged
Merged
Conversation
…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.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Closed
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 #470
Follow-up to #458, which enforced
BlockPublicAclsonPutBucketAcl/PutObjectAclonly. The other operations were uncoverable because none of them readx-amz-acl.What was broken
Two defects, one of which hid the other:
PutObject,CopyObject,CreateMultipartUploadandCreateBucketall discardedx-amz-acl, soGetObjectAcl/GetBucketAclreported 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.x-amz-grant-*family was stored by no operation — includingPutBucketAclandPutObjectAcl, which is wider than the issue title suggests.s3GrantHeadersArePublicparsed 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-readwas the hole that mattered: it is public by BPA's own definition ("AuthenticatedUsersgroup gets READ access"), so a bucket withBlockPublicAclsset could be walked through with onePutObject --acl authenticated-read.The change
The ACL model moves to a new
emulator/s3_acl.go.s3RequestACLreturnsnilwhen a request names no ACL, which keeps "named none" distinguishable from "named the default" — the two report identically throughGetObjectAcl, 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'sFULL_CONTROLrather 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
CopyObjectnever inherits the source's ACL; a multipart upload's ACL is fixed at create and applied at completion.Also fixed in passing:
DeleteBucketleaked thebucket_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.
CreateBucketwith 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 gateCreateBucketwould be modelling a control the emulator otherwise lacks.The gap is documented in
docs/services.mdand 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
emailAddressgrantee is skipped, not stored and not refused. S3 ended support for email grantees as of 2025-10-01 with an HTTP 405, but that is Region-conditional and applies to the XML body form too, so it is filed as S3: an emailAddress grantee is skipped rather than refused with HTTP 405 #507 rather than guessed at. A test pins today's behaviour so S3: an emailAddress grantee is skipped rather than refused with HTTP 405 #507 changes it deliberately.Valid Valueslists differ between operations and no error code is documented for a bad one.Tests
New
emulator/s3_acl_test.go(45 subtests) plus five new BPA tests inemulator/s3_publicaccess_test.go:log-delivery-writeis bucket-only in the table.uri, lists, mixed-case type, empty entries mid-list).PutObjectAcl.--acl privatestores an ACL while no header stores nothing — the assertion that keeps the nil-means-unnamed distinction from collapsing.CreateMultipartUploadrefusal carries a positive control (an accepted upload is listed), so the "nothing left behind" assertion cannot pass vacuously.headerACLCases()filters the existingpublicACLCases()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.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-readregression, bothlog-delivery-writekind mutants, and every grant-header parsing mutant.Probed end to end against
substrate serverwith the AWS CLI:put-object --acl public-readon a blocked bucket →AccessDeniedwithhead-object404;copy-objectandcreate-multipart-uploadlikewise, withlist-multipart-uploadsempty;--acl privatestill accepted; grant headers reported byget-object-acl; an overwrite naming no ACL back to owner-only.