Skip to content

Commit 74632e4

Browse files
authored
fix: adjust build state permission to require template update (#6472)
1 parent 29ced72 commit 74632e4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

coderd/coderdtest/authorize.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
132132
AssertObject: workspaceRBACObj,
133133
},
134134
"GET:/api/v2/workspacebuilds/{workspacebuild}/state": {
135-
AssertAction: rbac.ActionRead,
136-
AssertObject: workspaceRBACObj,
135+
AssertAction: rbac.ActionUpdate,
136+
AssertObject: templateObj,
137137
},
138138
"GET:/api/v2/workspaceagents/{workspaceagent}": {
139139
AssertAction: rbac.ActionRead,

coderd/workspacebuilds.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,18 @@ func (api *API) workspaceBuildState(rw http.ResponseWriter, r *http.Request) {
892892
})
893893
return
894894
}
895+
template, err := api.Database.GetTemplateByID(ctx, workspace.TemplateID)
896+
if err != nil {
897+
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
898+
Message: "Failed to get template",
899+
Detail: err.Error(),
900+
})
901+
return
902+
}
895903

896-
if !api.Authorize(r, rbac.ActionRead, workspace) {
904+
// You must have update permissions on the template to get the state.
905+
// This matches a push!
906+
if !api.Authorize(r, rbac.ActionUpdate, template.RBACObject()) {
897907
httpapi.ResourceNotFound(rw)
898908
return
899909
}

0 commit comments

Comments
 (0)