Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1550cc6

Browse files
chore: update rbac
1 parent 456989e commit 1550cc6

File tree

7 files changed

+31
-4
lines changed

7 files changed

+31
-4
lines changed

coderd/agentapi/resources_monitoring.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (a *ResourcesMonitoringAPI) monitorMemory(ctx context.Context, datapoints [
136136
debouncedUntil = a.Clock.Now().Add(a.Debounce)
137137
}
138138

139-
err = a.Database.UpdateMemoryResourceMonitor(ctx, database.UpdateMemoryResourceMonitorParams{
139+
err = a.Database.UpdateMemoryResourceMonitor(dbauthz.AsResourceMonitor(ctx), database.UpdateMemoryResourceMonitorParams{
140140
AgentID: a.AgentID,
141141
State: newState,
142142
UpdatedAt: dbtime.Time(a.Clock.Now()),
@@ -217,7 +217,7 @@ func (a *ResourcesMonitoringAPI) monitorVolumes(ctx context.Context, datapoints
217217
})
218218
}
219219

220-
if err := a.Database.UpdateVolumeResourceMonitor(ctx, database.UpdateVolumeResourceMonitorParams{
220+
if err := a.Database.UpdateVolumeResourceMonitor(dbauthz.AsResourceMonitor(ctx), database.UpdateVolumeResourceMonitorParams{
221221
AgentID: a.AgentID,
222222
Path: monitor.Path,
223223
State: newState,

coderd/database/dbauthz/dbauthz.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,24 @@ var (
289289
Scope: rbac.ScopeAll,
290290
}.WithCachedASTValue()
291291

292+
subjectResourceMonitor = rbac.Subject{
293+
FriendlyName: "Resource Monitor",
294+
ID: uuid.Nil.String(),
295+
Roles: rbac.Roles([]rbac.Role{
296+
{
297+
Identifier: rbac.RoleIdentifier{Name: "resourcemonitor"},
298+
DisplayName: "Resource Monitor",
299+
Site: rbac.Permissions(map[string][]policy.Action{
300+
// The workspace monitor needs to be able to update monitors
301+
rbac.ResourceWorkspaceAgentResourceMonitor.Type: {policy.ActionUpdate},
302+
}),
303+
Org: map[string][]rbac.Permission{},
304+
User: []rbac.Permission{},
305+
},
306+
}),
307+
Scope: rbac.ScopeAll,
308+
}.WithCachedASTValue()
309+
292310
subjectSystemRestricted = rbac.Subject{
293311
FriendlyName: "System",
294312
ID: uuid.Nil.String(),
@@ -376,6 +394,12 @@ func AsNotifier(ctx context.Context) context.Context {
376394
return context.WithValue(ctx, authContextKey{}, subjectNotifier)
377395
}
378396

397+
// AsResourceMonitor returns a context with an actor that has permissions required for
398+
// updating resource monitors.
399+
func AsResourceMonitor(ctx context.Context) context.Context {
400+
return context.WithValue(ctx, authContextKey{}, subjectResourceMonitor)
401+
}
402+
379403
// AsSystemRestricted returns a context with an actor that has permissions
380404
// required for various system operations (login, logout, metrics cache).
381405
func AsSystemRestricted(ctx context.Context) context.Context {

coderd/rbac/object_gen.go

Lines changed: 1 addition & 0 deletions
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ var RBACPermissions = map[string]PermissionDefinition{
306306
Actions: map[Action]ActionDefinition{
307307
ActionRead: actDef("read workspace agent resource monitor"),
308308
ActionCreate: actDef("create workspace agent resource monitor"),
309+
ActionUpdate: actDef("update workspace agent resource monitor"),
309310
},
310311
},
311312
}

coderd/rbac/roles_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ func TestRolePermissions(t *testing.T) {
779779
},
780780
{
781781
Name: "ResourceMonitor",
782-
Actions: []policy.Action{policy.ActionRead, policy.ActionCreate},
782+
Actions: []policy.Action{policy.ActionRead, policy.ActionCreate, policy.ActionUpdate},
783783
Resource: rbac.ResourceWorkspaceAgentResourceMonitor,
784784
AuthorizeMap: map[bool][]hasAuthSubjects{
785785
true: {owner},

codersdk/rbacresources_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.

site/src/api/rbacresourcesGenerated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export const RBACResourceActions: Partial<
171171
workspace_agent_resource_monitor: {
172172
create: "create workspace agent resource monitor",
173173
read: "read workspace agent resource monitor",
174+
update: "update workspace agent resource monitor",
174175
},
175176
workspace_dormant: {
176177
application_connect: "connect to workspace apps via browser",

0 commit comments

Comments
 (0)