Repository navigation
fix(s3): a subresource marker routes on presence, not on a sentinel value (#656) - #657
Merged
Merged
Conversation
…alue (#656) S3 routes bucket-policy and ACL operations on a query-string marker, and substrate compared that marker against the "1" sentinel parser.go assigns to *bare* query keys. aws-sdk-go-v2 does not send a bare key: it sends "?policy=", a key with an empty value, which the sentinel is never applied to. Seven comparisons therefore failed on every request a real client made, and each fell through to its arm's default: PutBucketPolicy -> CreateBucket (409 BucketAlreadyExists) GetBucketPolicy -> ListObjectsV2 DeleteBucketPolicy -> DeleteBucket PutBucketAcl -> CreateBucket GetBucketAcl -> ListObjectsV2 PutObjectAcl -> PutObject (overwrites the object) GetObjectAcl -> GetObject DeleteBucketPolicy is data loss: clearing a policy destroyed the bucket. On a bucket holding objects the misroute surfaced as BucketNotEmpty; on an empty one it answered 204, byte for byte what a correct DeleteBucketPolicy returns, so only a later call revealed the bucket was gone. Every S3 unit test passed throughout, because each hand-built Params{"policy": "1"} -- the one shape no client sends. The rule adopted here is that a subresource marker is tested for presence and never for a value: it carries no information beyond being there, and its wire shape is the client's choice. list-type stays a value test, being the one query key whose value genuinely selects the operation. Coverage goes to the levels that can see the difference: through Server.ServeHTTP in both marker shapes, a value-insensitivity assertion over nine markers and five values, and e2e journeys through the real SDK -- one of which exists solely to reach the silent case and assert an emptied bucket is still standing after its policy is cleared. Verified against a live server with the AWS CLI. Mutation-tested 5/5 caught.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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 #656
The defect
S3 routes bucket-policy and ACL operations on a query-string marker —
?policy,?acl— andemulator/s3_plugin.gocompared that marker against the"1"sentinelparser.goassigns to bare query keys. aws-sdk-go-v2 does not send a bare key. It sends?policy=— a key with an empty value — which the sentinel is never applied to.Captured from aws-sdk-go-v2
service/s3v1.107.0 against an httptest server:So the comparison failed on every request a real client made, and seven operations fell through to their arm's default:
PutBucketPolicyCreateBucket→409 BucketAlreadyExistsGetBucketPolicyListObjectsV2DeleteBucketPolicyDeleteBucketPutBucketAclCreateBucket→409GetBucketAclListObjectsV2PutObjectAclPutObject— overwrites the object with the ACL request's empty bodyGetObjectAclGetObjectDeleteBucketPolicyis data loss. A consumer clearing a bucket policy destroyed the bucket. On a bucket holding objects the misroute at least surfaced asBucketNotEmpty; on an empty bucket it answered204— byte for byte what a correctDeleteBucketPolicyreturns — so nothing in the response distinguished the two and only a later call revealed the bucket was gone.Why no test caught it
Every S3 unit test passed throughout. Each one hand-built
Params{"policy": "1"}, so the suite asserted the routing worked for the one request shape no client sends. This is the #446 class and the #561/#610/#636 class at once: a path only a real client exercises cannot be pinned by a test that builds the request itself.The fix
All seven comparisons become presence tests, under a block comment stating the invariant: a subresource marker is tested for presence, never for a value. A marker carries no information beyond being there, and its wire shape is the client's choice, not substrate's.
list-typeis the sole exception and stays a value test, because2genuinely selectsListObjectsV2.Coverage, at the levels that can see the difference
emulator/s3_subresource_routing_test.go— throughServer.ServeHTTP, so the parser produces the params:HeadBucketthat asserts the bucket survived (a misrouted delete answers 204 either way, so only a later call distinguishes the data-loss path)PutObjectAcllist-typecounter-case, asserting"","1"and"3"are notListObjectsV2test/e2e/journey_s3_bucket_policy_test.go— through the real SDK, the tier that found this.TestS3_DeleteBucketPolicyLeavesAnEmptyBucketStandingis separate on purpose: in the full lifecycle the misroute is stopped byBucketNotEmptybefore the survival assertion is reached, so the silent case needs its own path to it.Verification
Full gate green:
gofmt/build/vet/golangci-lint(0 issues),make test(race),make coverage(emulator82.7%), docs targets,npm --prefix docs run build,test/e2e.Each new test was confirmed to fail against the pre-fix code, including the silent path with only the DELETE-arm sentinel restored.
Live-server check with the real AWS CLI (
AWS_MAX_ATTEMPTS=1): policy put/get/delete round trip, thepublic-readgrant reflected inGetBucketAcl, the bucket standing afterDeleteBucketPolicy, andNoSuchBucketPolicyon the follow-up read.Mutation testing: 5 mutants, 5 CAUGHT, 0 survivors — four sentinel restorations plus one flattening
list-typeto a presence test. The last survived the first version ofTestS3_ListTypeIsStillValueSensitive, which only covered=2and absence; extending it to other values caught it.