mirror of
https://github.com/versity/versitygw.git
synced 2026-09-25 09:24:22 +00:00
feat: add standalone IAM support in WebGUI
Gates bucket listing behind an identity policy, lets browsers reach the standalone IAM API, and turns the WebUI into a dashboard for S3, IAM, or both.
**Bucket listing.** `ListBuckets` is now gated by the new `s3:ListAllMyBuckets` action, evaluated against `arn:aws:s3:::*`. The request names no bucket, so only identity policies apply — there is no resource policy to combine with, which is the same shape `CreateBucket` already had, so both now share one identity-only evaluation path. Root and admin bypass it, and backends with no identity-policy layer keep listing as before since their listing is already narrowed to the caller's own buckets. The action is IAM-only and is deliberately absent from the bucket-policy action list.
**Fixed bucket ownership.** The standalone IAM client has no per-user ownership to express — accounts are all plain users, cannot be enumerated, and access is decided by policy rather than ACL — so it now implements `auth.FixedBucketOwner` and every bucket is owned by root. Bucket creation stops resolving an owner, `ListBuckets` returns every bucket to every caller (what they may then do with one stays a per-request policy decision), and the admin `ChangeBucketOwner` reports method-not-supported. Other IAM backends are untouched.
**IAM service CORS.** `--cors-allow-origin` now applies to the `iam` command: it answers preflights and stamps the CORS headers, mirroring back the requested method and headers rather than enumerating the SigV4 header set. Without it no browser can reach the IAM API at all, so setting `--webui` without it falls back to `*` with a warning. The chart gets `iamServer.corsAllowOrigin`.
**WebUI.** New IAM pages for users, roles and OIDC providers, signing IAM/STS query-form requests directly from the browser. Navigation is capability-gated rather than role-gated: on sign-in the session probes the S3, admin and IAM endpoints independently and each page shows only what those credentials actually reach, so one build serves an IAM-only dashboard, an S3-only dashboard, and a combined one. The login page takes an optional IAM endpoint, seeded from the new `--webui-iam-gateways` (chart: `webui.iamGateways`) — never auto-detected, since the IAM service is a separate process. The WebUI can also be hosted by `versitygw iam` itself, for deployments with no S3 gateway behind it.
**The admin API is ignored once an IAM endpoint is in play.** The IAM service is then the user directory and bucket ownership is fixed, which leaves the admin API no job: the session is given no admin endpoint at all, its login field is hidden, `users.html` redirects to its IAM counterpart, and every admin-only surface stays off screen. Dashboard and Buckets remain available to any S3 session in such a deployment, running on the S3 and IAM APIs alone and surfacing each denial per action instead of redirecting.
Also fixes two WebUI bugs: embedded assets went out with a zero modification time and no `Cache-Control`, so browsers treated them as fresh for centuries and an upgraded gateway served new HTML against stale JS — they now revalidate against an ETag; and the login page's advanced-options section clipped its last field, since it animated to a height named in the stylesheet rather than the one it measures now.
**Usage**
IAM-only dashboard, served by the IAM service:
versitygw iam --port :7076 --webui :8080 --cors-allow-origin http://localhost:8080/
IAM + S3, dashboard served by the IAM service — point it at the gateway with `--webui-gateways`, and let the gateway accept the dashboard's origin:
versitygw iam --port :7076 --webui :8080 --webui-gateways http://localhost:7070/ --cors-allow-origin http://localhost:8080/
versitygw --port :7070 --cors-allow-origin http://localhost:8080/ posix /data
IAM + S3, dashboard served by the S3 gateway — point it at the IAM service with `--webui-iam-gateways`, and let the IAM service accept the dashboard's origin:
versitygw --port :7070 --webui :8080 --webui-iam-gateways http://localhost:7076/ posix /data
versitygw iam --port :7076 --cors-allow-origin http://localhost:8080/
This commit is contained in:
+32
-7
@@ -556,11 +556,37 @@ func VerifyCreateBucketAccess(ctx fiber.Ctx, iam IAMService, isRoot bool, acc Ac
|
||||
return s3err.GetAPIError(s3err.ErrAccessDenied)
|
||||
}
|
||||
|
||||
resourceArn := ResourceArnPrefix + bucket
|
||||
return verifyIdentityOnlyAccess(ctx, pe, acc, CreateBucketAction, bucket)
|
||||
}
|
||||
|
||||
// VerifyListAllMyBucketsAccess decides whether acc may list buckets. The
|
||||
// request names no bucket, so only identity policies apply: an Allow for
|
||||
// s3:ListAllMyBuckets on "arn:aws:s3:::*", the ARN AWS's own bucket-listing
|
||||
// policy names. Backends with no identity-policy layer already narrow the
|
||||
// listing to the caller's own buckets, so they need no permission of their own.
|
||||
func VerifyListAllMyBucketsAccess(ctx fiber.Ctx, iam IAMService, isRoot bool, acc Account) error {
|
||||
if isRoot || acc.Role == RoleAdmin {
|
||||
return nil
|
||||
}
|
||||
|
||||
pe, hasPolicyEvaluator := iam.(PolicyEvaluator)
|
||||
if !hasPolicyEvaluator {
|
||||
return nil
|
||||
}
|
||||
|
||||
return verifyIdentityOnlyAccess(ctx, pe, acc, ListAllMyBucketsAction, "*")
|
||||
}
|
||||
|
||||
// verifyIdentityOnlyAccess decides one action from the caller's identity
|
||||
// policies alone, for requests naming no existing bucket and therefore no
|
||||
// resource-based policy. resource is the ARN part after "arn:aws:s3:::": a
|
||||
// bucket name for CreateBucket, "*" for an account-level action.
|
||||
func verifyIdentityOnlyAccess(ctx fiber.Ctx, pe PolicyEvaluator, acc Account, action Action, resource string) error {
|
||||
resourceArn := ResourceArnPrefix + resource
|
||||
identity, err := identityPolicyDecisions(pe, AccessOptions{
|
||||
Acc: acc,
|
||||
Bucket: bucket,
|
||||
Actions: []Action{CreateBucketAction},
|
||||
Bucket: resource,
|
||||
Actions: []Action{action},
|
||||
}, []string{""}, nil, requestConditionContext(ctx))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -572,8 +598,7 @@ func VerifyCreateBucketAccess(ctx fiber.Ctx, iam IAMService, isRoot bool, acc Ac
|
||||
}
|
||||
|
||||
// A session policy narrows what the session may do; there is no resource
|
||||
// policy for a bucket that does not exist yet, so the two decisions
|
||||
// simply intersect here.
|
||||
// policy to combine with here, so the two decisions simply intersect.
|
||||
decision := identity.Decisions[0].Decision
|
||||
if identity.HasSessionPolicy {
|
||||
switch sd := identity.SessionDecisions[0].Decision; {
|
||||
@@ -586,11 +611,11 @@ func VerifyCreateBucketAccess(ctx fiber.Ctx, iam IAMService, isRoot bool, acc Ac
|
||||
|
||||
switch decision {
|
||||
case policyDecisionDeny:
|
||||
return s3err.GetExplicitDenyAccessErr(principal, string(CreateBucketAction), resourceArn, "an identity-based policy")
|
||||
return s3err.GetExplicitDenyAccessErr(principal, string(action), resourceArn, "an identity-based policy")
|
||||
case policyDecisionAllow:
|
||||
return nil
|
||||
}
|
||||
return s3err.GetImplicitDenyAccessErr(principal, string(CreateBucketAction), resourceArn)
|
||||
return s3err.GetImplicitDenyAccessErr(principal, string(action), resourceArn)
|
||||
}
|
||||
|
||||
func IsAdminOrOwner(acct Account, isRoot bool, acl ACL) error {
|
||||
|
||||
@@ -642,6 +642,65 @@ func TestVerifyCreateBucketAccess_PolicyEvaluatorIgnoresUserPlus(t *testing.T) {
|
||||
assert.Len(t, pe.calls, 1, "EvaluatePolicy must be consulted even for a userplus account once a PolicyEvaluator is configured")
|
||||
}
|
||||
|
||||
// Root and admin always list buckets, with no iam backend consulted.
|
||||
func TestVerifyListAllMyBucketsAccess_RootAndAdminBypass(t *testing.T) {
|
||||
pe := newMockPolicyEvaluator(policyDecisionDeny)
|
||||
|
||||
err := VerifyListAllMyBucketsAccess(testFiberCtx(t), pe, true, Account{Access: "testuser", Role: RoleUser})
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = VerifyListAllMyBucketsAccess(testFiberCtx(t), pe, false, Account{Access: "testuser", Role: RoleAdmin})
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Empty(t, pe.calls, "root/admin bypass before any policy evaluation")
|
||||
}
|
||||
|
||||
// Backends without an identity-policy layer keep listing buckets as before:
|
||||
// the listing is already narrowed to the caller's own buckets.
|
||||
func TestVerifyListAllMyBucketsAccess_NoPolicyEvaluatorIsUnrestricted(t *testing.T) {
|
||||
err := VerifyListAllMyBucketsAccess(testFiberCtx(t), NewIAMServiceSingle(Account{}), false, Account{Access: "testuser", Role: RoleUser})
|
||||
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
// A policy granting s3:ListAllMyBuckets allows the listing, evaluated
|
||||
// against "arn:aws:s3:::*".
|
||||
func TestVerifyListAllMyBucketsAccess_PolicyEvaluatorAllow(t *testing.T) {
|
||||
pe := newMockPolicyEvaluator(policyDecisionAllow)
|
||||
|
||||
err := VerifyListAllMyBucketsAccess(testFiberCtx(t), pe, false, Account{Access: "testuser", Role: RoleUser})
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, pe.calls, 1)
|
||||
assert.Equal(t, "testuser", pe.calls[0].access)
|
||||
assert.Equal(t, []string{"arn:aws:s3:::*"}, pe.calls[0].resources)
|
||||
assert.Equal(t, []Action{ListAllMyBucketsAction}, pe.calls[0].actions)
|
||||
}
|
||||
|
||||
// No matching policy denies with the AWS-shaped implicit-deny message.
|
||||
func TestVerifyListAllMyBucketsAccess_PolicyEvaluatorNoMatchDenies(t *testing.T) {
|
||||
pe := newMockPolicyEvaluator(policyDecisionNoMatch)
|
||||
pe.principalArn = "arn:aws:iam::000000000000:user/testuser"
|
||||
|
||||
err := VerifyListAllMyBucketsAccess(testFiberCtx(t), pe, false, Account{Access: "testuser", Role: RoleUser})
|
||||
|
||||
apiErr := requireAccessDeniedAPIError(t, err)
|
||||
assert.Contains(t, apiErr.Description, "arn:aws:iam::000000000000:user/testuser")
|
||||
assert.Contains(t, apiErr.Description, "because no identity-based policy allows the s3:ListAllMyBuckets action")
|
||||
}
|
||||
|
||||
// An explicit Deny is reported with the AWS-shaped explicit-deny message.
|
||||
func TestVerifyListAllMyBucketsAccess_PolicyEvaluatorExplicitDenyWins(t *testing.T) {
|
||||
pe := newMockPolicyEvaluator(policyDecisionDeny)
|
||||
pe.principalArn = "arn:aws:iam::000000000000:user/testuser"
|
||||
|
||||
err := VerifyListAllMyBucketsAccess(testFiberCtx(t), pe, false, Account{Access: "testuser", Role: RoleUser})
|
||||
|
||||
apiErr := requireAccessDeniedAPIError(t, err)
|
||||
assert.Contains(t, apiErr.Description, "s3:ListAllMyBuckets")
|
||||
assert.Contains(t, apiErr.Description, "with an explicit deny in an identity-based policy")
|
||||
}
|
||||
|
||||
// noObjectLockBackend answers "no lock configuration" for
|
||||
// GetObjectLockConfiguration, so VerifyObjectsAccess's lock check is a no-op
|
||||
// and only the policy/ACL half of the result is under test — matching what
|
||||
|
||||
@@ -94,6 +94,10 @@ const (
|
||||
DeleteBucketWebsiteAction Action = "s3:DeleteBucketWebsite"
|
||||
GetBucketPolicyStatusAction Action = "s3:GetBucketPolicyStatus"
|
||||
GetBucketLocationAction Action = "s3:GetBucketLocation"
|
||||
// s3:ListAllMyBuckets may appear only in iam user/role
|
||||
// policies, so it doesn't appear in supportedActionList and
|
||||
// it can never be used in bucket policy documents
|
||||
ListAllMyBucketsAction Action = "s3:ListAllMyBuckets"
|
||||
|
||||
AllActions Action = "s3:*"
|
||||
)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// 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 auth
|
||||
|
||||
// FixedBucketOwner is implemented by IAM backends that give every bucket the
|
||||
// same owner instead of the account that created it — currently only the
|
||||
// standalone IAM service client, which has no per-user ownership to express:
|
||||
// every account is a plain RoleUser, they cannot be enumerated, and access is
|
||||
// decided by IAM policy rather than by ACL.
|
||||
//
|
||||
// Backends that do not implement it keep per-creator ownership as before.
|
||||
type FixedBucketOwner interface {
|
||||
BucketOwner() Account
|
||||
}
|
||||
|
||||
// ResolveFixedBucketOwner reports the account that owns every bucket when iam
|
||||
// fixes ownership, and false when ownership follows the creator instead.
|
||||
func ResolveFixedBucketOwner(iam IAMService) (Account, bool) {
|
||||
fbo, ok := iam.(FixedBucketOwner)
|
||||
if !ok {
|
||||
return Account{}, false
|
||||
}
|
||||
|
||||
return fbo.BucketOwner(), true
|
||||
}
|
||||
@@ -118,6 +118,7 @@ var (
|
||||
_ IAMService = (*IAMServiceStandalone)(nil)
|
||||
_ SigningKeyProvider = (*IAMServiceStandalone)(nil)
|
||||
_ PolicyEvaluator = (*IAMServiceStandalone)(nil)
|
||||
_ FixedBucketOwner = (*IAMServiceStandalone)(nil)
|
||||
)
|
||||
|
||||
// NewIAMServiceStandalone constructs the standalone IAM service client.
|
||||
@@ -637,6 +638,12 @@ func (s *IAMServiceStandalone) ResolveAccounts(accessKeyIDs []string) ([]string,
|
||||
return missing, nil
|
||||
}
|
||||
|
||||
// BucketOwner implements FixedBucketOwner: every bucket is owned by the
|
||||
// gateway's root account, the only account this process knows locally.
|
||||
func (s *IAMServiceStandalone) BucketOwner() Account {
|
||||
return s.rootAcc
|
||||
}
|
||||
|
||||
// CreateAccount is not supported
|
||||
func (s *IAMServiceStandalone) CreateAccount(Account) error {
|
||||
return s3err.GetAPIError(s3err.ErrAdminMethodNotSupported)
|
||||
|
||||
Reference in New Issue
Block a user