Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: allow TemplateAdmin to delete prebuilds via auth layer#18333

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ssncferreira merged 15 commits intomainfromssncferreira/poc-prebuild-rbac-authz
Jun 20, 2025

Conversation

ssncferreira
Copy link
Contributor

@ssncferreirassncferreira commentedJun 11, 2025
edited
Loading

Description

This PR adds support for deleting prebuilt workspaces via the authorization layer. It introduces special-case handling to ensure thatprebuilt_workspace permissions are evaluated when attempting to delete a prebuilt workspace, falling back to the standardworkspace resource as needed.

Prebuilt workspaces are a subset of workspaces, identified by havingowner_id set toPREBUILD_SYSTEM_USER.
This means:

  • A user withprebuilt_workspace.delete permission is allowed todelete only prebuilt workspaces.
  • A user withworkspace.delete permission candelete both normal and prebuilt workspaces.

⚠️ This implementation is scoped todeletion operations only. No other operations are currently supported for theprebuilt_workspace resource.

To delete a workspace, users must have the following permissions:

  • workspace.read: to read the current workspace state
  • update: to modify workspace metadata and related resources during deletion (e.g., updating thedeleted field in the database)
  • delete: to perform the actual deletion of the workspace

Changes

  • IntroducedauthorizeWorkspace() helper to handle prebuilt workspace authorization logic.
  • Ensured bothprebuilt_workspace andworkspace permissions are checked.
  • Added comments to clarify the current behavior and limitations.
  • MovedSystemUserID constant from theprebuilds package to thedatabase packagePrebuildsSystemUserID to resolve an import cycle (commitf24e4ab).
  • Update middlewareExtractOrganizationMember to include system user members.

@ssncferreirassncferreira changed the titlefeat: POC for allowing TemplateAdmin to delete prebuild workspaces via auth layerfeat: poc to allow TemplateAdmin to delete prebuilds via auth layerJun 11, 2025
@ssncferreirassncferreiraforce-pushed thessncferreira/poc-prebuild-rbac-authz branch 2 times, most recently frome05480d todb80b4dCompareJune 11, 2025 19:37
@ssncferreirassncferreiraforce-pushed thessncferreira/poc-prebuild-rbac-authz branch fromdb80b4d to2ba15c5CompareJune 11, 2025 19:38
@ssncferreirassncferreira changed the titlefeat: poc to allow TemplateAdmin to delete prebuilds via auth layerfeat: allow TemplateAdmin to delete prebuilds via auth layer in POCJun 12, 2025
@ssncferreirassncferreira changed the titlefeat: allow TemplateAdmin to delete prebuilds via auth layer in POCfeat: allow TemplateAdmin to delete prebuilds via auth layer (POC)Jun 12, 2025
@ssncferreirassncferreira marked this pull request as ready for reviewJune 18, 2025 09:06
@ssncferreirassncferreira changed the titlefeat: allow TemplateAdmin to delete prebuilds via auth layer (POC)feat: allow TemplateAdmin to delete prebuilds via auth layerJun 18, 2025
@ssncferreirassncferreira requested a review fromEmyrkJune 18, 2025 18:45
Comment on lines +278 to +281
// PrebuiltWorkspaces are a subset of Workspaces.
// Explicitly setting PrebuiltWorkspace permissions for clarity.
// Note: even without PrebuiltWorkspace permissions, access is still granted via Workspace permissions.
ResourcePrebuiltWorkspace.Type: {policy.ActionUpdate, policy.ActionDelete},
Copy link
Member

Choose a reason for hiding this comment

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

👍 Always +1 for clarity.

ssncferreira reacted with heart emoji
@@ -180,7 +180,7 @@ func ExtractOrganizationMember(ctx context.Context, auth func(r *http.Request, a
organizationMembers, err := db.OrganizationMembers(ctx, database.OrganizationMembersParams{
OrganizationID: orgID,
UserID: user.ID,
IncludeSystem:false,
IncludeSystem:true,
Copy link
Member

Choose a reason for hiding this comment

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

review: this is required in order to be able to delete a prebuilt workspace from the CLI, as it needs to fetch it first.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Added to the PR description as well:

  • Update middleware ExtractOrganizationMember to include system user members.

Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

Nice work! I don't have any blocking comments.

ssncferreira reacted with heart emoji
@ssncferreirassncferreira requested a review fromEmyrkJune 20, 2025 14:01
Copy link
Member

@EmyrkEmyrk left a comment

Choose a reason for hiding this comment

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

Requiringworkspace.read simplifies the problem. 👍

ssncferreira reacted with thumbs up emoji
Comment on lines +163 to +172
if (action==policy.ActionUpdate||action==policy.ActionDelete)&&workspace.IsPrebuild() {
// Try prebuilt-specific authorization first
ifprebuiltErr=q.authorizeContext(ctx,action,workspace.AsPrebuild());prebuiltErr==nil {
returnnil
}
}
// Fallback to normal workspace authorization check
iferr:=q.authorizeContext(ctx,action,workspace);err!=nil {
returnxerrors.Errorf("authorize context: %w",errors.Join(prebuiltErr,err))
}
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 the normal workspace check is more likely to succeed then the prebuild. So it might be a slight optimization to flip these checks.

But that will probably break some of the unit tests? No need to change this, just a thought.

ssncferreira reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Good point, I had considered that optimization as well. I believe it might require some test updates, so I'd prefer to merge this PR and address the optimization in a follow-up PR.

@@ -5564,3 +5564,63 @@ func (s *MethodTestSuite) TestChat() {
}).Asserts(c, policy.ActionUpdate)
}))
}

func (s *MethodTestSuite) TestAuthorizePrebuiltWorkspace() {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@ssncferreirassncferreira merged commit72f7d70 intomainJun 20, 2025
38 of 39 checks passed
@ssncferreirassncferreira deleted the ssncferreira/poc-prebuild-rbac-authz branchJune 20, 2025 16:36
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJun 20, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@EmyrkEmyrkEmyrk approved these changes

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@ssncferreirassncferreira

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@ssncferreira@johnstcn@Emyrk

[8]ページ先頭

©2009-2025 Movatter.jp