Repository navigation
Description
Symptom
aws-sdk-go-v2's PutBucketPolicy is routed as CreateBucket, and DeleteBucketPolicy as DeleteBucket — so a consumer clearing a bucket policy silently destroys the bucket and everything in it. The same fall-through affects every ?acl operation.
Found while writing the AWS Config e2e journey for #580: PutBucketPolicy on an existing bucket answered 409 BucketAlreadyExists, which is CreateBucket's error, not PutBucketPolicy's.
Cause
s3Route (emulator/s3_plugin.go:260, :263, :285, :301, :304, :351, :370) tests these subresources with req.Params["policy"] == "1". The "1" is the sentinel parseRequest (emulator/parser.go:52-67) assigns to a bare query key — ?policy with no =.
The SDK does not send a bare key. Captured against an httptest server with aws-sdk-go-v2/service/s3 v1.107.0:
PUT /b RawQuery="policy=" <- PutBucketPolicy
GET /b RawQuery="policy=" <- GetBucketPolicy
DELETE /b RawQuery="policy=" <- DeleteBucketPolicy
PUT /b RawQuery="acl=" <- PutBucketAcl
GET /b RawQuery="acl=" <- GetBucketAcl
GET /b RawQuery="tagging=" <- GetBucketTagging
GET /b RawQuery="versioning=" <- GetBucketVersioning
?policy= is a key with an empty value, not a bare key, so the sentinel is never applied and Params["policy"] == "". The comparison against "1" fails and the switch falls through to its default:
| SDK call | routed as | consequence |
|---|---|---|
PutBucketPolicy |
CreateBucket |
policy never stored; 409 BucketAlreadyExists |
DeleteBucketPolicy |
DeleteBucket |
the bucket is deleted |
GetBucketPolicy |
ListObjectsV2 (GET fall-through) |
wrong shape |
PutBucketAcl |
CreateBucket |
ACL never stored |
GetBucketAcl |
ListObjectsV2 |
wrong shape |
tagging, versioning, notification, lifecycle and publicAccessBlock are unaffected: those sites use if _, ok := req.Params[...]; ok, which matches presence regardless of value. Only the seven == "1" sites are wrong, and all seven are in s3_plugin.go.
Why unit tests did not catch it
Every S3 unit test builds the request by hand and sets Params{"policy": "1"}, i.e. asserts the sentinel the SDK never sends. That is the #561/#610/#636 class in a new guise: the code path is fully covered and unreachable from a real client. The v0.101.0 Config work used Params{"policy": "1"} in its CFN test harness for the same reason and so was equally blind.
Fix
Test presence, not the sentinel, at all seven sites — if _, ok := req.Params["policy"]; ok — matching the style already used for the other subresources. A subresource marker is meaningful when present; its value never carries information, so comparing against any particular value is wrong regardless of which value the SDK happens to send.
Acceptance criteria
- All seven
== "1"comparisons ins3Routetest presence instead. - A unit test asserts routing from a request whose
Paramscarry""for these keys — the shape the SDK actually sends — so the sentinel assumption cannot come back. - An e2e journey (
test/e2e/, real SDK) coversPutBucketPolicy→GetBucketPolicy→DeleteBucketPolicy, and asserts the bucket still exists after the delete. - Same for
PutBucketAcl/GetBucketAcl. - Audit the repo for any other
Params[...] == "1"comparison. (Checked at filing time: the seven ins3_plugin.goare the only ones.) -
CHANGELOG.mdFixed entry naming the data-loss path explicitly, since a consumer who ranDeleteBucketPolicyagainst an affected version lost bucket contents.
Activity
fix(s3): a subresource marker routes on presence, not on a sentinel v…
fix(#1349): name every published S3 sub-resource, so an unrouted one …