@@ -372,13 +372,12 @@ var (
372
372
DisplayName : "Coder" ,
373
373
Site : rbac .Permissions (map [string ][]policy.Action {
374
374
// May use template, read template-related info, & insert template-related resources (preset prebuilds).
375
- rbac .ResourceTemplate .Type : {policy .ActionRead , policy .ActionUpdate , policy .ActionUse },
375
+ rbac .ResourceTemplate .Type : {policy .ActionRead , policy .ActionUpdate , policy .ActionUse , policy . ActionViewInsights },
376
376
// May CRUD workspaces, and start/stop them.
377
377
rbac .ResourceWorkspace .Type : {
378
378
policy .ActionCreate , policy .ActionDelete , policy .ActionRead , policy .ActionUpdate ,
379
379
policy .ActionWorkspaceStart , policy .ActionWorkspaceStop ,
380
380
},
381
- rbac .ResourceSystem .Type : {policy .ActionRead },
382
381
}),
383
382
},
384
383
}),
@@ -1185,7 +1184,7 @@ func (q *querier) CleanTailnetTunnels(ctx context.Context) error {
1185
1184
}
1186
1185
1187
1186
func (q * querier ) CountInProgressPrebuilds (ctx context.Context ) ([]database.CountInProgressPrebuildsRow , error ) {
1188
- if err := q .authorizeContext (ctx , policy .ActionRead , rbac .ResourceSystem ); err != nil {
1187
+ if err := q .authorizeContext (ctx , policy .ActionRead , rbac .ResourceWorkspace . All () ); err != nil {
1189
1188
return nil , err
1190
1189
}
1191
1190
return q .db .CountInProgressPrebuilds (ctx )
@@ -2135,7 +2134,9 @@ func (q *querier) GetParameterSchemasByJobID(ctx context.Context, jobID uuid.UUI
2135
2134
}
2136
2135
2137
2136
func (q * querier ) GetPrebuildMetrics (ctx context.Context ) ([]database.GetPrebuildMetricsRow , error ) {
2138
- if err := q .authorizeContext (ctx , policy .ActionRead , rbac .ResourceSystem ); err != nil {
2137
+ // GetPrebuildMetrics returns metrics related to prebuilt workspaces,
2138
+ // such as the number of created and failed prebuilt workspaces.
2139
+ if err := q .authorizeContext (ctx , policy .ActionRead , rbac .ResourceWorkspace .All ()); err != nil {
2139
2140
return nil , err
2140
2141
}
2141
2142
return q .db .GetPrebuildMetrics (ctx )
@@ -2174,7 +2175,8 @@ func (q *querier) GetPresetParametersByTemplateVersionID(ctx context.Context, te
2174
2175
}
2175
2176
2176
2177
func (q * querier ) GetPresetsBackoff (ctx context.Context , lookback time.Time ) ([]database.GetPresetsBackoffRow , error ) {
2177
- if err := q .authorizeContext (ctx , policy .ActionRead , rbac .ResourceSystem ); err != nil {
2178
+ // GetPresetsBackoff returns a list of template version presets along with metadata such as the number of failed prebuilds.
2179
+ if err := q .authorizeContext (ctx , policy .ActionViewInsights , rbac .ResourceTemplate .All ()); err != nil {
2178
2180
return nil , err
2179
2181
}
2180
2182
return q .db .GetPresetsBackoff (ctx , lookback )
@@ -2331,7 +2333,8 @@ func (q *querier) GetReplicasUpdatedAfter(ctx context.Context, updatedAt time.Ti
2331
2333
}
2332
2334
2333
2335
func (q * querier ) GetRunningPrebuiltWorkspaces (ctx context.Context ) ([]database.GetRunningPrebuiltWorkspacesRow , error ) {
2334
- if err := q .authorizeContext (ctx , policy .ActionRead , rbac .ResourceSystem ); err != nil {
2336
+ // This query returns only prebuilt workspaces, but we decided to require permissions for all workspaces.
2337
+ if err := q .authorizeContext (ctx , policy .ActionRead , rbac .ResourceWorkspace .All ()); err != nil {
2335
2338
return nil , err
2336
2339
}
2337
2340
return q .db .GetRunningPrebuiltWorkspaces (ctx )
@@ -2462,10 +2465,9 @@ func (q *querier) GetTemplateParameterInsights(ctx context.Context, arg database
2462
2465
}
2463
2466
2464
2467
func (q * querier ) GetTemplatePresetsWithPrebuilds (ctx context.Context , templateID uuid.NullUUID ) ([]database.GetTemplatePresetsWithPrebuildsRow , error ) {
2465
- // Although this fetches presets. It filters them by prebuilds and is only of use to the prebuild system.
2466
- // As such, we authorize this in line with other prebuild queries, not with other preset queries.
2467
-
2468
- if err := q .authorizeContext (ctx , policy .ActionRead , rbac .ResourceSystem ); err != nil {
2468
+ // GetTemplatePresetsWithPrebuilds retrieves template versions with configured presets and prebuilds.
2469
+ // Presets and prebuilds are part of the template, so if you can access templates - you can access them as well.
2470
+ if err := q .authorizeContext (ctx , policy .ActionRead , rbac .ResourceTemplate .All ()); err != nil {
2469
2471
return nil , err
2470
2472
}
2471
2473
return q .db .GetTemplatePresetsWithPrebuilds (ctx , templateID )
0 commit comments