Skip to content

Commit b96bb21

Browse files
committed
Merge remote-tracking branch 'origin/authzquerier_layer' into authzquerier_layer
2 parents eb38c0d + f1f05cc commit b96bb21

File tree

4 files changed

+7
-48
lines changed

4 files changed

+7
-48
lines changed

coderd/activitybump.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@ import (
1010
"golang.org/x/xerrors"
1111

1212
"cdr.dev/slog"
13-
"github.com/coder/coder/coderd/authzquery"
1413
"github.com/coder/coder/coderd/database"
15-
"github.com/coder/coder/coderd/rbac"
1614
)
1715

1816
// activityBumpWorkspace automatically bumps the workspace's auto-off timer
1917
// if it is set to expire soon.
20-
func activityBumpWorkspace(log slog.Logger, db database.Store, workspaceID uuid.UUID) {
18+
func activityBumpWorkspace(ctx context.Context, log slog.Logger, db database.Store, workspaceID uuid.UUID) {
2119
// We set a short timeout so if the app is under load, these
2220
// low priority operations fail first.
23-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
24-
// We always want to use the **system** authz context for this.
25-
ctx = authzquery.WithAuthorizeSystemContext(ctx, rbac.RolesAdminSystem())
21+
ctx, cancel := context.WithTimeout(ctx, time.Second*15)
2622
defer cancel()
2723

2824
err := db.InTx(func(s database.Store) error {

coderd/authzquery/context.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,6 @@ func WithAuthorizeContext(ctx context.Context, actor rbac.Subject) context.Conte
3030
return context.WithValue(ctx, authContextKey{}, actor)
3131
}
3232

33-
// WithWorkspaceAgentTokenContext returns a context with a workspace agent token
34-
// authorization subject. A workspace agent authorization subject is the
35-
// workspace owner's authorization subject + a workspace agent scope.
36-
//
37-
// TODO: The arguments and usage of this function are not finalized. It might
38-
// be a bit awkward to use at present. The arguments are required to build the
39-
// required authorization context. The arguments should be the owner of the
40-
// workspace authorization roles.
41-
func WithWorkspaceAgentTokenContext(ctx context.Context, workspaceID uuid.UUID, actorID uuid.UUID, roles rbac.ExpandableRoles, groups []string) context.Context {
42-
// TODO: This workspace ID should be applied in the scope.
43-
var _ = workspaceID
44-
return context.WithValue(ctx, authContextKey{}, rbac.Subject{
45-
ID: actorID.String(),
46-
Roles: roles,
47-
Scope: rbac.Scope{
48-
Role: rbac.Role{
49-
Name: "workspace-agent-scope",
50-
DisplayName: "Workspace Agent Scope",
51-
// TODO: More permissions are needed for the agent to work.
52-
Site: []rbac.Permission{
53-
{
54-
ResourceType: rbac.ResourceWorkspace.Type,
55-
Action: rbac.ActionRead,
56-
},
57-
{
58-
ResourceType: rbac.ResourceWorkspace.Type,
59-
Action: rbac.ActionRead,
60-
},
61-
// TODO: Read the workspace owner user.
62-
},
63-
Org: map[string][]rbac.Permission{},
64-
User: []rbac.Permission{},
65-
},
66-
// TODO: We need to whitelist more resources such as the workspace
67-
// owner.
68-
AllowIDList: []string{workspaceID.String()},
69-
},
70-
Groups: groups,
71-
})
72-
}
73-
7433
// ActorFromContext returns the authorization subject from the context.
7534
// All authentication flows should set the authorization subject in the context.
7635
// If no actor is present, the function returns false.

coderd/rbac/scopes.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ func (s Scope) Name() string {
4343
return s.Role.Name
4444
}
4545

46+
// WorkspaceAgentScope returns a scope that is the same as ScopeAll but can only
47+
// affect resources in the allow list. Only a scope is returned as the roles
48+
// should come from the workspace owner.
4649
func WorkspaceAgentScope(workspaceID, ownerID uuid.UUID) Scope {
4750
allScope, err := ScopeAll.Expand()
4851
if err != nil {
@@ -58,6 +61,7 @@ func WorkspaceAgentScope(workspaceID, ownerID uuid.UUID) Scope {
5861
AllowIDList: []string{
5962
workspaceID.String(),
6063
ownerID.String(),
64+
// TODO: Might want to include the template the workspace uses too?
6165
},
6266
}
6367
}

coderd/workspaceagents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ func (api *API) workspaceAgentReportStats(rw http.ResponseWriter, r *http.Reques
897897
slog.F("payload", req),
898898
)
899899

900-
activityBumpWorkspace(api.Logger.Named("activity_bump"), api.Database, workspace.ID)
900+
activityBumpWorkspace(ctx, api.Logger.Named("activity_bump"), api.Database, workspace.ID)
901901

902902
payload, err := json.Marshal(req)
903903
if err != nil {

0 commit comments

Comments
 (0)