Skip to content

fix(s3): ListBuckets honours its four request parameters (#884) - #905

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/s3-list-buckets-parameters
Sep 15, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/s3-list-buckets-parameters

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

What was broken

S3 ListBuckets took its request as _ *RequestContext, _ *AWSRequest and 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 only Name and CreationDate per bucket with no Owner element 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.
  • prefix and bucket-region merely 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.

  1. "This needs the Region to be stored at CreateBucket if it is not already, which is the one non-trivial part of this issue." It was already stored. createBucket has always persisted S3Bucket.Region from reqCtx.Region, so bucket-region filters on a value substrate has held all along. The non-trivial part turned out not to exist.

  2. "Each bucket carries BucketRegion and BucketArn." BucketArn is not implemented, deliberately — see Provenance. The Bucket type documents it as directory-bucket-only and ListBuckets does not support directory buckets, so no ListBuckets response AWS produces carries one. Separately, BucketRegion is 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, following emulator/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 in s3_plugin.go.

Refuse rather than clamp. An out-of-range or non-integer max-buckets, and an undecodable or over-long continuation-token, answer 400 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 in docs/services.md, because ListBuckets documents none.

Truncation is decided on the next matching bucket, not on a count reaching the limit. A listing whose last page exactly fills max-buckets therefore 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 s3BucketsOwner type rather than reusing S3Owner. The two differ in exactly the way that matters: S3Owner is the ACL owner and renders DisplayName unconditionally, so adding omitempty to 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.ID is 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, so docs/services.md states 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 in docs/services.md.

Provenance

All quotations are from the official AWS S3 API reference, fetched during this work.

From API_ListBuckets:

  • All four parameters are query-string, per the published Request Syntax:
    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-buckets range: "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-buckets default: "If you specify the bucket-region, prefix, or continuation-token query parameters without using max-buckets to 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-token semantics: "ContinuationToken indicates to Amazon S3 that the list is being continued on this bucket with a token. ContinuationToken is obfuscated and is not a real key. You can use this ContinuationToken for pagination of the list results." / "Length Constraints: Minimum length of 0. Maximum length of 1024. Required: No."
  • Response ContinuationToken is the forward cursor, not an echo: "ContinuationToken is included in the response when there are more buckets that can be listed with pagination. The next ListBuckets request to Amazon S3 can be continued with this ContinuationToken." Examples 2 and 3 show the response value passed straight back as the continuation-token query parameter. The page publishes no NextContinuationToken, unlike ListObjectsV2.
  • prefix: "Limits the response to bucket names that begin with the specified bucket name prefix." Response Prefix: "If Prefix was 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 as us-west-2 … Requests made to a Regional endpoint that is different from the bucket-region parameter 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 no DisplayName.
  • Response element order, from the Response Syntax: Buckets, Owner, ContinuationToken, Prefix.
  • Directory buckets: "This operation is not supported for directory buckets."

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 with ListBuckets not supporting directory buckets, this is why substrate emits no BucketArn — the operation can never be looking at a bucket the member applies to.
  • BucketRegion: "BucketRegion indicates 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 no BucketRegion; 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

  • The error code. API_ListBuckets publishes no Errors section, and ErrorResponses returned an effectively empty body to WebFetch (only the "Amazon S3" heading, no error table). Nothing could be sourced for what AWS returns on an out-of-range max-buckets or an undecodable token. InvalidArgument with 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, in docs/services.md and in CHANGELOG.md.
  • Response ordering. AWS documents no order for ListBuckets. Lexicographic is substrate's reading, consistent with the existing statement in docs/services.md.
  • Whether AWS enforces the Regional-endpoint/bucket-region match. "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 helpers loadBucket, 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 — the ListBuckets row in the hand-written operations table, plus a new ### Listing buckets section 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 real PUT through newS3TestServer and 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 real CreateBucket.

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 for beta- and gamma-). 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 BucketArn even 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-buckets bounding 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); prefix filtering and the conditional Prefix echo in both directions; bucket-region filtering including a Region holding nothing; the filters composing, including paged prefix and paged region; Owner present with DisplayName absent; BucketRegion conditional across four request shapes; BucketArn never emitted; the InvalidArgument refusals; a token past the end; the empty account; and an unfiltered-listing compatibility gate.

