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:
niksis02
2026-08-27 20:28:51 +04:00
parent 61f1d1c9c8
commit abb3b27149
37 changed files with 5854 additions and 307 deletions
+2
View File
@@ -1578,6 +1578,7 @@ func TestS3IAMAccessControl(ts *TestState) {
ts.Run(S3IAMAccessControl_policy_combinations)
ts.Run(S3IAMAccessControl_copy_object_requires_both_sides)
ts.Run(S3IAMAccessControl_create_bucket)
ts.Run(S3IAMAccessControl_list_buckets)
ts.Run(S3IAMAccessControl_governance_bypass_sources)
ts.Run(S3IAMAccessControl_governance_without_bypass_header)
ts.Run(S3IAMAccessControl_compliance_mode_not_bypassable)
@@ -2002,6 +2003,7 @@ func GetIntTests() IntTests {
"S3IAMAccessControl_policy_combinations": S3IAMAccessControl_policy_combinations,
"S3IAMAccessControl_copy_object_requires_both_sides": S3IAMAccessControl_copy_object_requires_both_sides,
"S3IAMAccessControl_create_bucket": S3IAMAccessControl_create_bucket,
"S3IAMAccessControl_list_buckets": S3IAMAccessControl_list_buckets,
"S3IAMAccessControl_governance_bypass_sources": S3IAMAccessControl_governance_bypass_sources,
"S3IAMAccessControl_governance_without_bypass_header": S3IAMAccessControl_governance_without_bypass_header,
"S3IAMAccessControl_compliance_mode_not_bypassable": S3IAMAccessControl_compliance_mode_not_bypassable,
+109
View File
@@ -696,6 +696,104 @@ func S3IAMAccessControl_create_bucket(s *S3Conf) error {
})
}
// S3IAMAccessControl_list_buckets verifies ListBuckets is gated by
// s3:ListAllMyBuckets under the standalone IAM service: root always lists,
// an ordinary user needs an identity-policy Allow for the action.
func S3IAMAccessControl_list_buckets(s *S3Conf) error {
testName := "S3IAMAccessControl_list_buckets"
return s3IAMActionHandler(s, testName, func(root *iam.Client, bucket string) error {
allBuckets := "arn:aws:s3:::*"
cases := []struct {
name string
policy string
wantErr func(user *s3IAMPrincipal) s3err.S3Error
}{
{
name: "no policy denies",
wantErr: func(u *s3IAMPrincipal) s3err.S3Error {
return wantImplicitDeny(u.arn, actS3ListAllMyBuckets, allBuckets)
},
},
{
name: "another action's grant doesn't allow",
policy: policyDoc(accessStatement{Effect: "Allow", Action: actS3ListBucket, Resource: bucketArn(bucket)}),
wantErr: func(u *s3IAMPrincipal) s3err.S3Error {
return wantImplicitDeny(u.arn, actS3ListAllMyBuckets, allBuckets)
},
},
{
name: "explicit deny",
policy: policyDoc(accessStatement{Effect: "Deny", Action: actS3ListAllMyBuckets, Resource: "*"}),
wantErr: func(u *s3IAMPrincipal) s3err.S3Error {
return wantExplicitIdentityDeny(u.arn, actS3ListAllMyBuckets, allBuckets)
},
},
{
name: "grant on the bucket wildcard arn allows",
policy: policyDoc(accessStatement{Effect: "Allow", Action: actS3ListAllMyBuckets, Resource: allBuckets}),
},
{
name: "grant on a bare wildcard resource allows",
policy: policyDoc(accessStatement{Effect: "Allow", Action: actS3ListAllMyBuckets, Resource: "*"}),
},
{
name: "grant scoped to one bucket doesn't allow",
policy: policyDoc(accessStatement{Effect: "Allow", Action: actS3ListAllMyBuckets, Resource: bucketArn(bucket)}),
wantErr: func(u *s3IAMPrincipal) s3err.S3Error {
return wantImplicitDeny(u.arn, actS3ListAllMyBuckets, allBuckets)
},
},
}
for _, tc := range cases {
if err := func() error {
policies := map[string]string{}
if tc.policy != "" {
policies["p"] = tc.policy
}
user, cleanup, err := newS3IAMUser(root, s, policies)
if err != nil {
return err
}
defer cleanup()
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
out, err := user.client.ListBuckets(ctx, &s3.ListBucketsInput{})
cancel()
if tc.wantErr != nil {
return checkApiErr(err, tc.wantErr(user))
}
if err != nil {
return fmt.Errorf("expected ListBuckets to be allowed: %w", err)
}
// Ownership is fixed to root here, so an allowed user sees
// every bucket, including the one this test created.
if !containsBucket(out.Buckets, bucket) {
return fmt.Errorf("expected the listing to contain %q, got %v", bucket, out.Buckets)
}
return nil
}(); err != nil {
return fmt.Errorf("%s: %w", tc.name, err)
}
}
// Root lists with no policy of its own, and is never subject to one.
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
out, err := s.GetClient().ListBuckets(ctx, &s3.ListBucketsInput{})
cancel()
if err != nil {
return fmt.Errorf("root ListBuckets: %w", err)
}
if !containsBucket(out.Buckets, bucket) {
return fmt.Errorf("root: expected the listing to contain %q, got %v", bucket, out.Buckets)
}
return nil
})
}
// S3IAMAccessControl_governance_bypass_sources verifies s3:BypassGovernance
// Retention follows the same precedence as any other action: an Allow from
// either the identity policy or the bucket policy is enough on its own, and
@@ -1803,3 +1901,14 @@ func S3IAMAccessControl_bucket_policy_unknown_principal_rejected(s *S3Conf) erro
})
})
}
// containsBucket reports whether buckets names bucket, so a listing can be
// asserted without depending on what else other tests left behind.
func containsBucket(buckets []types.Bucket, bucket string) bool {
for _, b := range buckets {
if b.Name != nil && *b.Name == bucket {
return true
}
}
return false
}
+1
View File
@@ -39,6 +39,7 @@ const (
actS3DeleteObjectVersion = "s3:DeleteObjectVersion"
actS3ListBucket = "s3:ListBucket"
actS3CreateBucket = "s3:CreateBucket"
actS3ListAllMyBuckets = "s3:ListAllMyBuckets"
actS3BypassGovernance = "s3:BypassGovernanceRetention"
)