Repository navigation
fix(s3): ListBuckets honours its four request parameters (#884) - #905
Merged
Merged
Conversation
The handler took its request as `_ *AWSRequest` and implemented none of max-buckets, continuation-token, prefix or bucket-region, and omitted Owner and BucketRegion from the response. max-buckets bounds the page over the documented 1-10000 range with a 10000 default; an out-of-range value is refused rather than clamped. continuation-token pages over the lexicographic bucket-name order StateManager.List guarantees (#865); ContinuationToken is returned only when the listing was truncated. prefix filters by name and is echoed. bucket-region filters on the Region CreateBucket already stored. Owner is unconditional with ID set to the account ID. BucketRegion is conditional on the request naming a parameter, per the Bucket type. BucketArn is deliberately not reported: it is documented as supported for directory buckets only, which ListBuckets does not support.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
7 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.
What was broken
S3 ListBucketstook its request as_ *RequestContext, _ *AWSRequestand implemented none of the operation's four query parameters. It returned every bucket in the account, unfiltered and unpaged, whatever the caller asked for, and its response carried onlyNameandCreationDateper bucket with noOwnerelement at all.The paging pair is the sharp end, because a dropped parameter there is invisible in the response:
max-buckets— a caller asking for 10 buckets and receiving 500 sees a well-formed answer. A short page and a complete listing are the same shape, so there is no signal that the parameter was ignored.continuation-token— worse, because it is wrong in a loop. Page two was page one, so a paging caller either spun forever or silently processed the same buckets twice.prefixandbucket-regionmerely over-returned, which a consumer can at least notice.Stale premises in the issue
Two of the issue's claims did not survive contact with the tree or the AWS reference. Both are implemented as the documentation says rather than as the issue asked.
"This needs the Region to be stored at
CreateBucketif it is not already, which is the one non-trivial part of this issue." It was already stored.createBuckethas always persistedS3Bucket.RegionfromreqCtx.Region, sobucket-regionfilters on a value substrate has held all along. The non-trivial part turned out not to exist."Each bucket carries
BucketRegionandBucketArn."BucketArnis not implemented, deliberately — see Provenance. TheBuckettype documents it as directory-bucket-only andListBucketsdoes not support directory buckets, so noListBucketsresponse AWS produces carries one. Separately,BucketRegionis conditional rather than unconditional, which the issue did not mention.The line reference in the issue (
emulator/s3_plugin.go:420-455) was accurate at the time of writing.Design decisions
A new
emulator/s3_list_buckets.go, followingemulator/iam_list_policies.go: a file-level why preamble, then the validation consts, the wire types, the handler and its private helpers. A pointer comment sits where the handler used to live ins3_plugin.go.Refuse rather than clamp. An out-of-range or non-integer
max-buckets, and an undecodable or over-longcontinuation-token, answer400 InvalidArgument. The reasoning is the defect's own: silently substituting a value the caller did not ask for is invisible in a well-formed response, which is exactly what made the original bug undetectable. The token case is the sharper one — treating an undecodable token as "no cursor" restarts the listing, which is the non-terminating loop this issue describes rather than merely a wrong answer.Pagination is a cursor over
StateManager.List's lexicographic order (#865), which is why that sort had to land first: a cursor over an unstable order both omits and repeats members between pages. The order itself remains substrate's reading, labelled as such in the code comment and indocs/services.md, becauseListBucketsdocuments none.Truncation is decided on the next matching bucket, not on a count reaching the limit. A listing whose last page exactly fills
max-bucketstherefore reports no token. Emitting one would cost a paging caller a round trip to an empty page, and AWS ties the token to there being "more buckets that can be listed" rather than to a full page.A private
s3BucketsOwnertype rather than reusingS3Owner. The two differ in exactly the way that matters:S3Owneris the ACL owner and rendersDisplayNameunconditionally, so addingomitemptyto it would change every ACL response. This was caught by a test, not by inspection — the first run emitted<DisplayName></DisplayName>, a shape AWS never returns.Owner.IDis the account ID. Substrate has no account-owner concept beyond it. Real S3 returns a 64-character hex canonical user ID unrelated to the account number, sodocs/services.mdstates that a consumer must not read the value as one; the account ID is the only account-scoped identifier substrate holds and it stays stable across a replay, which a synthesized one would not.The Regional-endpoint restriction is not enforced. AWS says requests to an endpoint differing from
bucket-region"are not supported" but names no error code, so refusing would mean inventing one. Recorded as deliberately unenforced indocs/services.md.Provenance
All quotations are from the official AWS S3 API reference, fetched during this work.
From
API_ListBuckets:GET /?bucket-region={{BucketRegion}}&continuation-token={{ContinuationToken}}&max-buckets={{MaxBuckets}}&prefix={{Prefix}}The page heads the section "URI Request Parameters — The request uses the following URI parameters."
max-bucketsrange: "Maximum number of buckets to be returned in response. When the number is more than the count of buckets that are owned by an AWS account, return all the buckets in response." / "Valid Range: Minimum value of 1. Maximum value of 10000."max-bucketsdefault: "If you specify thebucket-region,prefix, orcontinuation-tokenquery parameters without usingmax-bucketsto set the maximum number of buckets returned in the response, Amazon S3 applies a default page size of 10,000 and provides a continuation token if there are more buckets."continuation-tokensemantics: "ContinuationTokenindicates to Amazon S3 that the list is being continued on this bucket with a token.ContinuationTokenis obfuscated and is not a real key. You can use thisContinuationTokenfor pagination of the list results." / "Length Constraints: Minimum length of 0. Maximum length of 1024. Required: No."ContinuationTokenis the forward cursor, not an echo: "ContinuationTokenis included in the response when there are more buckets that can be listed with pagination. The nextListBucketsrequest to Amazon S3 can be continued with thisContinuationToken." Examples 2 and 3 show the response value passed straight back as thecontinuation-tokenquery parameter. The page publishes noNextContinuationToken, unlikeListObjectsV2.prefix: "Limits the response to bucket names that begin with the specified bucket name prefix." ResponsePrefix: "IfPrefixwas sent with the request, it is included in the response. All bucket names in the response begin with the specified bucket name prefix."bucket-region: "Limits the response to buckets that are located in the specified AWS Region. The AWS Region must be expressed according to the AWS Region code, such asus-west-2… Requests made to a Regional endpoint that is different from thebucket-regionparameter are not supported."Owner: "The owner of the buckets listed. Type: Owner data type." Rendered in all five published examples, always as<Owner><ID>AIDACKCEVSQ6C2EXAMPLE</ID></Owner>with noDisplayName.Buckets,Owner,ContinuationToken,Prefix.From
API_Bucket:BucketArn: "The Amazon Resource Name (ARN) of the S3 bucket. ARNs uniquely identify AWS resources across all of AWS. This parameter is only supported for S3 directory buckets." / "Length Constraints: Minimum length of 1. Maximum length of 128. Pattern:arn:[^:]+:(s3|s3express):.*Required: No." Combined withListBucketsnot supporting directory buckets, this is why substrate emits noBucketArn— the operation can never be looking at a bucket the member applies to.BucketRegion: "BucketRegionindicates the AWS region where the bucket is located. If the request contains at least one valid parameter, it is included in the response." Borne out by the examples: the unpaginated Example 1 shows noBucketRegion; Examples 2–5, each passing a parameter, all show one.From
API_Owner:ID: "Container for the ID of the owner. Type: String. Required: No."DisplayName: carries no description at all — the page renders an empty description followed by "Type: String. Required: No." That, plus its absence from every example, is why substrate omits it.Unverified
API_ListBucketspublishes noErrorssection, andErrorResponsesreturned an effectively empty body toWebFetch(only the "Amazon S3" heading, no error table). Nothing could be sourced for what AWS returns on an out-of-rangemax-bucketsor an undecodable token.InvalidArgumentwith HTTP 400 is substrate's reading, chosen because it is what S3 uses elsewhere for a malformed query-parameter value. Labelled unverified in the code comment, indocs/services.mdand inCHANGELOG.md.ListBuckets. Lexicographic is substrate's reading, consistent with the existing statement indocs/services.md.bucket-regionmatch. "Are not supported" names no error code; substrate does not enforce it.Files
emulator/s3_list_buckets.go— new. Preamble,s3MaxBucketsLimit/s3MaxBucketsDefault/s3ContinuationTokenMaxLength, the wire types (s3BucketEntry,s3ListAllMyBucketsResult,s3BucketsOwner),listBuckets, and the helpersloadBucket,s3ListBucketsOwnerFor,parseS3ListBucketsParams.emulator/s3_plugin.go— old handler removed, replaced by a pointer comment to the new file.emulator/s3_list_buckets_test.go— new, 16 tests.docs/services.md— theListBucketsrow in the hand-written operations table, plus a new### Listing bucketssection citing#884.CHANGELOG.md—## [Unreleased]/### Fixed.Tests
16 tests in
package emulator_test, table-driven where there is a table. Every bucket is created with a realPUTthroughnewS3TestServerand every listing read off the raw wire response, per #765 — no test writes state directly. A regional path-style host (s3.<region>.amazonaws.com) is what puts the Region on the wire, so the stored Region comes from a realCreateBucket.The fixture creates nine buckets across three Regions, named so the prefix groups and Region groups cut across each other (
alpha-one/us-east-1,alpha-two/us-west-2,alpha-three/eu-west-1, and likewise forbeta-andgamma-). Filtering by one dimension must not imply the other, and a filter that silently ignored its parameter returns three times as many buckets.The decode target deliberately declares
BucketArneven though substrate never emits it: asserting a field is absent needs somewhere for it to land, and a struct without the field would unmarshal an unexpected element into nothing and pass.Coverage:
max-bucketsbounding including both range endpoints and the exactly-full-page case; a full nine-bucket walk three at a time asserting no repeat and no omission; token opacity (base64, not a bare name);prefixfiltering and the conditionalPrefixecho in both directions;bucket-regionfiltering including a Region holding nothing; the filters composing, including paged prefix and paged region;Ownerpresent withDisplayNameabsent;BucketRegionconditional across four request shapes;BucketArnnever emitted; theInvalidArgumentrefusals; a token past the end; the empty account; and an unfiltered-listing compatibility gate.Mutation test
The pre-#884 handler was restored verbatim (via
cpto/tmp, nevergit stash) and the suite re-run. 12 of the 16 top-level tests failed, then all passed again after restore:The four that passed against the old handler are the deliberate compatibility and negative gates, and their passing is the correct result:
TestS3ListBuckets_UnfilteredListingIsUnchanged(an unparameterised listing is unchanged by this PR),TestS3ListBuckets_PrefixOmittedWhenNotSentandTestS3ListBuckets_BucketArnIsNeverReported(both assert an element is absent, which the old handler also satisfied), andTestS3ListBuckets_AcceptsTheRangeBounds(valid values were never refused).A subtlety worth naming:
TestS3ListBuckets_BucketRegionIsConditional/no_parametersalso passes against the old handler, for the same absence reason — the failing subtests are the three that pass a parameter.Verification
Every command run from the worktree root.
make testwas redirected to a file with$?checked separately, never piped totail.gofmt -l . && go build ./... && go vet ./...golangci-lint run ./...0 issues.make testok github.com/scttfrdmn/substrate/emulator 19.408sGOTOOLCHAIN=go1.26.6 make testok … emulator 12.338sGOTOOLCHAIN=go1.26.6 make coveragemake docs-reference docs-reference-check docs-versions authz-reference-checkdocs/services.md already up to date (67 plugins)go vet -C test/e2e ./... && go test -C test/e2e ./...ok github.com/scttfrdmn/substrate/test/e2e 0.722snpm --prefix docs run buildbuild complete in 1.97sCoverage holds the baseline exactly (83.9% emulator / 83.4% total). The
docs/node_modulessymlink was created for the build and removed before committing;git status --porcelainis clean on the commit.golangci-lintcaught threegodotviolations on comments ending in a closing quote (the linter wants the period outside it) — fixed by moving the period out, which also reads better for a quotation.Compatibility
A caller that passes no parameters sees one addition: an
<Owner>element. The bucket list itself is unchanged — same members, same lexicographic order, sameNameandCreationDate, and noBucketRegion, because the conditional rule makes an unparameterised listing render exactly what it rendered before.TestS3ListBuckets_UnfilteredListingIsUnchangedis the gate on that. A consumer using a generated AWS SDK is unaffected either way, sinceOwneris a modelled member it already knows.A caller that passes parameters now gets what it asked for, which is a behavioural change in the direction of correctness but a change nonetheless. Anything that passed
max-bucketsorprefixand relied on receiving the whole account regardless will now receive a page or a filtered set. Nothing could have depended on that deliberately, since the response gave no indication the parameters were dropped.Newly refused requests.
max-bucketsoutside 1–10000 or non-integer, and acontinuation-tokenthat is not decodable base64 or exceeds 1024 characters, now answer400 InvalidArgumentwhere they previously returned200and the full listing. The code is unverified against AWS (see Provenance); a consumer asserting on it should know that.BucketArnis not available, and per theBuckettype it is not available from realListBucketseither. A consumer needing a bucket ARN must construct it, as it must against AWS.No state format changed, so no recorded event log or existing state store is invalidated by this PR.
Closes #884.