Repository navigation
fix(#1349): name every published S3 sub-resource, so an unrouted one is refused rather than reinterpreted - #1351
Merged
Conversation
…is refused rather than reinterpreted parseS3Operation reached each method's default by absence: any published sub-resource missing from its lists became DeleteBucket, CreateBucket, ListObjects, PutObject or GetObject. DeleteBucketCors, DeleteBucketEncryption, DeleteBucketWebsite, DeleteBucketOwnershipControls and DeleteBucketReplication each deleted the bucket; PutObjectRetention and PutObjectLegalHold overwrote the object with their XML body; GetBucketLocation answered a listing. The name was also what the request was authorized under, so each needed s3:DeleteBucket or s3:PutObject rather than its own action. #446 and #656 fixed one sub-resource at a time. emulator/s3_subresources.go names every published bucket- and object-level sub-resource substrate does not route, and parseS3Operation consults it just before each default, after every routed test, so no routed operation changes name. Each resolves to its real operation and HandleRequest's existing default refuses it as NotImplemented/501, the code S3 publishes. emulator/s3_subresource_routing_test.go drives every unrouted bucket DELETE and requires the bucket to survive, requires the object to survive both object PUTs, and pins the resolved names through ParseAWSRequest beside twenty routed ones. Fixes #1349
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Oct 3, 2026
Closed
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.
Fixes #1349
The bug: data loss from a routing default
parseS3Operationnames every S3 request's operation, for the plugin's switch and for thepipeline's authorization, metering and event log. Each method arm tested a fixed list of sub-resource
keys and otherwise returned its default, so any published sub-resource missing from the list became
a different, routed operation:
DeleteBucketCors,DeleteBucketEncryption,DeleteBucketWebsite,DeleteBucketOwnershipControls,DeleteBucketReplicationDeleteBucketHeadBucket404)PutObjectRetention,PutObjectLegalHoldPutObjectGetBucketLocationListObjectsListBucketResultPutBucketCorsand othersCreateBucketThe resolved name was also the authorized name.
DeleteBucketEncryptionneededs3:DeleteBucket;ListObjectsmaps tos3:ListBucketatauthz.go:840.#446 (
?publicAccessBlock) and #656 (?policy,?acl) each fixed one sub-resource by adding itto the list. The defaults were reached by absence, so the next unlisted name failed the same way.
#1350's S3 wire test found it: its
GetBucketLocationpresence anchor read a listing.The fix: name each unrouted sub-resource for what it is
The new
emulator/s3_subresources.goholds two tables, bucket-level and object-level, mapping(method, sub-resource key)to the real operation name for every published sub-resource substratedoes not route:
metrics, intelligent-tiering), where an
idparam selects Get and its absence selects List; cors;encryption; location; logging; object-lock; ownershipControls; policyStatus; replication;
requestPayment; website; the V1
metadataTableand V2metadataConfigurationfamilies, includingtheir two
PUTupdate operations; andsession(CreateSession).I checked the URI forms of the less common ones (
CreateSession, the metadata tables,intelligent-tiering,
GetObjectAttributes) against the S3 API reference today.parseS3Operationconsults the tables immediately before each default, after every routed test,so no routed operation changes name.
HandleRequest's switch does not route the new names, andits existing default answers
NotImplemented/501, which is S3's own published code. The operationcatalog is generated from that switch, so
operation-catalog-checkandoperation-docs-checksee nochange. Keys are tested for presence only, per the file's #656 convention, since SDKs send
?cors=.Keys are visited in sorted order, so a malformed two-key request always resolves the same way, which
matters for replay.
Tests:
emulator/s3_subresource_routing_test.go, 46 subtests through the real serverDELETE(eleven) is refused with 501 and thebucket still answers
HeadBucket200.PUT ?retentionand?legal-holdare refused, and the object's bytes areunchanged.
GET/PUT/POSTrequests at both levels answer 501.ParseAWSRequest,DELETE /b?encryptionresolves toDeleteBucketEncryption, the id-keyed families split Get/List correctly, and twenty routedforms (
DeleteBucket,ListObjectswithprefix/delimiter,ListObjectsV2withstart-after,PutObject, the tagging operations and others) resolve exactly as before.Negative control (run, then restored)
Removing
encryptionfrom theDELETEtable brings the bug straight back:UnroutedDelete…/DeleteBucketEncryptionfails, because the request is reinterpreted.Resolves…/DELETE /b?encryptionfails, because it resolves toDeleteBucketagain.All existing S3 tests pass unchanged.
Not in this PR
Implementing any of the newly named operations stays with its own issue: CORS is #1278 and encryption
is #493. Both get a comment that they are now refused rather than reinterpreted. #508's sub-resource
cleanup on
DeleteBucketis separate.Verification
All of these pass:
make lint: 0 issues.make test: race,-count=1.docs-reference-check docs-versions version-check discarded-unmarshal-check wire-bookkeeping-check operation-catalog-check operation-docs-check.