Skip to content

Commit

Permalink
feat: should return error when no permission configured
Browse files Browse the repository at this point in the history
  • Loading branch information
ishanarya0 committed Mar 7, 2024
1 parent d623998 commit 6a48bdf
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/proxy/middleware/authz/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ func (c *Authz) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
return
}

if valid, err := config.validate(); !valid {
c.log.Error("middleware", c.Info().Name, "err", err)
c.notAllowed(rw, nil)
return
}

permissionAttributes := map[string]interface{}{}

permissionAttributes["namespace"] = rule.Backend.Namespace
Expand Down Expand Up @@ -297,6 +303,14 @@ func (w Authz) notAllowed(rw http.ResponseWriter, err error) {
rw.WriteHeader(http.StatusUnauthorized)
}

func (cg Config) validate() (bool, error) {
if len(cg.Permissions) == 0 {
return false, errors.New("no permissions configured")
}

return true, nil
}

func enrichExpression(exp expression.Expression, attributes map[string]interface{}) expression.Expression {
if val, ok := attributes[exp.Attribute.(string)]; ok {
exp.Attribute = val
Expand Down

0 comments on commit 6a48bdf

Please sign in to comment.