Skip to content

Commit 5db3d25

Browse files
committed
Reuse system rbac subject
1 parent d6edd29 commit 5db3d25

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

coderd/httpmw/workspaceproxy.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/coder/coder/coderd/database"
1515
"github.com/coder/coder/coderd/database/dbauthz"
1616
"github.com/coder/coder/coderd/httpapi"
17-
"github.com/coder/coder/coderd/rbac"
1817
"github.com/coder/coder/codersdk"
1918
)
2019

@@ -136,23 +135,22 @@ func ExtractExternalProxy(opts ExtractExternalProxyConfig) func(http.Handler) ht
136135

137136
ctx = r.Context()
138137
ctx = context.WithValue(ctx, externalProxyContextKey{}, proxy)
139-
ctx = context.WithValue(ctx, userAuthKey{}, Authorization{
140-
Actor: rbac.Subject{
141-
ID: "proxy:" + proxy.ID.String(),
142-
// We don't have a system role currently so just use owner
143-
// for now.
144-
// TODO: add a system role
145-
Roles: rbac.RoleNames{rbac.RoleOwner()},
146-
Groups: []string{},
147-
Scope: rbac.ScopeAll,
148-
},
149-
ActorName: "proxy_" + proxy.Name,
150-
})
151138
//nolint:gocritic // Workspace proxies have full permissions. The
152139
// workspace proxy auth middleware is not mounted to every route, so
153140
// they can still only access the routes that the middleware is
154141
// mounted to.
155142
ctx = dbauthz.AsSystemRestricted(ctx)
143+
subj, ok := dbauthz.ActorFromContext(ctx)
144+
if !ok {
145+
// This should never happen
146+
httpapi.InternalServerError(w, xerrors.New("developer error: ExtractExternalProxy missing rbac actor"))
147+
return
148+
}
149+
// Use the same subject for the userAuthKey
150+
ctx = context.WithValue(ctx, userAuthKey{}, Authorization{
151+
Actor: subj,
152+
ActorName: "proxy_" + proxy.Name,
153+
})
156154

157155
next.ServeHTTP(w, r.WithContext(ctx))
158156
})

0 commit comments

Comments
 (0)