Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

fix(iam): accept bare "*" resource in PutUserPolicy (#9209) (#9210)

Chris Lu88c2f3c34d4d
diff --git a/weed/s3api/s3api_embedded_iam.go b/weed/s3api/s3api_embedded_iam.go
index 1e581d5453..7e02f39b88 100644
--- a/weed/s3api/s3api_embedded_iam.go
+++ b/weed/s3api/s3api_embedded_iam.go
@@ -819,9 +819,18 @@ func (e *EmbeddedIamApi) getActions(policy *policy_engine.PolicyDocument) ([]str
return nil, fmt.Errorf("not a valid effect: '%s'. Only 'Allow' is possible", statement.Effect)
}
for _, resource := range statement.Resource.Strings() {
- res := strings.Split(resource, ":")
- if len(res) != 6 || res[0] != "arn" || res[1] != "aws" || res[2] != "s3" {
- continue
+ // AWS IAM treats a bare "*" as "any resource". Normalize it to the
+ // full-wildcard S3 ARN so it flows through the same path as
+ // "arn:aws:s3:::*" instead of being dropped as malformed.
+ var resourcePath string
+ if resource == "*" {
+ resourcePath = "*"
+ } else {
+ res := strings.Split(resource, ":")
+ if len(res) != 6 || res[0] != "arn" || res[1] != "aws" || res[2] != "s3" {
+ continue
+ }
+ resourcePath = res[5]
}
for _, action := range statement.Action.Strings() {
act := strings.Split(action, ":")
@@ -833,7 +842,6 @@ func (e *EmbeddedIamApi) getActions(policy *policy_engine.PolicyDocument) ([]str
return nil, fmt.Errorf("not a valid action: '%s'", act[1])
}
- resourcePath := res[5]
if resourcePath == "*" {
// Wildcard - applies to all buckets
actions = append(actions, statementAction)
diff --git a/weed/s3api/s3api_embedded_iam_test.go b/weed/s3api/s3api_embedded_iam_test.go
index 124831eb95..4d2412dee5 100644
--- a/weed/s3api/s3api_embedded_iam_test.go
+++ b/weed/s3api/s3api_embedded_iam_test.go
@@ -1814,6 +1814,33 @@ func TestEmbeddedIamGetActionsFromPolicy(t *testing.T) {
assert.Contains(t, actions, "Write:mybucket")
}
+// TestEmbeddedIamPutUserPolicyAllResourceWildcard reproduces issue #9209:
+// an AWS-style policy using "Action":"s3:*" with a bare "Resource":"*" is
+// valid AWS IAM syntax (meaning "any resource") but was rejected with
+// "no valid actions found in policy document" because the resource parser
+// required a full ARN.
+func TestEmbeddedIamPutUserPolicyAllResourceWildcard(t *testing.T) {
+ api := NewEmbeddedIamApiForTest()
+
+ // From issue #9209: bare "*" resource and bare "s3:*" action.
+ policyDoc := `{
+ "Version": "2012-10-17",
+ "Statement": [{
+ "Sid": "AllowS3Admin",
+ "Effect": "Allow",
+ "Action": "s3:*",
+ "Resource": "*"
+ }]
+ }`
+
+ policy, err := api.GetPolicyDocument(&policyDoc)
+ require.NoError(t, err)
+
+ actions, err := api.getActions(&policy)
+ require.NoError(t, err, "getActions must accept bare \"*\" resource")
+ assert.Contains(t, actions, ACTION_ADMIN, "s3:* should map to admin action")
+}
+
// TestEmbeddedIamSetUserStatus tests enabling/disabling a user
func TestEmbeddedIamSetUserStatus(t *testing.T) {
api := NewEmbeddedIamApiForTest()