mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-08-19 05:36:58 +00:00
* fix(s3): stop S3 Tables routes from swallowing buckets named "buckets" or "get-table"
The S3 Tables REST endpoints share top-level paths with the regular S3
API (/buckets for ListTableBuckets/CreateTableBucket, /get-table for
GetTable). They are registered first on the same router as the bucket
subrouter, so a path-style request such as GET /buckets?list-type=2 on
a bucket actually named "buckets" matched ListTableBuckets and returned
JSON. AWS SDK V2 (and Hadoop s3a / Spark) then failed XML parsing with
"Unexpected character '{' (code 123) in prolog".
Disambiguate by requiring the AWS V4 credential scope to name the
s3tables service on the colliding routes. Regular S3 SDKs sign with
service=s3, S3 Tables SDKs sign with service=s3tables, and the scope is
present in both the Authorization header and the X-Amz-Credential query
parameter for presigned URLs, so the matcher works for both flavors.
ARN-bearing S3 Tables routes (/buckets/<arn>, /namespaces/<arn>, etc.)
already cannot collide because colons are not valid in bucket names, so
they are left untouched.
* fix(s3): accept AWS JSON RPC content type as S3 Tables intent signal
The Iceberg catalog integration tests send unsigned PUT /buckets with
Content-Type: application/x-amz-json-1.1 to create table buckets. With
only the credential-scope check, those requests fell through to the
regular S3 CreateBucket handler and the suite went red on this branch.
Extend the matcher so a request is recognized as S3 Tables when either:
- its AWS V4 credential scope names SERVICE=s3tables; or
- it carries the canonical AWS JSON RPC 1.1 content type and is
unsigned (a request explicitly signed for SERVICE=s3 still wins).
The regular S3 SDKs do not send application/x-amz-json-1.1, so the
signal is safe for the colliding paths (/buckets, /get-table).
Also add an AWS SDK V2 for Go integration test under
test/s3/sdk_v2_routing/ that drives the SDK's own XML deserializer
against a bucket literally named "buckets" and "get-table" — the SDK
errors before the test asserts if the server returns the wrong body
shape. Wired up via .github/workflows/s3-sdk-v2-routing-tests.yml,
mirroring the etag/acl workflow.
* s3api: extend service matcher to all S3 Tables routes; simplify scope check
- Apply serviceMatcher to every S3 Tables route, not just the bare-path
ones. ARN-bearing paths could otherwise be hit by an S3 object key
that starts with arn:aws:s3tables:..., inside a bucket named
"buckets", "namespaces", "tables", or "tag". One matcher everywhere
closes both collision classes.
- Replace strings.Split + index lookup with strings.Contains for the
credential-scope check. The scope shape is fixed at
AK/DATE/REGION/SERVICE/aws4_request, slashes only delimit components,
and access keys are alphanumeric — so /s3tables/ matches iff SERVICE
is exactly s3tables. Existing unit cases (including the
access-key-substring case) still pass.
- Read the GetObject body in the SDK v2 routing test with io.ReadAll;
the single Read could return short and make the equality check flaky.
* s3api: drop content-type fallback; sign s3 tables harness traffic instead
The content-type fallback in isS3TablesSignedRequest let an anonymous
regular-S3 request whose body type is application/x-amz-json-1.1 hit
an S3 Tables route when the path-style object key happened to be
shaped like an S3 Tables ARN (e.g. PutObject on bucket "buckets"
with key arn:aws:s3tables:.../bucket/foo/policy). Narrow the matcher
back to the AWS V4 credential scope so only requests signed for
SERVICE=s3tables match the S3 Tables routes.
Update the Iceberg catalog test harness — the only caller still
sending unsigned PUT /buckets — to sign with SERVICE=s3tables. The
mini instance runs in default-allow mode, so the signature itself is
not verified; only the credential scope matters for the route match.
Drop the stale unit cases for the JSON-RPC content-type signal and
the routing test that exercised unsigned harness traffic.
159 lines
5.5 KiB
Go
159 lines
5.5 KiB
Go
package s3api
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
// TestIsS3TablesSignedRequest covers the credential-scope parser used to
|
|
// disambiguate S3 Tables REST requests from regular S3 requests on paths
|
|
// the two APIs share (e.g. /buckets, /get-table).
|
|
func TestIsS3TablesSignedRequest(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
auth string
|
|
cred string
|
|
want bool
|
|
}{
|
|
{
|
|
name: "regular S3 auth header",
|
|
auth: "AWS4-HMAC-SHA256 Credential=AKIA/20260101/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-date, Signature=deadbeef",
|
|
want: false,
|
|
},
|
|
{
|
|
name: "S3 Tables auth header",
|
|
auth: "AWS4-HMAC-SHA256 Credential=AKIA/20260101/us-east-1/s3tables/aws4_request, SignedHeaders=host;x-amz-date, Signature=deadbeef",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "S3 Tables presigned query",
|
|
cred: "AKIA/20260101/us-east-1/s3tables/aws4_request",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "regular S3 presigned query",
|
|
cred: "AKIA/20260101/us-east-1/s3/aws4_request",
|
|
want: false,
|
|
},
|
|
{
|
|
name: "unsigned request",
|
|
want: false,
|
|
},
|
|
{
|
|
name: "malformed credential",
|
|
auth: "AWS4-HMAC-SHA256 Credential=AKIA, Signature=zzz",
|
|
want: false,
|
|
},
|
|
{
|
|
name: "service substring in access key must not match",
|
|
auth: "AWS4-HMAC-SHA256 Credential=s3tablesAKIA/20260101/us-east-1/s3/aws4_request, Signature=zzz",
|
|
want: false,
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodGet, "/buckets", nil)
|
|
if tc.auth != "" {
|
|
req.Header.Set("Authorization", tc.auth)
|
|
}
|
|
if tc.cred != "" {
|
|
q := req.URL.Query()
|
|
q.Set("X-Amz-Credential", tc.cred)
|
|
req.URL.RawQuery = q.Encode()
|
|
}
|
|
if got := isS3TablesSignedRequest(req); got != tc.want {
|
|
t.Fatalf("isS3TablesSignedRequest=%v, want %v", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestRouting_ListObjectsV2OnBucketNamedBuckets covers the route collision
|
|
// between regular S3 listObjectsV2 on a bucket named "buckets" and the
|
|
// S3 Tables ListTableBuckets endpoint, both of which use the path /buckets.
|
|
// The credential scope on a regular S3 request is /s3/aws4_request, so the
|
|
// S3 Tables route must reject it and let the bucket subrouter take it,
|
|
// otherwise AWS SDK V2 / s3a clients receive a JSON body in place of the
|
|
// expected XML and fail to parse the response.
|
|
func TestRouting_ListObjectsV2OnBucketNamedBuckets(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
s3a := setupRoutingTestServer(t)
|
|
s3a.registerRouter(router)
|
|
|
|
req, _ := http.NewRequest(http.MethodGet, "/buckets?list-type=2&prefix=logs%2F", nil)
|
|
signRoutingTestRequest(t, req, "", "s3")
|
|
|
|
var match mux.RouteMatch
|
|
if !router.Match(req, &match) {
|
|
t.Fatalf("expected GET /buckets?list-type=2 (signed for s3) to match a route; got no match: %v", match.MatchErr)
|
|
}
|
|
if tmpl, _ := match.Route.GetPathTemplate(); tmpl == "/buckets" {
|
|
t.Fatalf("GET /buckets?list-type=2 signed for service=s3 matched the S3 Tables ListTableBuckets route (Path=%q); it must fall through to the bucket subrouter", tmpl)
|
|
}
|
|
}
|
|
|
|
// TestRouting_S3TablesListTableBucketsStillReachable verifies the matcher
|
|
// does not break legitimate S3 Tables traffic: a request signed for the
|
|
// s3tables service on GET /buckets must still reach ListTableBuckets.
|
|
func TestRouting_S3TablesListTableBucketsStillReachable(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
s3a := setupRoutingTestServer(t)
|
|
s3a.registerRouter(router)
|
|
|
|
req, _ := http.NewRequest(http.MethodGet, "/buckets", nil)
|
|
signRoutingTestRequest(t, req, "", "s3tables")
|
|
|
|
var match mux.RouteMatch
|
|
if !router.Match(req, &match) {
|
|
t.Fatalf("expected GET /buckets (signed for s3tables) to match a route; got no match: %v", match.MatchErr)
|
|
}
|
|
tmpl, _ := match.Route.GetPathTemplate()
|
|
if tmpl != "/buckets" {
|
|
t.Fatalf("GET /buckets signed for service=s3tables matched %q; want the S3 Tables route /buckets", tmpl)
|
|
}
|
|
}
|
|
|
|
// TestRouting_CreateBucketNamedBuckets covers the PUT collision: a PUT
|
|
// /buckets signed for s3 is CreateBucket on the regular S3 API, not
|
|
// CreateTableBucket.
|
|
func TestRouting_CreateBucketNamedBuckets(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
s3a := setupRoutingTestServer(t)
|
|
s3a.registerRouter(router)
|
|
|
|
req, _ := http.NewRequest(http.MethodPut, "/buckets", nil)
|
|
signRoutingTestRequest(t, req, "", "s3")
|
|
|
|
var match mux.RouteMatch
|
|
if !router.Match(req, &match) {
|
|
t.Fatalf("expected PUT /buckets (signed for s3) to match a route; got no match: %v", match.MatchErr)
|
|
}
|
|
if tmpl, _ := match.Route.GetPathTemplate(); tmpl == "/buckets" {
|
|
t.Fatalf("PUT /buckets signed for service=s3 matched the S3 Tables CreateTableBucket route (Path=%q); it must fall through to the bucket subrouter", tmpl)
|
|
}
|
|
}
|
|
|
|
// TestRouting_GetObjectOnBucketNamedGetTable covers the GET /get-table
|
|
// collision: a regular S3 request on a bucket named "get-table" must
|
|
// reach the bucket subrouter, not the S3 Tables GetTable handler.
|
|
func TestRouting_GetObjectOnBucketNamedGetTable(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
s3a := setupRoutingTestServer(t)
|
|
s3a.registerRouter(router)
|
|
|
|
req, _ := http.NewRequest(http.MethodGet, "/get-table?list-type=2", nil)
|
|
signRoutingTestRequest(t, req, "", "s3")
|
|
|
|
var match mux.RouteMatch
|
|
if !router.Match(req, &match) {
|
|
t.Fatalf("expected GET /get-table?list-type=2 (signed for s3) to match a route; got no match: %v", match.MatchErr)
|
|
}
|
|
if tmpl, _ := match.Route.GetPathTemplate(); tmpl == "/get-table" {
|
|
t.Fatalf("GET /get-table signed for service=s3 matched the S3 Tables GetTable route (Path=%q); it must fall through to the bucket subrouter", tmpl)
|
|
}
|
|
}
|