Skip to content

Commit ef8c950

Browse files
committed
chore: static custom role assignment
For now, only owners can assign custom roles
1 parent 2eba21e commit ef8c950

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

coderd/rbac/object_gen.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/rbac/policy/policy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ var RBACPermissions = map[string]PermissionDefinition{
209209
Actions: map[Action]ActionDefinition{
210210
ActionAssign: actDef("ability to assign roles"),
211211
ActionRead: actDef("view what roles are assignable"),
212-
ActionDelete: actDef("ability to delete roles"),
212+
ActionDelete: actDef("ability to unassign roles"),
213+
ActionCreate: actDef("ability to create/delete/edit custom roles"),
213214
},
214215
},
215216
"assign_org_role": {

coderd/rbac/roles.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const (
2020
templateAdmin string = "template-admin"
2121
userAdmin string = "user-admin"
2222
auditor string = "auditor"
23+
// customSiteRole is a placeholder for all custom site roles.
24+
// This is used for what roles can assign other roles.
25+
// TODO: Make this more dynamic to allow other roles to grant.
26+
customSiteRole string = "custom-site-role"
2327

2428
orgAdmin string = "organization-admin"
2529
orgMember string = "organization-member"
@@ -52,6 +56,8 @@ func RoleOwner() string {
5256
return roleName(owner, "")
5357
}
5458

59+
func CustomSiteRole() string { return roleName(customSiteRole, "") }
60+
5561
func RoleTemplateAdmin() string {
5662
return roleName(templateAdmin, "")
5763
}
@@ -320,22 +326,24 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
320326
// map[actor_role][assign_role]<can_assign>
321327
var assignRoles = map[string]map[string]bool{
322328
"system": {
323-
owner: true,
324-
auditor: true,
325-
member: true,
326-
orgAdmin: true,
327-
orgMember: true,
328-
templateAdmin: true,
329-
userAdmin: true,
329+
owner: true,
330+
auditor: true,
331+
member: true,
332+
orgAdmin: true,
333+
orgMember: true,
334+
templateAdmin: true,
335+
userAdmin: true,
336+
customSiteRole: true,
330337
},
331338
owner: {
332-
owner: true,
333-
auditor: true,
334-
member: true,
335-
orgAdmin: true,
336-
orgMember: true,
337-
templateAdmin: true,
338-
userAdmin: true,
339+
owner: true,
340+
auditor: true,
341+
member: true,
342+
orgAdmin: true,
343+
orgMember: true,
344+
templateAdmin: true,
345+
userAdmin: true,
346+
customSiteRole: true,
339347
},
340348
userAdmin: {
341349
member: true,

coderd/rbac/roles_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ func TestRolePermissions(t *testing.T) {
248248
false: {otherOrgAdmin, otherOrgMember, memberMe, userAdmin},
249249
},
250250
},
251+
{
252+
Name: "CreateCustomRole",
253+
Actions: []policy.Action{policy.ActionCreate},
254+
Resource: rbac.ResourceAssignRole,
255+
AuthorizeMap: map[bool][]authSubject{
256+
true: {owner},
257+
false: {userAdmin, orgAdmin, orgMemberMe, otherOrgAdmin, otherOrgMember, memberMe, templateAdmin},
258+
},
259+
},
251260
{
252261
Name: "RoleAssignment",
253262
Actions: []policy.Action{policy.ActionAssign, policy.ActionDelete},
@@ -380,7 +389,7 @@ func TestRolePermissions(t *testing.T) {
380389
},
381390
// Some admin style resources
382391
{
383-
Name: "Licences",
392+
Name: "Licenses",
384393
Actions: []policy.Action{policy.ActionCreate, policy.ActionRead, policy.ActionDelete},
385394
Resource: rbac.ResourceLicense,
386395
AuthorizeMap: map[bool][]authSubject{

0 commit comments

Comments
 (0)