Access Control: Make the evaluator prefix match only (#38025)

* Make the evaluator prefix match only

* Handle empty scopes

* Bump version of settings read role

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
This commit is contained in:
Jeremy Price
2021-08-23 14:03:20 +02:00
committed by GitHub
co-authored by Karl Persson
parent 1b3eecddcd
commit 9a71cec1f0
5 changed files with 79 additions and 28 deletions
@@ -2,6 +2,7 @@ package accesscontrol
import (
"context"
"strings"
"github.com/grafana/grafana/pkg/models"
)
@@ -53,3 +54,15 @@ func BuildPermissionsMap(permissions []*Permission) map[string]bool {
return permissionsMap
}
func ValidateScope(scope string) bool {
prefix, last := scope[:len(scope)-1], scope[len(scope)-1]
// verify that last char is either ':' or '/' if last character of scope is '*'
if len(prefix) > 0 && last == '*' {
lastChar := prefix[len(prefix)-1]
if lastChar != ':' && lastChar != '/' {
return false
}
}
return !strings.ContainsAny(prefix, "*?")
}