mirror of
https://github.com/versity/versitygw.git
synced 2026-09-22 07:54:14 +00:00
Closes #2322 The admin API could not be served under a path prefix. Admin requests are SigV4-signed over the full path, so a reverse proxy or Gateway API route cannot strip a prefix before forwarding. That made it impossible to serve the WebUI and the admin API under one hostname. The new `--admin-path-prefix` (`VGW_ADMIN_PATH_PREFIX`) option mounts the admin routes under a single-segment prefix such as `/admin`, on `--admin-port` or, when that is unset, on the S3 port. Admin clients include the prefix in their endpoint URL, which the admin CLI and the WebUI already support. The prefix is limited to unreserved characters, because clients and the gateway encode other characters differently when signing. When the admin API shares the S3 port, the prefix must also differ from `--webui-s3-prefix`, otherwise the WebUI mount answers the admin requests. Auto-detected WebUI admin gateway URLs and the startup banner now include the prefix. The admin routes served on the S3 port now reuse `S3AdminRouter` instead of a duplicated route list. This also stops the standalone admin server from recording bucket creation under the `ActionAdminListBuckets` action. The Helm chart now exposes `webui.pathPrefix`, `webui.s3Prefix` and `admin.pathPrefix`. The WebUI gateway lists are also passed when only `webui.s3Prefix` is set, since the WebUI hosted on the S3 port does not require `webui.enabled`. Internal IAM data can now live on its own volume. `iam.dir` sets the IAM directory, and `iam.persistence` creates or references a dedicated PVC when `iam.enabled` is true and `iam.type` is `internal`. Otherwise IAM data stays in the `iam` subdirectory of the backend data volume, so existing releases are unaffected. The chart now rejects overlapping storage directories. `iam.dir` must be an absolute path outside `/mnt/data`, `gateway.backend.sidecarDir` and `gateway.backend.versioningDir`, and those three directories must not overlap each other. Deleting a bucket removes `<dir>/<bucket>` from the sidecar and versioning directories, so with nested directories, deleting a suitably named bucket could wipe IAM accounts, object versions or the entire backend data directory.
137 lines
4.5 KiB
Go
137 lines
4.5 KiB
Go
// Copyright 2026 Versity Software
|
|
// This file is licensed under the Apache License, Version 2.0
|
|
// (the "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing,
|
|
// software distributed under the License is distributed on an
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
// KIND, either express or implied. See the License for the
|
|
// specific language governing permissions and limitations
|
|
// under the License.
|
|
|
|
package s3api
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
|
|
"github.com/gofiber/fiber/v3"
|
|
"github.com/versity/versitygw/auth"
|
|
"github.com/versity/versitygw/backend"
|
|
"github.com/versity/versitygw/s3api/controllers"
|
|
"github.com/versity/versitygw/s3api/middlewares"
|
|
)
|
|
|
|
func TestAdminPathPrefix(t *testing.T) {
|
|
servers := []struct {
|
|
name string
|
|
newApp func(t *testing.T, prefix string) *fiber.App
|
|
}{
|
|
{name: "standalone admin server", newApp: newTestAdminApp},
|
|
{name: "admin on s3 server", newApp: newTestS3AdminApp},
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
prefix string
|
|
path string
|
|
handled bool
|
|
}{
|
|
{name: "no prefix", prefix: "", path: "/list-buckets", handled: true},
|
|
{name: "prefixed route", prefix: "/admin", path: "/admin/list-buckets", handled: true},
|
|
{name: "prefixed route with trailing slash", prefix: "/admin", path: "/admin/list-buckets/", handled: true},
|
|
{name: "root route with prefix set", prefix: "/admin", path: "/list-buckets", handled: false},
|
|
{name: "other prefix", prefix: "/admin", path: "/adminx/list-buckets", handled: false},
|
|
}
|
|
|
|
for _, srv := range servers {
|
|
for _, tt := range tests {
|
|
t.Run(srv.name+"/"+tt.name, func(t *testing.T) {
|
|
app := srv.newApp(t, tt.prefix)
|
|
resp, err := app.Test(signedAdminRequest(t, tt.path))
|
|
if err != nil {
|
|
t.Fatalf("app.Test: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
// BackendUnsupported answers a signed, routed list-buckets call with 501.
|
|
handled := resp.StatusCode == http.StatusNotImplemented
|
|
if handled != tt.handled {
|
|
t.Fatalf("PATCH %s with prefix %q: status %d, want handled=%v", tt.path, tt.prefix, resp.StatusCode, tt.handled)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAdminPathPrefixExtraRoutes(t *testing.T) {
|
|
srv := NewAdminServer(backend.BackendUnsupported{}, testAdminRoot, "us-east-1", testAdminIAM(), nil, controllers.S3ApiController{},
|
|
WithAdminConcurrencyLimiter(10, 10),
|
|
WithAdminQuiet(),
|
|
WithAdminPathPrefix("/admin"),
|
|
WithAdminRoute(http.MethodGet, "/extra", func(ctx fiber.Ctx) error {
|
|
return ctx.SendStatus(http.StatusNoContent)
|
|
}),
|
|
)
|
|
|
|
for path, want := range map[string]bool{"/admin/extra": true, "/extra": false} {
|
|
resp, err := srv.app.Test(httptest.NewRequest(http.MethodGet, path, nil))
|
|
if err != nil {
|
|
t.Fatalf("app.Test %s: %v", path, err)
|
|
}
|
|
resp.Body.Close()
|
|
if got := resp.StatusCode == http.StatusNoContent; got != want {
|
|
t.Errorf("GET %s: status %d, want handled=%v", path, resp.StatusCode, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
var testAdminRoot = middlewares.RootUserConfig{Access: "access", Secret: "secret"}
|
|
|
|
func testAdminIAM() auth.IAMService {
|
|
return auth.NewIAMServiceSingle(auth.Account{Access: testAdminRoot.Access, Secret: testAdminRoot.Secret})
|
|
}
|
|
|
|
func newTestAdminApp(t *testing.T, prefix string) *fiber.App {
|
|
t.Helper()
|
|
srv := NewAdminServer(backend.BackendUnsupported{}, testAdminRoot, "us-east-1", testAdminIAM(), nil, controllers.S3ApiController{},
|
|
WithAdminConcurrencyLimiter(10, 10),
|
|
WithAdminQuiet(),
|
|
WithAdminPathPrefix(prefix),
|
|
)
|
|
return srv.app
|
|
}
|
|
|
|
func newTestS3AdminApp(t *testing.T, prefix string) *fiber.App {
|
|
t.Helper()
|
|
srv, err := newTestS3ApiServer(WithQuiet(), WithAdminServer(), WithAdminServerPathPrefix(prefix))
|
|
if err != nil {
|
|
t.Fatalf("new s3 server: %v", err)
|
|
}
|
|
return srv.app
|
|
}
|
|
|
|
func signedAdminRequest(t *testing.T, path string) *http.Request {
|
|
t.Helper()
|
|
sum := sha256.Sum256(nil)
|
|
payloadHash := hex.EncodeToString(sum[:])
|
|
|
|
req := httptest.NewRequest(http.MethodPatch, "http://localhost"+path, nil)
|
|
req.Header.Set("X-Amz-Content-Sha256", payloadHash)
|
|
creds := aws.Credentials{AccessKeyID: testAdminRoot.Access, SecretAccessKey: testAdminRoot.Secret}
|
|
if err := v4.NewSigner().SignHTTP(context.Background(), creds, req, payloadHash, "s3", "us-east-1", time.Now()); err != nil {
|
|
t.Fatalf("sign request: %v", err)
|
|
}
|
|
return req
|
|
}
|