Mutation test

The pre-#884 handler was restored verbatim (via cp to /tmp, never git stash) and the suite re-run. 12 of the 16 top-level tests failed, then all passed again after restore:

--- FAIL: TestS3ListBuckets_MaxBucketsBoundsTheResult          (one, three, eight)
--- FAIL: TestS3ListBuckets_ContinuationTokenPagesWithoutRepeatOrOmission
--- FAIL: TestS3ListBuckets_ContinuationTokenIsOpaqueBase64
--- FAIL: TestS3ListBuckets_PrefixFilters                      (all 5 subtests)
--- FAIL: TestS3ListBuckets_BucketRegionFilters                (all 4 subtests)
--- FAIL: TestS3ListBuckets_FiltersCompose                     (all 3 subtests)
--- FAIL: TestS3ListBuckets_OwnerIsReported
--- FAIL: TestS3ListBuckets_BucketRegionIsConditional          (max-buckets, prefix, bucket-region)
--- FAIL: TestS3ListBuckets_RejectsOutOfRangeMaxBuckets        (all 6 subtests)
--- FAIL: TestS3ListBuckets_RejectsMalformedContinuationToken  (all 3 subtests)
--- FAIL: TestS3ListBuckets_TokenBeyondTheEndReturnsNothing
--- FAIL: TestS3ListBuckets_EmptyAccountStillReportsOwner

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_PrefixOmittedWhenNotSent and TestS3ListBuckets_BucketArnIsNeverReported (both assert an element is absent, which the old handler also satisfied), and TestS3ListBuckets_AcceptsTheRangeBounds (valid values were never refused).

A subtlety worth naming: TestS3ListBuckets_BucketRegionIsConditional/no_parameters also 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 test was redirected to a file with $? checked separately, never piped to tail.

Command Result
gofmt -l . && go build ./... && go vet ./... exit 0, no output
golangci-lint run ./... 0 issues.
make test exit 0 — ok github.com/scttfrdmn/substrate/emulator 19.408s
GOTOOLCHAIN=go1.26.6 make test exit 0 — ok … emulator 12.338s
GOTOOLCHAIN=go1.26.6 make coverage exit 0 — emulator 83.9%, total 83.4%
make docs-reference docs-reference-check docs-versions authz-reference-check exit 0 — docs/services.md already up to date (67 plugins)
go vet -C test/e2e ./... && go test -C test/e2e ./... exit 0 — ok github.com/scttfrdmn/substrate/test/e2e 0.722s
npm --prefix docs run build exit 0 — build complete in 1.97s

Coverage holds the baseline exactly (83.9% emulator / 83.4% total). The docs/node_modules symlink was created for the build and removed before committing; git status --porcelain is clean on the commit.

golangci-lint caught three godot violations 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, same Name and CreationDate, and no BucketRegion, because the conditional rule makes an unparameterised listing render exactly what it rendered before. TestS3ListBuckets_UnfilteredListingIsUnchanged is the gate on that. A consumer using a generated AWS SDK is unaffected either way, since Owner is 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-buckets or prefix and 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-buckets outside 1–10000 or non-integer, and a continuation-token that is not decodable base64 or exceeds 1024 characters, now answer 400 InvalidArgument where they previously returned 200 and the full listing. The code is unverified against AWS (see Provenance); a consumer asserting on it should know that.

BucketArn is not available, and per the Bucket type it is not available from real ListBuckets either. 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.

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

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.10526% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/s3_list_buckets.go 92.10% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit ab9baa3 into main Sep 15, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/s3-list-buckets-parameters branch September 15, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

S3 ListBuckets implements none of its request parameters and omits Owner, BucketArn and BucketRegion

1 participant