Skip to content

Commit 915b2b0

Browse files
author
Callum Styan
committed
refactor(coderd/dbauthz): use authorizeContext for system check
Replace direct actor type checking with authorizeContext pattern for consistency with other dbauthz wrappers. This checks for ActionRead on ResourceSystem, which will only succeed for system-restricted contexts.
1 parent abddcbe commit 915b2b0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3930,10 +3930,11 @@ func (q *querier) GetWorkspaceResourceByID(ctx context.Context, id uuid.UUID) (d
39303930
// we can bypass the authorization cascade that would normally call
39313931
// GetWorkspaceBuildByJobID.
39323932
func (q *querier) GetWorkspaceResourceWithJobByID(ctx context.Context, id uuid.UUID) (database.GetWorkspaceResourceWithJobByIDRow, error) {
3933-
// Check if this is a system-restricted context.
3934-
actor, ok := ActorFromContext(ctx)
3935-
if !ok || actor.Type != rbac.SubjectTypeSystemRestricted {
3936-
return database.GetWorkspaceResourceWithJobByIDRow{}, xerrors.New("GetWorkspaceResourceWithJobByID requires system-restricted context")
3933+
// Authorize for system resource access. This will only succeed for
3934+
// system-restricted contexts, ensuring this optimized path is only used
3935+
// in appropriate scenarios.
3936+
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
3937+
return database.GetWorkspaceResourceWithJobByIDRow{}, err
39373938
}
39383939

39393940
// With system-restricted context, we can safely bypass the authorization

0 commit comments

Comments
 (0)