mirror of
https://github.com/hanzoai/s3.git
synced 2026-10-30 14:59:09 +00:00
hanzoai/s3 was an AGPL-3.0 MinIO fork whose network-copyleft blocks embedding
and reselling as a managed service. Replace it wholesale with a fork of
SeaweedFS (github.com/seaweedfs/seaweedfs, Apache-2.0, Go) which ships a
built-in S3 gateway + Filer.
- License: AGPL-3.0 -> Apache-2.0 (upstream LICENSE kept verbatim, incl.
"Copyright 2025 Chris Lu"); NOTICE added crediting SeaweedFS. No AGPL/BUSL/
SSPL/GPL or enterprise ("ee") files remain.
- Module: go.mod path set to github.com/hanzoai/s3 with a self-replace
(replace github.com/seaweedfs/seaweedfs => ./) so the ~1800 internal Go files
keep their upstream import paths with zero churn. Internal identifiers and
import paths are intentionally NOT renamed.
- CLI rebrand: the binary is built as `s3` (was `weed`); root usage, per-command
help/usage/flag strings, shell autocomplete program name, and the product name
in CLI output now read "Hanzo S3" / `s3`. Users never see `weed`.
(e.g. `s3 server`, `s3 filer`, `s3 master`, `s3 volume`, `s3 s3`, `s3 mount`.)
- Build: `make` (or `go build -o s3 ./weed`) builds the `s3` binary green;
`cmd/weed-db` and `cmd/weed-sql` also build; `go vet ./weed/command/` clean.
- README/LLM.md rewritten for Hanzo S3; AGENTS.md/CLAUDE.md symlinks preserved.
- Dropped a 33MB prebuilt Mach-O `stress` binary upstream had committed; `.gitignore`
updated to ignore the `s3` build output.
132 lines
5.0 KiB
Go
132 lines
5.0 KiB
Go
package s3api
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go/service/s3"
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAccountForUnscopedIdentity(t *testing.T) {
|
|
assert.Equal(t, "alice", accountForUnscopedIdentity("alice").Id, "a named identity gets its own account id")
|
|
assert.NotEqual(t, AccountAdmin.Id, accountForUnscopedIdentity("alice").Id, "a named identity must not inherit the admin account")
|
|
assert.Same(t, &AccountAdmin, accountForUnscopedIdentity(AccountAdmin.Id), "the conventional admin keeps the admin account")
|
|
assert.Same(t, &AccountAdmin, accountForUnscopedIdentity(""), "an empty name falls back to the admin account")
|
|
}
|
|
|
|
func TestUnscopedIdentitiesGetDistinctAccounts(t *testing.T) {
|
|
resetMemoryStore()
|
|
|
|
config := `{
|
|
"identities": [
|
|
{"name": "alice", "credentials": [{"accessKey": "alice_ak", "secretKey": "alice_sk"}], "actions": ["Read"]},
|
|
{"name": "admin", "credentials": [{"accessKey": "admin_ak", "secretKey": "admin_sk"}], "actions": ["Admin"]}
|
|
]
|
|
}`
|
|
tmp, err := os.CreateTemp("", "s3-config-*.json")
|
|
require.NoError(t, err)
|
|
defer os.Remove(tmp.Name())
|
|
_, err = tmp.WriteString(config)
|
|
require.NoError(t, err)
|
|
require.NoError(t, tmp.Close())
|
|
|
|
iam := NewIdentityAccessManagementWithStore(&S3ApiServerOption{Config: tmp.Name()}, nil, "memory")
|
|
|
|
alice, _, found := iam.LookupByAccessKey("alice_ak")
|
|
require.True(t, found)
|
|
require.NotNil(t, alice.Account)
|
|
assert.Equal(t, "alice", alice.Account.Id, "a non-admin account-less identity owns resources as itself, not as admin")
|
|
|
|
admin, _, found := iam.LookupByAccessKey("admin_ak")
|
|
require.True(t, found)
|
|
require.NotNil(t, admin.Account)
|
|
assert.Equal(t, AccountAdmin.Id, admin.Account.Id, "the admin identity keeps the admin account")
|
|
}
|
|
|
|
// A distinct non-owner is denied an admin-owned bucket (iam nil => isUserAdmin
|
|
// false, so only real ownership grants access).
|
|
func TestCheckAccessByOwnershipDeniesNonOwner(t *testing.T) {
|
|
adminOwner := AccountAdmin.Id
|
|
s3a := &S3ApiServer{
|
|
bucketRegistry: &BucketRegistry{
|
|
metadataCache: map[string]*BucketMetaData{
|
|
"b": {Name: "b", Owner: &s3.Owner{ID: &adminOwner}},
|
|
},
|
|
notFound: map[string]struct{}{},
|
|
},
|
|
}
|
|
|
|
nonOwner := httptest.NewRequest(http.MethodGet, "/b?ownershipControls=", nil)
|
|
nonOwner.Header.Set(s3_constants.AmzAccountId, "alice")
|
|
assert.Equal(t, s3err.ErrAccessDenied, s3a.checkAccessByOwnership(nonOwner, "b"), "a distinct non-owner is denied the admin-owned bucket")
|
|
|
|
owner := httptest.NewRequest(http.MethodGet, "/b?ownershipControls=", nil)
|
|
owner.Header.Set(s3_constants.AmzAccountId, AccountAdmin.Id)
|
|
assert.Equal(t, s3err.ErrNone, s3a.checkAccessByOwnership(owner, "b"), "the actual owner is still allowed")
|
|
}
|
|
|
|
// An account-less identity's synthesized account must be registered in the
|
|
// account lookup so its id resolves to a display name. Otherwise ACL grantee
|
|
// validation and owner display report the id as "not exists" — the regression
|
|
// where a canned PutObjectAcl granting to the caller's own account returned
|
|
// 400 InvalidRequest.
|
|
func TestUnscopedIdentityAccountResolvesByName(t *testing.T) {
|
|
resetMemoryStore()
|
|
|
|
config := `{
|
|
"identities": [
|
|
{"name": "alice", "credentials": [{"accessKey": "alice_ak", "secretKey": "alice_sk"}], "actions": ["Read", "Write"]}
|
|
]
|
|
}`
|
|
tmp, err := os.CreateTemp("", "s3-config-*.json")
|
|
require.NoError(t, err)
|
|
defer os.Remove(tmp.Name())
|
|
_, err = tmp.WriteString(config)
|
|
require.NoError(t, err)
|
|
require.NoError(t, tmp.Close())
|
|
|
|
iam := NewIdentityAccessManagementWithStore(&S3ApiServerOption{Config: tmp.Name()}, nil, "memory")
|
|
|
|
assert.Equal(t, "alice", iam.GetAccountNameById("alice"),
|
|
"account-less identity id must resolve to a display name for ACL/owner validation")
|
|
}
|
|
|
|
// When an account is explicitly configured with the same id an account-less
|
|
// identity would synthesize, the identity must reuse that configured account so
|
|
// its custom display name/email are preserved.
|
|
func TestUnscopedIdentityReusesConfiguredAccount(t *testing.T) {
|
|
resetMemoryStore()
|
|
|
|
config := `{
|
|
"accounts": [
|
|
{"id": "alice", "displayName": "Alice Smith", "emailAddress": "[email protected]"}
|
|
],
|
|
"identities": [
|
|
{"name": "alice", "credentials": [{"accessKey": "alice_ak", "secretKey": "alice_sk"}], "actions": ["Read"]}
|
|
]
|
|
}`
|
|
tmp, err := os.CreateTemp("", "s3-config-*.json")
|
|
require.NoError(t, err)
|
|
defer os.Remove(tmp.Name())
|
|
_, err = tmp.WriteString(config)
|
|
require.NoError(t, err)
|
|
require.NoError(t, tmp.Close())
|
|
|
|
iam := NewIdentityAccessManagementWithStore(&S3ApiServerOption{Config: tmp.Name()}, nil, "memory")
|
|
|
|
assert.Equal(t, "Alice Smith", iam.GetAccountNameById("alice"),
|
|
"explicitly configured account display name must be preserved")
|
|
|
|
alice, _, found := iam.LookupByAccessKey("alice_ak")
|
|
require.True(t, found)
|
|
require.NotNil(t, alice.Account)
|
|
assert.Equal(t, "Alice Smith", alice.Account.DisplayName,
|
|
"identity must reuse the configured account, not the synthesized one")
|
|
}
|