-
Notifications
You must be signed in to change notification settings - Fork 936
chore: add built in organization roles to match site #13938
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c071985
chore: add built in organization roles to match site
Emyrk 3685b18
fixup some testS
Emyrk 2ab3be7
add unit tests, also give user read perm
Emyrk a1124d1
update test with permission asserts
Emyrk 4718636
update test with permission asserts
Emyrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,11 @@ const ( | |
customSiteRole string = "custom-site-role" | ||
customOrganizationRole string = "custom-organization-role" | ||
|
||
orgAdmin string = "organization-admin" | ||
orgMember string = "organization-member" | ||
orgAdmin string = "organization-admin" | ||
orgMember string = "organization-member" | ||
orgAuditor string = "organization-auditor" | ||
orgUserAdmin string = "organization-user-admin" | ||
orgTemplateAdmin string = "organization-template-admin" | ||
) | ||
|
||
func init() { | ||
|
@@ -144,18 +147,38 @@ func RoleOrgMember() string { | |
return orgMember | ||
} | ||
|
||
func RoleOrgAuditor() string { | ||
return orgAuditor | ||
} | ||
|
||
func RoleOrgUserAdmin() string { | ||
return orgUserAdmin | ||
} | ||
|
||
func RoleOrgTemplateAdmin() string { | ||
return orgTemplateAdmin | ||
} | ||
|
||
// ScopedRoleOrgAdmin is the org role with the organization ID | ||
// Deprecated This was used before organization scope was included as a | ||
// field in all user facing APIs. Usage of 'ScopedRoleOrgAdmin()' is preferred. | ||
func ScopedRoleOrgAdmin(organizationID uuid.UUID) RoleIdentifier { | ||
return RoleIdentifier{Name: orgAdmin, OrganizationID: organizationID} | ||
return RoleIdentifier{Name: RoleOrgAdmin(), OrganizationID: organizationID} | ||
} | ||
|
||
// ScopedRoleOrgMember is the org role with the organization ID | ||
// Deprecated This was used before organization scope was included as a | ||
// field in all user facing APIs. Usage of 'ScopedRoleOrgMember()' is preferred. | ||
func ScopedRoleOrgMember(organizationID uuid.UUID) RoleIdentifier { | ||
return RoleIdentifier{Name: orgMember, OrganizationID: organizationID} | ||
return RoleIdentifier{Name: RoleOrgMember(), OrganizationID: organizationID} | ||
} | ||
|
||
func ScopedRoleOrgAuditor(organizationID uuid.UUID) RoleIdentifier { | ||
return RoleIdentifier{Name: RoleOrgAuditor(), OrganizationID: organizationID} | ||
} | ||
|
||
func ScopedRoleOrgUserAdmin(organizationID uuid.UUID) RoleIdentifier { | ||
return RoleIdentifier{Name: RoleOrgUserAdmin(), OrganizationID: organizationID} | ||
} | ||
|
||
func ScopedRoleOrgTemplateAdmin(organizationID uuid.UUID) RoleIdentifier { | ||
return RoleIdentifier{Name: RoleOrgTemplateAdmin(), OrganizationID: organizationID} | ||
} | ||
|
||
func allPermsExcept(excepts ...Objecter) []Permission { | ||
|
@@ -365,7 +388,11 @@ func ReloadBuiltinRoles(opts *RoleOptions) { | |
return Role{ | ||
Identifier: RoleIdentifier{Name: orgAdmin, OrganizationID: organizationID}, | ||
DisplayName: "Organization Admin", | ||
Site: []Permission{}, | ||
Site: Permissions(map[string][]policy.Action{ | ||
// To assign organization members, we need to be able to read | ||
// users at the site wide to know they exist. | ||
ResourceUser.Type: {policy.ActionRead}, | ||
}), | ||
Org: map[string][]Permission{ | ||
// Org admins should not have workspace exec perms. | ||
organizationID.String(): append(allPermsExcept(ResourceWorkspace, ResourceWorkspaceDormant, ResourceAssignRole), Permissions(map[string][]policy.Action{ | ||
|
@@ -377,8 +404,7 @@ func ReloadBuiltinRoles(opts *RoleOptions) { | |
} | ||
}, | ||
|
||
// orgMember has an empty set of permissions, this just implies their membership | ||
// in an organization. | ||
// orgMember is an implied role to any member in an organization. | ||
orgMember: func(organizationID uuid.UUID) Role { | ||
return Role{ | ||
Identifier: RoleIdentifier{Name: orgMember, OrganizationID: organizationID}, | ||
|
@@ -406,6 +432,59 @@ func ReloadBuiltinRoles(opts *RoleOptions) { | |
}, | ||
} | ||
}, | ||
orgAuditor: func(organizationID uuid.UUID) Role { | ||
return Role{ | ||
Identifier: RoleIdentifier{Name: orgAuditor, OrganizationID: organizationID}, | ||
DisplayName: "Organization Auditor", | ||
Site: []Permission{}, | ||
Org: map[string][]Permission{ | ||
organizationID.String(): Permissions(map[string][]policy.Action{ | ||
ResourceAuditLog.Type: {policy.ActionRead}, | ||
}), | ||
}, | ||
User: []Permission{}, | ||
} | ||
}, | ||
orgUserAdmin: func(organizationID uuid.UUID) Role { | ||
// Manages organization members and groups. | ||
return Role{ | ||
Identifier: RoleIdentifier{Name: orgUserAdmin, OrganizationID: organizationID}, | ||
DisplayName: "Organization User Admin", | ||
Site: Permissions(map[string][]policy.Action{ | ||
// To assign organization members, we need to be able to read | ||
// users at the site wide to know they exist. | ||
ResourceUser.Type: {policy.ActionRead}, | ||
}), | ||
Comment on lines
+453
to
+457
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be fixed by only needing the org member read permission. But |
||
Org: map[string][]Permission{ | ||
organizationID.String(): Permissions(map[string][]policy.Action{ | ||
// Assign, remove, and read roles in the organization. | ||
ResourceAssignOrgRole.Type: {policy.ActionAssign, policy.ActionDelete, policy.ActionRead}, | ||
ResourceOrganizationMember.Type: {policy.ActionCreate, policy.ActionRead, policy.ActionUpdate, policy.ActionDelete}, | ||
ResourceGroup.Type: ResourceGroup.AvailableActions(), | ||
}), | ||
}, | ||
User: []Permission{}, | ||
} | ||
}, | ||
orgTemplateAdmin: func(organizationID uuid.UUID) Role { | ||
// Manages organization members and groups. | ||
return Role{ | ||
Identifier: RoleIdentifier{Name: orgTemplateAdmin, OrganizationID: organizationID}, | ||
DisplayName: "Organization Template Admin", | ||
Site: []Permission{}, | ||
Org: map[string][]Permission{ | ||
organizationID.String(): Permissions(map[string][]policy.Action{ | ||
ResourceTemplate.Type: {policy.ActionCreate, policy.ActionRead, policy.ActionUpdate, policy.ActionDelete, policy.ActionViewInsights}, | ||
ResourceFile.Type: {policy.ActionCreate, policy.ActionRead}, | ||
ResourceWorkspace.Type: {policy.ActionRead}, | ||
// Assigning template perms requires this permission. | ||
ResourceOrganizationMember.Type: {policy.ActionRead}, | ||
ResourceGroup.Type: {policy.ActionRead}, | ||
}), | ||
}, | ||
User: []Permission{}, | ||
} | ||
}, | ||
} | ||
} | ||
|
||
|
@@ -421,6 +500,9 @@ var assignRoles = map[string]map[string]bool{ | |
member: true, | ||
orgAdmin: true, | ||
orgMember: true, | ||
orgAuditor: true, | ||
orgUserAdmin: true, | ||
orgTemplateAdmin: true, | ||
templateAdmin: true, | ||
userAdmin: true, | ||
customSiteRole: true, | ||
|
@@ -432,6 +514,9 @@ var assignRoles = map[string]map[string]bool{ | |
member: true, | ||
orgAdmin: true, | ||
orgMember: true, | ||
orgAuditor: true, | ||
orgUserAdmin: true, | ||
orgTemplateAdmin: true, | ||
templateAdmin: true, | ||
userAdmin: true, | ||
customSiteRole: true, | ||
|
@@ -444,8 +529,14 @@ var assignRoles = map[string]map[string]bool{ | |
orgAdmin: { | ||
orgAdmin: true, | ||
orgMember: true, | ||
orgAuditor: true, | ||
orgUserAdmin: true, | ||
orgTemplateAdmin: true, | ||
customOrganizationRole: true, | ||
}, | ||
orgUserAdmin: { | ||
orgMember: true, | ||
}, | ||
} | ||
|
||
// ExpandableRoles is any type that can be expanded into a []Role. This is implemented | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unfortunate, but to add a user to an org, we need to know that user exists.