mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 05:42:28 +08:00

* Unexport store and create new constructor function * Add ResourceAuthorizer and LegacyAccessClient * Configure checks for user store * List with checks if AccessClient is configured * Allow system user service account to read all users --------- Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package accesscontrol
|
|
|
|
import (
|
|
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
|
)
|
|
|
|
func Checker(user identity.Requester, action string) func(scopes ...string) bool {
|
|
permissions := user.GetPermissions()
|
|
userScopes, ok := permissions[action]
|
|
if !ok {
|
|
return func(scopes ...string) bool { return false }
|
|
}
|
|
|
|
lookup := make(map[string]bool, len(userScopes))
|
|
for i := range userScopes {
|
|
lookup[userScopes[i]] = true
|
|
}
|
|
|
|
var checkedWildcards bool
|
|
var hasWildcard bool
|
|
|
|
return func(scopes ...string) bool {
|
|
if !checkedWildcards {
|
|
wildcards := wildcardsFromScopes(scopes...)
|
|
for _, w := range wildcards {
|
|
if _, ok := lookup[w]; ok {
|
|
hasWildcard = true
|
|
break
|
|
}
|
|
}
|
|
checkedWildcards = true
|
|
}
|
|
|
|
if hasWildcard {
|
|
return true
|
|
}
|
|
|
|
for _, s := range scopes {
|
|
if lookup[s] {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
}
|
|
|
|
func wildcardsFromScopes(scopes ...string) Wildcards {
|
|
prefixes := make([]string, len(scopes))
|
|
for _, scope := range scopes {
|
|
prefixes = append(prefixes, ScopePrefix(scope))
|
|
}
|
|
|
|
return WildcardsFromPrefixes(prefixes)
|
|
}
|