- 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?
Changes fromall commits
2ba15c5
a043f92
6cae769
afc5359
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -226,9 +226,26 @@ func (w Workspace) WorkspaceTable() WorkspaceTable { | ||
} | ||
func (w Workspace) RBACObject() rbac.Object { | ||
// if w.IsPrebuild() { | ||
//return w.PrebuildRBAC() | ||
//} | ||
return w.WorkspaceTable().RBACObject() | ||
} | ||
func (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() | ||
} | ||
Comment on lines +235 to +247 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. 🤔 what about
| ||
func (w WorkspaceTable) RBACObject() rbac.Object { | ||
if w.DormantAt.Valid { | ||
return w.DormantRBAC() | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -496,6 +496,15 @@ func TestRolePermissions(t *testing.T) { | ||
false: {setOtherOrg, userAdmin, templateAdmin, memberMe, orgTemplateAdmin, orgUserAdmin, orgAuditor}, | ||
}, | ||
}, | ||
{ | ||
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 commentThe reason will be displayed to describe this comment to others.Learn more. I think | ||
AuthorizeMap: map[bool][]hasAuthSubjects{ | ||
true: {owner, orgAdmin, templateAdmin, orgTemplateAdmin}, | ||
false: {setOtherOrg, userAdmin, memberMe, orgUserAdmin, orgAuditor, orgMemberMe}, | ||
}, | ||
}, | ||
// Some admin style resources | ||
{ | ||
Name: "Licenses", | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -404,6 +404,16 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) { | ||
ctx, | ||
tx, | ||
func(action policy.Action, object rbac.Objecter) bool { | ||
if object.RBACObject().Type == rbac.ResourceWorkspace.Type && action == policy.ActionDelete { | ||
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 | ||
} | ||
} | ||
} | ||
Comment on lines +408 to +416 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggestion: use inline conditional assignment e.g.
| ||
return api.Authorize(r, action, object) | ||
}, | ||
audit.WorkspaceBuildBaggageFromRequest(r), | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.