Skip to content

Commit 889b650

Browse files
committed
Only abort early on checks that should be removed
1 parent d6810de commit 889b650

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

coderd/authorize.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,27 @@ type HTTPAuthorizer struct {
5151
// return
5252
// }
5353
func (api *API) Authorize(r *http.Request, action rbac.Action, object rbac.Objecter) bool {
54+
// The experiment does not replace ALL rbac checks, but does replace most.
55+
// This statement aborts early on the checks that will be removed in the
56+
// future when this experiment is default.
5457
if api.Experiments.Enabled(codersdk.ExperimentAuthzQuerier) {
55-
return true
58+
// Some resource types do not interact with the persistent layer and
59+
// we need to keep these checks happening in the API layer.
60+
switch object.RBACObject().Type {
61+
case rbac.ResourceWorkspaceExecution.Type:
62+
// This is not a db resource, always in API layer
63+
case rbac.ResourceDeploymentConfig.Type:
64+
// For metric cache items like DAU, we do not hit the DB.
65+
// Some db actions are in asserted in the authz layer.
66+
case rbac.ResourceReplicas.Type:
67+
// Replica rbac is checked for adding and removing replicas.
68+
case rbac.ResourceProvisionerDaemon.Type:
69+
// Provisioner rbac is checked for adding and removing provisioners.
70+
case rbac.ResourceDebugInfo.Type:
71+
// This is not a db resource, always in API layer.
72+
default:
73+
return true
74+
}
5675
}
5776
return api.HTTPAuth.Authorize(r, action, object)
5877
}

0 commit comments

Comments
 (0)