Repository navigation
fix(s3): enforce BlockPublicAcls and BlockPublicPolicy (#458) - #466
Merged
Merged
Conversation
#446 made the four Block Public Access settings storable and readable, and nothing acted on any of them. A consumer asserting "once we lock the bucket down, a public ACL is refused" got a green test that verified nothing. A bucket with BlockPublicAcls set now refuses a public ACL on PutBucketAcl and PutObjectAcl; one with BlockPublicPolicy set refuses a public policy on PutBucketPolicy. Both are 403 AccessDenied / "Access Denied", and both check before the write, so a rejection stores nothing and the resource keeps the ACL or policy it had. PutObjectAcl reads the bucket's configuration: Block Public Access has no per-object setting. The policy rule is the substance, and it is inverted from the obvious reading. S3 does not look for a wildcard principal; it assumes the policy is public and then tries to qualify it as non-public, which happens only when access is granted solely to fixed values -- no wildcard, no IAM policy variable -- through the Principal or a Condition on one of the documented keys. So Principal: "*" narrowed by StringLike aws:SourceVpc: "vpc-*" is public, where StringEquals aws:SourceVpc: "vpc-91237329" is not. Only an Allow can make a policy public, and one surviving public statement makes the whole policy public. The aws:SourceIp breadth rule (broader than /8 IPv4, /32 IPv6, RFC1918 excluded) and the s3:DataAccessPointArn wildcard carve-out are implemented too. A public ACL is one granting any permission to AllUsers or AuthenticatedUsers, matched on the grantee URI, across all three forms it arrives in: the x-amz-acl canned header, an XML Grant, and an x-amz-grant-* header. The grant headers were previously unread anywhere in substrate and are parsed for this check only. IgnorePublicAcls and RestrictPublicBuckets stay recorded-only: both govern how an incoming request is evaluated rather than which write is refused, and substrate has no unauthenticated or cross-account request path to deny. PutObject and CreateBucket are not covered, since neither reads x-amz-acl at all. An unconfigured bucket and an all-false configuration behave exactly as before, which is the case that guards #446.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Aug 2, 2026
Merged
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 #458
#446 made the four Block Public Access settings storable and readable, and nothing acted on any of them. A consumer asserting "once we lock the bucket down, a public ACL is refused" got a green test that verified nothing — the assertion would have to be written a second time before it ever ran against AWS.
What changed
BlockPublicAclsPutBucketAcl,PutObjectAclwith a public ACL403 AccessDenied/Access DeniedBlockPublicPolicyPutBucketPolicywith a public policy403 AccessDenied/Access DeniedBoth check before the write, so a rejection stores nothing and the resource keeps the ACL or policy it already had — "existing policies and ACLs for buckets and objects aren't modified". Deleting the configuration re-allows what it was refusing.
PutObjectAclreads the bucket's configuration: "Amazon S3 doesn't support block public access settings on a per-object basis".The policy rule is inverted from the obvious reading
This is the substance of the change. S3 does not look for a wildcard principal — it "begins by assuming that the policy is public. It then evaluates the policy to determine whether it qualifies as non-public", which happens only when access is granted solely to fixed values (no
*, no?, no${...}policy variable) through thePrincipalor aConditionon one of the documented keys.Principal: "*", no conditionPrincipal: "*"+StringLike aws:SourceVpc: "vpc-*"Principal: "*"+StringEquals aws:SourceVpc: "vpc-91237329"Principal: {"AWS": "arn:aws:iam::123456789012:root"}Principal: {"AWS": "arn:aws:iam::123456789012:user/*"}Principal: "*"+aws:SourceIp: "203.0.113.0/24"Principal: "*"+aws:SourceIp: "0.0.0.0/1"/8, no wildcard character in sightEffect: Deny,Principal: "*"Also implemented: the
aws:SourceIpbreadth rule ("broader than/8for IPv4 and/32for IPv6, excluding RFC1918 private ranges") vianet/netip, and thes3:DataAccessPointArncarve-out where a wildcard access-point name does not make a bucket policy public as long as the account ID is fixed. Only anAllowcan make a policy public, and one surviving public statement makes the whole policy public — the guide's worked example, where a single public statement disables an otherwise-legal cross-account grant.Public ACLs
Any permission granted to
AllUsersorAuthenticatedUsers, matched on the grantee URI, with the permission not inspected (WRITE_ACPcounts as much asREAD).AuthenticatedUsersis every AWS account rather than every account in yours, which is why it counts despite the name and why it can only arrive through an XML body — the canned-ACL resolver never emits it.All three documented forms are covered: the
x-amz-aclcanned header, an XMLGrantnaming a public group, and anx-amz-grant-*header whose grantee list contains one. The grant headers were previously unread anywhere in substrate; they are parsed for this check only, so an ACL set through them is still not stored (separate gap).Provenance
None of
PutBucketAcl,PutObjectAclorPutBucketPolicydocuments an Errors section covering this, so theAccessDenied/Access Denied/403triple comes from observed real-AWS behavior, not the API model — a blockedPutBucketPolicysurfaces through the CLI asAn error occurred (AccessDenied) when calling the PutBucketPolicy operation: Access Denied. The definitions of "public" are quoted from the user guide's Blocking public access → The meaning of "public", fetched and read rather than recalled.Deliberately not covered
IgnorePublicAclsandRestrictPublicBucketsstay recorded-only. Both govern how an incoming request is evaluated against an ACL or policy already in place rather than which write is refused, and substrate has no unauthenticated or cross-account request path to deny — every request it serves is already the bucket owner's.PutObjectandCreateBucketwith a public ACL are not refused, because neither handler readsx-amz-aclat all. Covering them means modelling ACL-on-create first; follow-up to be filed.s3:action and would go stale silently.PutBucketPolicyalready rejects non-JSON with400 MalformedPolicy, and the new check is not a second validity check.Tests
emulator/s3_publicaccess_test.go, 88 subtests. The ACL cases run against bothPutBucketAclandPutObjectAclfrom one table; the policy table has 30 rows.The gate on not regressing #446: an unconfigured bucket, an all-false configuration, and one setting only the other three settings all accept every public ACL and a public policy exactly as before enforcement existed. Also asserted — nothing is stored on rejection (read back through
GetBucketAcl/GetBucketPolicy), the existence checks still run first (NoSuchBucket, not the newAccessDenied),MalformedPolicystill fires at 400 rather than being displaced by the 403, deleting the configuration re-allows a public ACL, and one bucket's configuration does not govern another's.Mutation testing
24 mutants, all caught. Three survived the first pass and each pointed at a real gap:
/8reading the exclusion cannot change an IPv4 answer, since the broadest private range is10.0.0.0/8and the bound already admits it. It is load-bearing for IPv6, where unique-local isfc00::/7. Added anfd00::/8case and rewrote the doc comment, which had claimed the IPv4 rationale.{"not":"a policy"}, which unmarshals fine into an emptyPolicyDocument. Added{"Version":..., "Statement":"nope"}— a JSON object that clearsMalformedPolicybut genuinely fails to unmarshal as a policy.Principalcounts as fixedAllowstatement with noPrincipal; it must be public, which is the assume-public direction and the alternative would let a caller bypass the block by omitting the field.Verification
From the repo root:
gofmt -l .clean,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issues,make test(race) green,make docs-reference-check docs-versionsgreen,go test -C test/e2e ./...ok.The plan's consumer sequence, run end to end:
Docs:
docs/services.md§Block Public Access — the "settings are recorded, not enforced" paragraph is replaced with what is now enforced, the assume-public-then-qualify rule with thevpc-*example and the policy table, the ACL rule, and each of the four things above that stays uncovered with its reason. TheS3PublicAccessBlockConfigurationdoc comment, which stated the opposite, is updated too.