Skip to content

Commit 343c70d

Browse files
committed
check use perm on creating a workspace
1 parent bf439e8 commit 343c70d

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

coderd/rbac/object_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/rbac/policy/policy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ var RBACPermissions = map[string]PermissionDefinition{
134134
"template": {
135135
Actions: map[Action]ActionDefinition{
136136
ActionCreate: actDef("create a template"),
137-
ActionUse: actDef("use the template to create a workspace"),
137+
ActionUse: actDef("use the template to initially create a workspace, then workspace lifecycle permissions take over"),
138138
ActionRead: actDef("read template"),
139139
ActionUpdate: actDef("update a template"),
140140
ActionDelete: actDef("delete a template"),

coderd/workspaces.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,18 @@ func createWorkspace(
515515
return
516516
}
517517

518+
// The user also needs permission to use the template. At this point they have
519+
// read perms, but not necessarily "use"
520+
if !api.Authorize(r, policy.ActionUse, template) {
521+
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
522+
Message: fmt.Sprintf("Unauthorized access to use the template %q.", template.Name),
523+
Detail: "Although you are able to view the template, you are unable to create a workspace using it. " +
524+
"Please contact an administrator about your permissions if you feel this is an error.",
525+
Validations: nil,
526+
})
527+
return
528+
}
529+
518530
// Update audit log's organization
519531
auditReq.UpdateOrganizationID(template.OrganizationID)
520532

site/src/api/rbacresourcesGenerated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export const RBACResourceActions: Partial<
144144
delete: "delete a template",
145145
read: "read template",
146146
update: "update a template",
147-
use: "use the template to create a workspace",
147+
use: "use the template to initially create a workspace, then workspace lifecycle permissions take over",
148148
view_insights: "view insights",
149149
},
150150
user: {

0 commit comments

Comments
 (0)