3
0

Fix improper role resolution in workflow RBAC grant functions

This commit is contained in:
Tomaž Jerman
2022-12-12 15:29:15 +01:00
parent 73b85a0305
commit 3e00b38e2f
2 changed files with 46 additions and 15 deletions
+38 -9
View File
@@ -18,15 +18,11 @@ type (
FindByAny(ctx context.Context, identifier interface{}) (*types.User, error)
}
rbacRoleService interface {
Membership(ctx context.Context, userID uint64) (types.RoleMemberSet, error)
}
rbacHandler struct {
reg rbacHandlerRegistry
rbac rbacService
user rbacUserService
role rbacRoleService
role roleService
}
auxResource struct{ res string }
@@ -38,7 +34,7 @@ func (r auxResource) RbacResource() string {
return r.res
}
func RbacHandler(reg rbacHandlerRegistry, rbac rbacService, user rbacUserService, role rbacRoleService) *rbacHandler {
func RbacHandler(reg rbacHandlerRegistry, rbac rbacService, user rbacUserService, role roleService) *rbacHandler {
h := &rbacHandler{
reg: reg,
rbac: rbac,
@@ -51,15 +47,48 @@ func RbacHandler(reg rbacHandlerRegistry, rbac rbacService, user rbacUserService
}
func (h rbacHandler) allow(ctx context.Context, args *rbacAllowArgs) (err error) {
return h.grant(ctx, rbac.AllowRule(args.roleID, args.Resource.RbacResource(), args.Operation))
r, err := lookupRole(ctx, h.role, rolesLookupArgs{
hasLookup: args.hasRole,
Lookup: args.Role,
lookupID: args.roleID,
lookupHandle: args.roleHandle,
lookupRes: args.roleRes,
})
if err != nil {
return
}
return h.grant(ctx, rbac.AllowRule(r.ID, args.Resource.RbacResource(), args.Operation))
}
func (h rbacHandler) deny(ctx context.Context, args *rbacDenyArgs) (err error) {
return h.grant(ctx, rbac.DenyRule(args.roleID, args.Resource.RbacResource(), args.Operation))
r, err := lookupRole(ctx, h.role, rolesLookupArgs{
hasLookup: args.hasRole,
Lookup: args.Role,
lookupID: args.roleID,
lookupHandle: args.roleHandle,
lookupRes: args.roleRes,
})
if err != nil {
return
}
return h.grant(ctx, rbac.DenyRule(r.ID, args.Resource.RbacResource(), args.Operation))
}
func (h rbacHandler) inherit(ctx context.Context, args *rbacInheritArgs) (err error) {
return h.grant(ctx, rbac.InheritRule(args.roleID, args.Resource.RbacResource(), args.Operation))
r, err := lookupRole(ctx, h.role, rolesLookupArgs{
hasLookup: args.hasRole,
Lookup: args.Role,
lookupID: args.roleID,
lookupHandle: args.roleHandle,
lookupRes: args.roleRes,
})
if err != nil {
return
}
return h.grant(ctx, rbac.InheritRule(r.ID, args.Resource.RbacResource(), args.Operation))
}
// verifies grant op (granter needs to be allowed to grant on the component
+8 -6
View File
@@ -3,6 +3,13 @@ imports:
- github.com/cortezaproject/corteza/server/pkg/rbac
params:
roleLookup: &roleLookup
required: true
types:
- { wf: ID, }
- { wf: Handle, }
- { wf: Role, suffix: res }
manageParams: &manageParams
resource:
required: true
@@ -10,12 +17,7 @@ params:
# Note that we can not accept string here because
# we need whole resource with all the info loaded
- { wf: RbacResource }
role:
required: true
types:
- { wf: ID }
- { wf: Handle }
- { wf: Role, suffix: res }
role: *roleLookup
operation:
required: true
types: