Skip to content

chore: static custom role assignment #13297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion coderd/rbac/object_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion coderd/rbac/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ var RBACPermissions = map[string]PermissionDefinition{
Actions: map[Action]ActionDefinition{
ActionAssign: actDef("ability to assign roles"),
ActionRead: actDef("view what roles are assignable"),
ActionDelete: actDef("ability to delete roles"),
ActionDelete: actDef("ability to unassign roles"),
ActionCreate: actDef("ability to create/delete/edit custom roles"),
},
},
"assign_org_role": {
Expand Down
36 changes: 22 additions & 14 deletions coderd/rbac/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const (
templateAdmin string = "template-admin"
userAdmin string = "user-admin"
auditor string = "auditor"
// customSiteRole is a placeholder for all custom site roles.
// This is used for what roles can assign other roles.
// TODO: Make this more dynamic to allow other roles to grant.
customSiteRole string = "custom-site-role"

orgAdmin string = "organization-admin"
orgMember string = "organization-member"
Expand Down Expand Up @@ -52,6 +56,8 @@ func RoleOwner() string {
return roleName(owner, "")
}

func CustomSiteRole() string { return roleName(customSiteRole, "") }

func RoleTemplateAdmin() string {
return roleName(templateAdmin, "")
}
Expand Down Expand Up @@ -320,22 +326,24 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
// map[actor_role][assign_role]<can_assign>
var assignRoles = map[string]map[string]bool{
"system": {
owner: true,
auditor: true,
member: true,
orgAdmin: true,
orgMember: true,
templateAdmin: true,
userAdmin: true,
owner: true,
auditor: true,
member: true,
orgAdmin: true,
orgMember: true,
templateAdmin: true,
userAdmin: true,
customSiteRole: true,
},
owner: {
owner: true,
auditor: true,
member: true,
orgAdmin: true,
orgMember: true,
templateAdmin: true,
userAdmin: true,
owner: true,
auditor: true,
member: true,
orgAdmin: true,
orgMember: true,
templateAdmin: true,
userAdmin: true,
customSiteRole: true,
},
userAdmin: {
member: true,
Expand Down
11 changes: 10 additions & 1 deletion coderd/rbac/roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ func TestRolePermissions(t *testing.T) {
false: {otherOrgAdmin, otherOrgMember, memberMe, userAdmin},
},
},
{
Name: "CreateCustomRole",
Actions: []policy.Action{policy.ActionCreate},
Resource: rbac.ResourceAssignRole,
AuthorizeMap: map[bool][]authSubject{
true: {owner},
false: {userAdmin, orgAdmin, orgMemberMe, otherOrgAdmin, otherOrgMember, memberMe, templateAdmin},
},
},
{
Name: "RoleAssignment",
Actions: []policy.Action{policy.ActionAssign, policy.ActionDelete},
Expand Down Expand Up @@ -380,7 +389,7 @@ func TestRolePermissions(t *testing.T) {
},
// Some admin style resources
{
Name: "Licences",
Name: "Licenses",
Actions: []policy.Action{policy.ActionCreate, policy.ActionRead, policy.ActionDelete},
Resource: rbac.ResourceLicense,
AuthorizeMap: map[bool][]authSubject{
Expand Down
Loading