Skip to content

Commit 21d0f97

Browse files
committed
httpmw: pass systemCtx to getAgentSubject, add OwnerID to workspace agent scopes
1 parent 04e32bc commit 21d0f97

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

coderd/httpmw/workspaceagent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func ExtractWorkspaceAgent(db database.Store) func(http.Handler) http.Handler {
6565
return
6666
}
6767

68-
subject, err := getAgentSubject(ctx, db, agent)
68+
subject, err := getAgentSubject(systemCtx, db, agent)
6969
if err != nil {
7070
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
7171
Message: "Internal error fetching workspace agent.",
@@ -107,6 +107,6 @@ func getAgentSubject(ctx context.Context, db database.Store, agent database.Work
107107
ID: user.ID.String(),
108108
Roles: rbac.RoleNames(roles.Roles),
109109
Groups: roles.Groups,
110-
Scope: rbac.WorkspaceAgentScope(workspace.ID),
110+
Scope: rbac.WorkspaceAgentScope(workspace.ID, user.ID),
111111
}, nil
112112
}

coderd/rbac/scopes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (s Scope) Name() string {
4343
return s.Role.Name
4444
}
4545

46-
func WorkspaceAgentScope(workspaceID uuid.UUID) Scope {
46+
func WorkspaceAgentScope(workspaceID, ownerID uuid.UUID) Scope {
4747
allScope, err := ScopeAll.Expand()
4848
if err != nil {
4949
panic("failed to expand scope all, this should never happen")
@@ -57,6 +57,7 @@ func WorkspaceAgentScope(workspaceID uuid.UUID) Scope {
5757
// This prevents the agent from being able to access any other resource.
5858
AllowIDList: []string{
5959
workspaceID.String(),
60+
ownerID.String(),
6061
},
6162
}
6263
}

coderd/workspaceagents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func (api *API) workspaceAgent(rw http.ResponseWriter, r *http.Request) {
8080
// @Success 200 {object} agentsdk.Metadata
8181
// @Router /workspaceagents/me/metadata [get]
8282
func (api *API) workspaceAgentMetadata(rw http.ResponseWriter, r *http.Request) {
83-
ctx := r.Context()
8483
workspaceAgent := httpmw.WorkspaceAgent(r)
84+
ctx := r.Context()
8585
apiAgent, err := convertWorkspaceAgent(api.DERPMap, *api.TailnetCoordinator.Load(), workspaceAgent, nil, api.AgentInactiveDisconnectTimeout, api.DeploymentConfig.AgentFallbackTroubleshootingURL.Value)
8686
if err != nil {
8787
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{

0 commit comments

Comments
 (0)