fix: allow users with workspace:create for any owner to list users#21947
Merged
fix: allow users with workspace:create for any owner to list users#21947
Conversation
d1593f3 to
67c0d33
Compare
Custom roles that can create workspaces on behalf of other users need to
be able to list users to populate the owner dropdown in the workspace
creation UI.
This adds a new endpoint:
GET /organizations/{organization}/members/{user}/workspaces/available-users
The endpoint:
- Checks if the user can create workspaces for any owner in the org
- Returns all users (using system context, like templateAvailablePermissions)
- Returns minimal user data (id, username, name, avatar_url)
Also adds SDK method and tests.
Fixes #18203
4d75d11 to
ffc54c5
Compare
Switch the Create Workspace page to use the new scoped
GET /organizations/{org}/members/me/workspaces/available-users
endpoint instead of the global GET /api/v2/users endpoint.
This adds:
- getWorkspaceAvailableUsers API client method
- workspaceAvailableUsers React Query wrapper
- WorkspaceUserAutocomplete component using MinimalUser type
- Updated CreateWorkspacePage owner state to use MinimalUser
The new endpoint only returns users the caller can create workspaces
for, providing a lower-privilege alternative to the global users list.
Emyrk
reviewed
Feb 11, 2026
Member
Emyrk
left a comment
There was a problem hiding this comment.
Add this test to roles_test.go to have a test for which built in roles can do this.
{
Name: "CreateWorkspaceForMembers",
// When creating the WithID won't be set, but it does not change the result.
Actions: []policy.Action{policy.ActionCreate},
Resource: rbac.ResourceWorkspace.InOrg(orgID).WithOwner(policy.WildcardSymbol),
AuthorizeMap: map[bool][]hasAuthSubjects{
true: {owner, orgAdmin},
false: {setOtherOrg, orgUserAdmin, orgAuditor, memberMe, userAdmin, templateAdmin, orgTemplateAdmin},
},
},
Emyrk
approved these changes
Feb 11, 2026
Member
Emyrk
left a comment
There was a problem hiding this comment.
Small nit on the test, and 1 suggested test
Comment on lines
+2967
to
+2997
| func (api *API) workspaceAvailableUsers(rw http.ResponseWriter, r *http.Request) { | ||
| ctx := r.Context() | ||
| organization := httpmw.OrganizationParam(r) | ||
|
|
||
| // This endpoint requires the user to be able to create workspaces for other | ||
| // users in this organization. We check if they can create a workspace with | ||
| // a wildcard owner. | ||
| if !api.Authorize(r, policy.ActionCreate, rbac.ResourceWorkspace.InOrg(organization.ID).WithOwner(policy.WildcardSymbol)) { | ||
| httpapi.Forbidden(rw) | ||
| return | ||
| } | ||
|
|
||
| // Use system context to list all users. The authorization check above | ||
| // ensures only users who can create workspaces for others can access this. | ||
| //nolint:gocritic // System context needed to list users for workspace owner selection. | ||
| users, _, ok := api.GetUsers(rw, r.WithContext(dbauthz.AsSystemRestricted(ctx))) | ||
| if !ok { | ||
| return | ||
| } | ||
|
|
||
| minimalUsers := make([]codersdk.MinimalUser, 0, len(users)) | ||
| for _, user := range users { | ||
| minimalUsers = append(minimalUsers, codersdk.MinimalUser{ | ||
| ID: user.ID, | ||
| Username: user.Username, | ||
| Name: user.Name, | ||
| AvatarURL: user.AvatarURL, | ||
| }) | ||
| } | ||
|
|
||
| httpapi.Write(ctx, rw, http.StatusOK, minimalUsers) |
| t.Run("OwnerCanListUsers", func(t *testing.T) { | ||
| t.Parallel() | ||
| client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) | ||
| owner := coderdtest.CreateFirstUser(t, client) |
Member
There was a problem hiding this comment.
Maybe use an org admin instead. Owners can do everything anyway
- Add CreateWorkspaceForMembers RBAC test case to roles_test.go verifying only owner and orgAdmin can create workspaces for any owner - Change OwnerCanListUsers test to OrgAdminCanListUsers, using an org admin client instead of owner (owners can do everything anyway) - Remove unnecessary IncludeProvisionerDaemon from both test sub-tests
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Custom roles that can create workspaces on behalf of other users need to be able to list users to populate the owner dropdown in the workspace creation UI. Previously, this required a separate
user:readpermission, causing the dropdown to fail for custom roles.Changes
GetUsersindbauthzto check if the user can create workspaces for any owner (workspace:createwithowner_id: *)user:readpermissionTesting
Fixes #18203