Skip to content

feat(enterprise/coderd): allow system users to be added to groups #18341

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

SasSwart
Copy link
Contributor

@SasSwart SasSwart commented Jun 12, 2025

closes #18274

This pull request makes system users visible in various group related queries so that they can be added to groups. This allows system user quotas to be configured. System users are still ignored in certain queries, such as when license seat consumption is determined.

Summary by CodeRabbit

  • New Features
    • Organization and group member listings now include system users.
  • Bug Fixes
    • Updated tests to reflect the inclusion of system users in member and group queries.

@SasSwart SasSwart changed the title feat: allow system users to be added to groups feat(enterprise/coderd): allow system users to be added to groups Jun 12, 2025
@github-actions github-actions bot added the stale This issue is like stale bread. label Jun 20, 2025
@github-actions github-actions bot closed this Jun 23, 2025
@johnstcn johnstcn reopened this Jun 23, 2025
@johnstcn johnstcn removed the stale This issue is like stale bread. label Jun 23, 2025
@github-actions github-actions bot added the stale This issue is like stale bread. label Jul 1, 2025
@github-actions github-actions bot closed this Jul 5, 2025
@SasSwart SasSwart reopened this Jul 14, 2025
@SasSwart SasSwart removed the stale This issue is like stale bread. label Jul 14, 2025
@SasSwart SasSwart requested a review from ssncferreira July 14, 2025 13:55
@SasSwart SasSwart marked this pull request as ready for review July 14, 2025 13:55
Copy link
Contributor

@ssncferreira ssncferreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about this approach. Do we need to add IncludeSystem: true to all these queries just to support the prebuilds system user?
This means someone will need to manually create a group for the prebuilds user and assign it a quota, right?

Wouldn't it be more robust to automatically create a group for the prebuilds system user with a default quota, and allow users to override it if needed? That way, we avoid having to include system users in these queries and reduce the risk of system users leaking into user-facing features.

Comment on lines +92 to +97
-- Filter by system type
AND CASE
WHEN @include_system::bool THEN TRUE
ELSE
is_system = false
END
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit for readability:

Suggested change
-- Filter by system type
AND CASE
WHEN @include_system::bool THEN TRUE
ELSE
is_system = false
END
-- Conditionally include system users based on @include_system flag
AND (@include_system OR is_system = false)

@SasSwart
Copy link
Contributor Author

The prebuilds user has already leaked into user facing features. Administrators search for prebuilds by specifying the prebuilds user on the workspace list page. For consistency and clarity, I think we should embrace listing and showing the prebuilds user.

I like the idea of automatically creating a prebuilds group, but we'll need to decide what a sensible default quota would be if there is such a value that makes sense.

@ssncferreira
Copy link
Contributor

ssncferreira commented Jul 16, 2025

The prebuilds user has already leaked into user facing features. Administrators search for prebuilds by specifying the prebuilds user on the workspace list page. For consistency and clarity, I think we should embrace listing and showing the prebuilds user.

It’s true that the prebuilds user is already exposed in some user-facing features, like showing prebuilt workspaces, but that might not be the ideal approach 😕 The issue isn’t just about the prebuilds user, it extends to listing all current and future system users.

I like the idea of automatically creating a prebuilds group, but we'll need to decide what a sensible default quota would be if there is such a value that makes sense.

We already have a precedent with the Everyone group:

-- name: InsertAllUsersGroup :one
INSERT INTO groups (
id,
name,
organization_id
)
VALUES
(sqlc.arg(organization_id), 'Everyone', sqlc.arg(organization_id)) RETURNING *;

We could apply the same pattern here: automatically create the prebuilds group with a default quota of 0, and clearly document this behavior along with instructions on how users can update the quota if needed.

@github-actions github-actions bot added the stale This issue is like stale bread. label Jul 24, 2025
Copy link

coderabbitai bot commented Jul 24, 2025

Caution

Review failed

The head commit changed during the review from 1cd68e3 to 4c0c4d4.

Walkthrough

This change updates the logic for retrieving organization and group members to consistently include system users, such as the prebuilds system user, by default. It introduces a new boolean parameter to control this behavior in both SQL queries and Go code, and updates related tests to expect the presence of system users in member lists.

Changes

Files / Areas Change Summary
coderd/database/queries.sql.go, coderd/database/queries/organizationmembers.sql Added IncludeSystem boolean parameter to queries and Go structs/methods; updated SQL to filter system users.
coderd/members.go Modified queries to include system users by setting IncludeSystem: true.
enterprise/coderd/groups.go Updated group member queries to include system users (IncludeSystem: true).
coderd/members_test.go, enterprise/coderd/groups_test.go, enterprise/coderd/roles_test.go Updated tests to expect system users in member lists and adjusted assertions accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant API
    participant MembersService
    participant Database

    API->>MembersService: Request organization/group members
    MembersService->>Database: Query members (IncludeSystem: true)
    Database-->>MembersService: Return all members (including system users)
    MembersService-->>API: Return member list with system users
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

In the warren of code, a new rule appears,
System users hop in, dispelling old fears.
Member lists grow, with prebuilds in tow,
The queries now know who’s included below.
Tests count the bunnies, one more in the sun—
With every new member, the job is well done!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jjs/prebuilds-user-group-membership

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot removed the stale This issue is like stale bread. label Jul 25, 2025
@SasSwart SasSwart requested a review from ssncferreira July 29, 2025 09:09
Copy link
Contributor

@ssncferreira ssncferreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also add a test case that verifies the behavior when the prebuilds quota is actually used? I'm curious about what QuotaAllowance: 0 means in practice, does this mean prebuild creation will always fail due to no quota, or does 0 represent unlimited/no enforcement?
It would be helpful to have a test that actually attempts to create prebuilds after the group is set up to clarify this behavior and ensure the default quota setting works as intended.

_, err = s.store.InsertOrganizationMember(ctx, database.InsertOrganizationMemberParams{
// Create a "prebuilds" group in the organization and add the system user to it
// This group will have a quota of 0 by default, which users can adjust based on their needs
prebuildsGroup, err := s.store.InsertGroup(ctx, database.InsertGroupParams{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be done inside the if !alreadyOrgMember { condition? This way there was no need for all the additional unique violation checks, right? Or am I missing something? 🤔

@@ -156,7 +156,7 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {

currentMembers, err := api.Database.GetGroupMembersByGroupID(ctx, database.GetGroupMembersByGroupIDParams{
GroupID: group.ID,
IncludeSystem: false,
IncludeSystem: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need all these IncludeSystem: true cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, because I maintain that the prebuilds user should be visible. If we decide that we should hide the prebuilds user, then we can revert this back to false.

preExistingMembership bool
name string
includePreset []bool
preExistingOrgMembership []bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused here, why are we now using a slice of bool in these cases? Could you add a comment here as well as in the test cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The slices of bool allow us to test all the combinations of these scenarios. so in two "test cases", we actually technically have 16 tests.


if tc.expectUserInGroup != nil && !*tc.expectUserInGroup {
// Check that the system user is NOT a member of the prebuilds group
groupMembers, err := db.GetGroupMembersByGroupID(ctx, database.GetGroupMembersByGroupIDParams{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the prebuilds user always be part of the prebuilds group? Or is this the case where an organization doesn't have prebuilds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should. This is a defensive measure against an edge case where such a group happens to already exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Workspace prebuilds conform to the site quota, leading many to fail
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy