mirror of
https://github.com/pgsty/minio.git
synced 2026-07-21 21:20:23 +03:00
Add more context aware error for policy parsing errors (#8726)
In existing functionality we simply return a generic error such as "MalformedPolicy" which indicates just a generic string "invalid resource" which is not very meaningful when there might be multiple types of errors during policy parsing. This PR ensures that we send these errors back to client to indicate the actual error, brings in two concrete types such as - iampolicy.Error - policy.Error Refer #8202
This commit is contained in:
@@ -18,7 +18,6 @@ package policy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/minio/pkg/policy/condition"
|
||||
@@ -67,36 +66,36 @@ func (statement Statement) IsAllowed(args Args) bool {
|
||||
// isValid - checks whether statement is valid or not.
|
||||
func (statement Statement) isValid() error {
|
||||
if !statement.Effect.IsValid() {
|
||||
return fmt.Errorf("invalid Effect %v", statement.Effect)
|
||||
return Errorf("invalid Effect %v", statement.Effect)
|
||||
}
|
||||
|
||||
if !statement.Principal.IsValid() {
|
||||
return fmt.Errorf("invalid Principal %v", statement.Principal)
|
||||
return Errorf("invalid Principal %v", statement.Principal)
|
||||
}
|
||||
|
||||
if len(statement.Actions) == 0 {
|
||||
return fmt.Errorf("Action must not be empty")
|
||||
return Errorf("Action must not be empty")
|
||||
}
|
||||
|
||||
if len(statement.Resources) == 0 {
|
||||
return fmt.Errorf("Resource must not be empty")
|
||||
return Errorf("Resource must not be empty")
|
||||
}
|
||||
|
||||
for action := range statement.Actions {
|
||||
if action.isObjectAction() {
|
||||
if !statement.Resources.objectResourceExists() {
|
||||
return fmt.Errorf("unsupported Resource found %v for action %v", statement.Resources, action)
|
||||
return Errorf("unsupported Resource found %v for action %v", statement.Resources, action)
|
||||
}
|
||||
} else {
|
||||
if !statement.Resources.bucketResourceExists() {
|
||||
return fmt.Errorf("unsupported Resource found %v for action %v", statement.Resources, action)
|
||||
return Errorf("unsupported Resource found %v for action %v", statement.Resources, action)
|
||||
}
|
||||
}
|
||||
|
||||
keys := statement.Conditions.Keys()
|
||||
keyDiff := keys.Difference(actionConditionKeyMap[action])
|
||||
if !keyDiff.IsEmpty() {
|
||||
return fmt.Errorf("unsupported condition keys '%v' used for action '%v'", keyDiff, action)
|
||||
return Errorf("unsupported condition keys '%v' used for action '%v'", keyDiff, action)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user