Skip to content

fix(enterprise/coderd): skip org membership check for prebuilds user on group patch #18329

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 3 commits into from
Jun 23, 2025
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
6 changes: 6 additions & 0 deletions enterprise/coderd/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
})
return
}
// Skip membership checks for the prebuilds user. There is a valid use case
// for adding the prebuilds user to a single group: in order to set a quota
// allowance specifically for prebuilds.
if id == database.PrebuildsSystemUserID.String() {
continue
}
_, err := database.ExpectOne(api.Database.OrganizationMembers(ctx, database.OrganizationMembersParams{
OrganizationID: group.OrganizationID,
UserID: uuid.MustParse(id),
Expand Down
26 changes: 26 additions & 0 deletions enterprise/coderd/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,32 @@ func TestPatchGroup(t *testing.T) {
require.Equal(t, http.StatusBadRequest, cerr.StatusCode())
})

// For quotas to work with prebuilds, it's currently required to add the
// prebuilds user into a group with a quota allowance.
// See: docs/admin/templates/extending-templates/prebuilt-workspaces.md
t.Run("PrebuildsUser", func(t *testing.T) {
t.Parallel()

client, user := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureTemplateRBAC: 1,
},
}})
userAdminClient, _ := coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleUserAdmin())
ctx := testutil.Context(t, testutil.WaitLong)
group, err := userAdminClient.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
Name: "prebuilds",
QuotaAllowance: 123,
})
require.NoError(t, err)

group, err = userAdminClient.PatchGroup(ctx, group.ID, codersdk.PatchGroupRequest{
Name: "prebuilds",
AddUsers: []string{database.PrebuildsSystemUserID.String()},
})
require.NoError(t, err)
})

t.Run("Everyone", func(t *testing.T) {
t.Parallel()
t.Run("NoUpdateName", func(t *testing.T) {
Expand Down
Loading