@@ -27,8 +27,11 @@ const (
2727customSiteRole string = "custom-site-role"
2828customOrganizationRole string = "custom-organization-role"
2929
30- orgAdmin string = "organization-admin"
31- orgMember string = "organization-member"
30+ orgAdmin string = "organization-admin"
31+ orgMember string = "organization-member"
32+ orgAuditor string = "organization-auditor"
33+ orgUserAdmin string = "organization-user-admin"
34+ orgTemplateAdmin string = "organization-template-admin"
3235)
3336
3437func init () {
@@ -144,18 +147,38 @@ func RoleOrgMember() string {
144147return orgMember
145148}
146149
150+ func RoleOrgAuditor ()string {
151+ return orgAuditor
152+ }
153+
154+ func RoleOrgUserAdmin ()string {
155+ return orgUserAdmin
156+ }
157+
158+ func RoleOrgTemplateAdmin ()string {
159+ return orgTemplateAdmin
160+ }
161+
147162// ScopedRoleOrgAdmin is the org role with the organization ID
148- // Deprecated This was used before organization scope was included as a
149- // field in all user facing APIs. Usage of 'ScopedRoleOrgAdmin()' is preferred.
150163func ScopedRoleOrgAdmin (organizationID uuid.UUID )RoleIdentifier {
151- return RoleIdentifier {Name :orgAdmin ,OrganizationID :organizationID }
164+ return RoleIdentifier {Name :RoleOrgAdmin () ,OrganizationID :organizationID }
152165}
153166
154167// ScopedRoleOrgMember is the org role with the organization ID
155- // Deprecated This was used before organization scope was included as a
156- // field in all user facing APIs. Usage of 'ScopedRoleOrgMember()' is preferred.
157168func ScopedRoleOrgMember (organizationID uuid.UUID )RoleIdentifier {
158- return RoleIdentifier {Name :orgMember ,OrganizationID :organizationID }
169+ return RoleIdentifier {Name :RoleOrgMember (),OrganizationID :organizationID }
170+ }
171+
172+ func ScopedRoleOrgAuditor (organizationID uuid.UUID )RoleIdentifier {
173+ return RoleIdentifier {Name :RoleOrgAuditor (),OrganizationID :organizationID }
174+ }
175+
176+ func ScopedRoleOrgUserAdmin (organizationID uuid.UUID )RoleIdentifier {
177+ return RoleIdentifier {Name :RoleOrgUserAdmin (),OrganizationID :organizationID }
178+ }
179+
180+ func ScopedRoleOrgTemplateAdmin (organizationID uuid.UUID )RoleIdentifier {
181+ return RoleIdentifier {Name :RoleOrgTemplateAdmin (),OrganizationID :organizationID }
159182}
160183
161184func allPermsExcept (excepts ... Objecter ) []Permission {
@@ -365,7 +388,11 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
365388return Role {
366389Identifier :RoleIdentifier {Name :orgAdmin ,OrganizationID :organizationID },
367390DisplayName :"Organization Admin" ,
368- Site : []Permission {},
391+ Site :Permissions (map [string ][]policy.Action {
392+ // To assign organization members, we need to be able to read
393+ // users at the site wide to know they exist.
394+ ResourceUser .Type : {policy .ActionRead },
395+ }),
369396Org :map [string ][]Permission {
370397// Org admins should not have workspace exec perms.
371398organizationID .String ():append (allPermsExcept (ResourceWorkspace ,ResourceWorkspaceDormant ,ResourceAssignRole ),Permissions (map [string ][]policy.Action {
@@ -377,8 +404,7 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
377404}
378405},
379406
380- // orgMember has an empty set of permissions, this just implies their membership
381- // in an organization.
407+ // orgMember is an implied role to any member in an organization.
382408orgMember :func (organizationID uuid.UUID )Role {
383409return Role {
384410Identifier :RoleIdentifier {Name :orgMember ,OrganizationID :organizationID },
@@ -406,6 +432,59 @@ func ReloadBuiltinRoles(opts *RoleOptions) {
406432},
407433}
408434},
435+ orgAuditor :func (organizationID uuid.UUID )Role {
436+ return Role {
437+ Identifier :RoleIdentifier {Name :orgAuditor ,OrganizationID :organizationID },
438+ DisplayName :"Organization Auditor" ,
439+ Site : []Permission {},
440+ Org :map [string ][]Permission {
441+ organizationID .String ():Permissions (map [string ][]policy.Action {
442+ ResourceAuditLog .Type : {policy .ActionRead },
443+ }),
444+ },
445+ User : []Permission {},
446+ }
447+ },
448+ orgUserAdmin :func (organizationID uuid.UUID )Role {
449+ // Manages organization members and groups.
450+ return Role {
451+ Identifier :RoleIdentifier {Name :orgUserAdmin ,OrganizationID :organizationID },
452+ DisplayName :"Organization User Admin" ,
453+ Site :Permissions (map [string ][]policy.Action {
454+ // To assign organization members, we need to be able to read
455+ // users at the site wide to know they exist.
456+ ResourceUser .Type : {policy .ActionRead },
457+ }),
458+ Org :map [string ][]Permission {
459+ organizationID .String ():Permissions (map [string ][]policy.Action {
460+ // Assign, remove, and read roles in the organization.
461+ ResourceAssignOrgRole .Type : {policy .ActionAssign ,policy .ActionDelete ,policy .ActionRead },
462+ ResourceOrganizationMember .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionDelete },
463+ ResourceGroup .Type :ResourceGroup .AvailableActions (),
464+ }),
465+ },
466+ User : []Permission {},
467+ }
468+ },
469+ orgTemplateAdmin :func (organizationID uuid.UUID )Role {
470+ // Manages organization members and groups.
471+ return Role {
472+ Identifier :RoleIdentifier {Name :orgTemplateAdmin ,OrganizationID :organizationID },
473+ DisplayName :"Organization Template Admin" ,
474+ Site : []Permission {},
475+ Org :map [string ][]Permission {
476+ organizationID .String ():Permissions (map [string ][]policy.Action {
477+ ResourceTemplate .Type : {policy .ActionCreate ,policy .ActionRead ,policy .ActionUpdate ,policy .ActionDelete ,policy .ActionViewInsights },
478+ ResourceFile .Type : {policy .ActionCreate ,policy .ActionRead },
479+ ResourceWorkspace .Type : {policy .ActionRead },
480+ // Assigning template perms requires this permission.
481+ ResourceOrganizationMember .Type : {policy .ActionRead },
482+ ResourceGroup .Type : {policy .ActionRead },
483+ }),
484+ },
485+ User : []Permission {},
486+ }
487+ },
409488}
410489}
411490
@@ -421,6 +500,9 @@ var assignRoles = map[string]map[string]bool{
421500member :true ,
422501orgAdmin :true ,
423502orgMember :true ,
503+ orgAuditor :true ,
504+ orgUserAdmin :true ,
505+ orgTemplateAdmin :true ,
424506templateAdmin :true ,
425507userAdmin :true ,
426508customSiteRole :true ,
@@ -432,6 +514,9 @@ var assignRoles = map[string]map[string]bool{
432514member :true ,
433515orgAdmin :true ,
434516orgMember :true ,
517+ orgAuditor :true ,
518+ orgUserAdmin :true ,
519+ orgTemplateAdmin :true ,
435520templateAdmin :true ,
436521userAdmin :true ,
437522customSiteRole :true ,
@@ -444,8 +529,14 @@ var assignRoles = map[string]map[string]bool{
444529orgAdmin : {
445530orgAdmin :true ,
446531orgMember :true ,
532+ orgAuditor :true ,
533+ orgUserAdmin :true ,
534+ orgTemplateAdmin :true ,
447535customOrganizationRole :true ,
448536},
537+ orgUserAdmin : {
538+ orgMember :true ,
539+ },
449540}
450541
451542// ExpandableRoles is any type that can be expanded into a []Role. This is implemented