- Notifications
You must be signed in to change notification settings - Fork913
feat: allow TemplateAdmin to delete prebuilds via auth layer (POC)#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
base:main
Are you sure you want to change the base?
Conversation
e05480d
todb80b4d
Comparedb80b4d
to2ba15c5
Comparefunc (w Workspace) IsPrebuild() bool { | ||
// TODO: avoid import cycle | ||
return w.OwnerID == uuid.MustParse("c42fdf75-3097-471c-8c33-fb52454d81c0") | ||
} | ||
func (w Workspace) PrebuildRBAC() rbac.Object { | ||
if w.IsPrebuild() { | ||
return rbac.ResourcePrebuiltWorkspace.WithID(w.ID). | ||
InOrg(w.OrganizationID). | ||
WithOwner(w.OwnerID.String()) | ||
} | ||
return w.RBACObject() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
🤔 what about
func (w Workspace) AsPrebuild (rbac.Object, bool) {}if pb, ok := obj.AsPrebuild(); ok { ...}
workspaceObj, ok := object.(database.Workspace) | ||
if ok { | ||
prebuild := workspaceObj.PrebuildRBAC() | ||
// Fallback to normal workspace auth check | ||
if auth := api.Authorize(r, action, prebuild); auth { | ||
return auth | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Suggestion: use inline conditional assignment e.g.
if workspaceObj, ok := object.(database.Workspace); ok { // prebuild auth}
coderd/rbac/roles_test.go Outdated
{ | ||
Name: "PrebuiltWorkspace", | ||
Actions: []policy.Action{policy.ActionRead, policy.ActionUpdate, policy.ActionDelete}, | ||
Resource: rbac.ResourcePrebuiltWorkspace.WithID(uuid.New()).InOrg(orgID).WithOwner(memberMe.Actor.ID), | ||
AuthorizeMap: map[bool][]hasAuthSubjects{ | ||
true: {owner, orgMemberMe, templateAdmin, orgTemplateAdmin}, | ||
false: {setOtherOrg, userAdmin, memberMe, orgAdmin, orgUserAdmin, orgAuditor}, | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think this needs to be two separate tests:
- owner, templateAdmin, orgTemplateAdmin can delete and update
- owner, templateAdmin, orgTemplateAdmin, orgMemberMe can read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ah good point 👍
{ | ||
Name: "PrebuiltWorkspace", | ||
Actions: []policy.Action{policy.ActionRead, policy.ActionUpdate, policy.ActionDelete}, | ||
Resource: rbac.ResourcePrebuiltWorkspace.WithID(uuid.New()).InOrg(orgID).WithOwner(memberMe.Actor.ID), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I thinkWithOwner(memberMe)
is what's tripping you up here. It should be owned by the prebuilds user instead, right?
Uh oh!
There was an error while loading.Please reload this page.
POC (Do not Merge)
Support TemplateAdmin to delete prebuild workspaces via the authorization layer