Skip to content

feat: add prebuilt workspaces to non-default organizations #18010

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 8 commits into from
Jun 4, 2025

Conversation

SasSwart
Copy link
Contributor

@SasSwart SasSwart commented May 23, 2025

Comment on lines +394 to +396
rbac.ResourceOrganizationMember.Type: {
policy.ActionCreate,
},
Copy link
Member

Choose a reason for hiding this comment

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

I think you also need read here to determine which organizations the prebuild system user is a member of.

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.

Overall looks good to me 👍 just a few questions, mainly because I'm not too familiar with the RBAC code.
Also, I agree on using a map to store memberships, that seems like a cleaner approach.

@SasSwart SasSwart marked this pull request as ready for review May 27, 2025 13:30
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.

LGTM, just a couple of minor suggestions to improve the readability of the tests (mostly around naming and comments). I’m not very familiar with the RBAC code, so I’ll defer formal approval to someone with more experience in this area.

Roles: []string{},
})
if err != nil {
membershipInsertionErrors = errors.Join(membershipInsertionErrors, xerrors.Errorf("insert membership for prebuilt workspaces: %w", err))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe it would be useful to add the preset OrganizationID to the error message for further debugging?

@github-actions github-actions bot added the stale This issue is like stale bread. label Jun 4, 2025
@SasSwart SasSwart removed the stale This issue is like stale bread. label Jun 4, 2025
@SasSwart SasSwart requested a review from ssncferreira June 4, 2025 08:12
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.

LGTM 🚀 Just some small non-blocking comments

Comment on lines +52 to +55
// If the prebuilds system user is a member of an organization that doesn't have need any prebuilds,
// then it must have required prebuilds in the past. The membership is not currently necessary, but
// the reconciler won't remove it, because there's little cost to keeping it and prebuilds might be
// enabled again.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect 🥇
Just a small typo:

Suggested change
// If the prebuilds system user is a member of an organization that doesn't have need any prebuilds,
// then it must have required prebuilds in the past. The membership is not currently necessary, but
// the reconciler won't remove it, because there's little cost to keeping it and prebuilds might be
// enabled again.
// If the prebuilds system user is a member of an organization that doesn't currently need any prebuilds,
// then it must have required prebuilds in the past. The membership is not currently necessary, but
// the reconciler won't remove it, because there's little cost to keeping it and prebuilds might be
// enabled again.

func (s StoreMembershipReconciler) ReconcileAll(ctx context.Context, userID uuid.UUID, presets []database.GetTemplatePresetsWithPrebuildsRow) error {
organizationMemberships, err := s.store.GetOrganizationsByUserID(ctx, database.GetOrganizationsByUserIDParams{
UserID: userID,
Deleted: sql.NullBool{
Copy link
Contributor

Choose a reason for hiding this comment

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

I might have missed it, but do we have tests covering the case where a user is deleted?
Non-blocking, just something that might be worth considering in a future PR if not already covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

covering the case where a user is deleted
We don't. Although we allow the userID here is a parameter, it is guaranteed to be the prebuilds system user, so the risk of deletion is low.

coder/internal#526 will ensure that the prebuilds system user is not deleted whenever the reconciliation loop runs.

@SasSwart SasSwart merged commit 5f7e5d7 into main Jun 4, 2025
34 checks passed
@SasSwart SasSwart deleted the jjs/internal-527 branch June 4, 2025 12:20
@github-actions github-actions bot locked and limited conversation to collaborators Jun 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prebuilt workspaces should work in any organization
4 participants