Skip to content

Commit aa89bcf

Browse files
grafana-iam: RoleBindings implementation (grafana#112120)
* add permissions for rolebindings * fix required actions * fix VerbCreate * transform to wildcard scope * Apply suggestions from code review Co-authored-by: Gabriel MABILLE <[email protected]> * Apply suggestion from @gamab * lint --------- Co-authored-by: Gabriel MABILLE <[email protected]>
1 parent 54c224d commit aa89bcf

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pkg/services/authz/rbac/mapper.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type translation struct {
3535
actionSetMapping map[string][]string
3636
folderSupport bool
3737
skipScopeOnCreate bool
38+
// use this option if you need to limit access to users that can access all resources
39+
useWildcardScope bool
3840
}
3941

4042
func (t translation) Action(verb string) (string, bool) {
@@ -48,6 +50,9 @@ func (t translation) ActionSets(verb string) []string {
4850
}
4951

5052
func (t translation) Scope(name string) string {
53+
if t.useWildcardScope {
54+
return "*"
55+
}
5156
return t.resource + ":" + t.attribute + ":" + name
5257
}
5358

@@ -198,6 +203,22 @@ func NewMapperRegistry() MapperRegistry {
198203
folderSupport: false,
199204
skipScopeOnCreate: false,
200205
},
206+
"rolebindings": translation{
207+
resource: "rolebindings",
208+
// rolebidings should only be modifiable by admins with a wildcard access
209+
useWildcardScope: true,
210+
verbMapping: map[string]string{
211+
utils.VerbCreate: "users.roles:add",
212+
utils.VerbGet: "users.roles:read",
213+
utils.VerbUpdate: "users.roles:add",
214+
utils.VerbPatch: "users.roles:add",
215+
utils.VerbDelete: "users.roles:remove",
216+
utils.VerbDeleteCollection: "users.roles:remove",
217+
utils.VerbList: "users.roles:read",
218+
utils.VerbWatch: "users.roles:read",
219+
},
220+
folderSupport: false,
221+
},
201222
},
202223
"secret.grafana.app": {
203224
"securevalues": newResourceTranslation("secret.securevalues", "uid", false, false),

0 commit comments

Comments
 (0)