You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2018/05/17 02:26:00 UTC
[incubator-trafficcontrol] 14/17: disallow creation of roles with a
higher privLevel than the user's
This is an automated email from the ASF dual-hosted git repository.
mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git
commit 9a3585ddf0c35e1c6a24757f30d827493fb104c1
Author: Dylan Volz <Dy...@comcast.com>
AuthorDate: Tue May 1 13:24:02 2018 -0600
disallow creation of roles with a higher privLevel than the user's
---
traffic_ops/traffic_ops_golang/role/roles.go | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/traffic_ops/traffic_ops_golang/role/roles.go b/traffic_ops/traffic_ops_golang/role/roles.go
index fd992e4..e541f33 100644
--- a/traffic_ops/traffic_ops_golang/role/roles.go
+++ b/traffic_ops/traffic_ops_golang/role/roles.go
@@ -87,13 +87,15 @@ func (role TORole) Validate(db *sqlx.DB) []error {
errsToReturn := tovalidate.ToErrors(errs)
checkCaps := `SELECT cap FROM UNNEST($1::text[]) AS cap WHERE NOT cap = ANY(ARRAY(SELECT c.name FROM capability AS c WHERE c.name = ANY($1)))`
var badCaps []string
- err := db.Select(&badCaps, checkCaps, pq.Array(role.Capabilities))
- if err != nil {
- log.Errorf("got error from selecting bad capabilities: %v", err)
- return []error{tc.DBError}
- }
- if len(badCaps) > 0 {
- errsToReturn = append(errsToReturn, fmt.Errorf("can not add non-existent capabilities: %v", badCaps))
+ if db != nil {
+ err := db.Select(&badCaps, checkCaps, pq.Array(role.Capabilities))
+ if err != nil {
+ log.Errorf("got error from selecting bad capabilities: %v", err)
+ return []error{tc.DBError}
+ }
+ if len(badCaps) > 0 {
+ errsToReturn = append(errsToReturn, fmt.Errorf("can not add non-existent capabilities: %v", badCaps))
+ }
}
return errsToReturn
}
@@ -130,9 +132,12 @@ func (role *TORole) Create(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErr
continue CapabilitiesLoop
}
}
- return errors.New("Can not create a role with a capability you do not have: " + cap), tc.ForbiddenError
+ return errors.New("can not create a role with a capability you do not have: " + cap), tc.ForbiddenError
}
}
+ if *role.PrivLevel > user.PrivLevel {
+ return errors.New("can not create a role with a higher priv level than your own"), tc.ForbiddenError
+ }
resultRows, err := tx.NamedQuery(insertQuery(), role)
if err != nil {
if pqErr, ok := err.(*pq.Error); ok {
@@ -288,6 +293,10 @@ func (role *TORole) Update(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErr
}
}
+ if *role.PrivLevel > user.PrivLevel {
+ return errors.New("can not create a role with a higher priv level than your own"), tc.ForbiddenError
+ }
+
log.Debugf("about to run exec query: %s with role: %++v\n", updateQuery(), role)
result, err := tx.NamedExec(updateQuery(), role)
if err != nil {
--
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.