3
0

Handle RBAC trace req on wildcard resource with contextual roles

This commit is contained in:
Denis Arh
2022-07-28 15:55:06 +02:00
parent 773fe7a602
commit 05bdf6a1d4
2 changed files with 41 additions and 1 deletions

View File

@@ -119,7 +119,46 @@ func (svc *service) Check(ses Session, op string, res Resource) (a Access) {
// Trace checks RBAC rules and returns all decision trace log
func (svc *service) Trace(ses Session, op string, res Resource) *Trace {
var (
t = new(Trace)
t = new(Trace)
)
if hasWildcards(res.RbacResource()) {
// a special case for when user has contextual roles
// AND trace is done on a resource with wildcards
ctxRolesDebug := partRoles{ContextRole: make(map[uint64]bool)}
for _, memberOf := range ses.Roles() {
for _, role := range svc.roles {
if role.kind != ContextRole {
continue
}
if role.id != memberOf {
continue
}
// member of contextual role
//
// this is a tricky situation:
// when doing regular check this is an unlikely scenario since
// check can not be done on a resource with wildcards
//
// all contextual roles we're members off will be collected
ctxRolesDebug[ContextRole][memberOf] = true
}
}
if len(ctxRolesDebug[ContextRole]) > 0 {
// session has at least one contextual role
// and since we're checking this on a wildcard resource
// there is no need to procede with RBAC check
baseTraceInfo(t, res.RbacResource(), op, ctxRolesDebug)
resolve(t, Inherit, unknownContext)
return t
}
}
var (
fRoles = getContextRoles(ses, res, svc.roles)
)

View File

@@ -23,6 +23,7 @@ const (
bypassRoleMembership resolution = "bypass-role-membership"
noRules resolution = "no-rules"
noMatch resolution = "no-match"
unknownContext resolution = "unknown-context"
)
// baseTraceInfo updates given check trace struct