-
Notifications
You must be signed in to change notification settings - Fork 899
chore: Update rego to be partial execution friendly #3449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b3536bc
75e3a12
6cdf575
f5eacd0
4a7c68e
df75be5
e90ac2d
1e774e0
38917dc
e139a1f
c44d4d1
19f3557
f9dd9aa
bed9f4f
74d90f4
fe0d05a
dd5c55c
ae22f89
0266963
af457b9
21f4f21
2c87220
1c407ab
9f9b2d1
ab55cf5
abf098d
44c7370
4611322
c8e26a8
510e94b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,27 @@ import ( | |
"github.com/coder/coder/coderd/rbac" | ||
) | ||
|
||
func AuthorizeFilter[O rbac.Objecter](api *API, r *http.Request, action rbac.Action, objects []O) []O { | ||
func AuthorizeFilter[O rbac.Objecter](api *API, r *http.Request, action rbac.Action, objects []O) ([]O, error) { | ||
roles := httpmw.AuthorizationUserRoles(r) | ||
return rbac.Filter(r.Context(), api.Authorizer, roles.ID.String(), roles.Roles, action, objects) | ||
|
||
if len(objects) == 0 { | ||
return objects, nil | ||
} | ||
objecType := objects[0].RBACObject().Type | ||
objects, err := rbac.Filter(r.Context(), api.Authorizer, roles.ID.String(), roles.Roles, action, objecType, objects) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like all of this logic could be in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right about the object type stuff 👍 As for |
||
if err != nil { | ||
api.Logger.Error(r.Context(), "filter failed", | ||
slog.Error(err), | ||
slog.F("object_type", objecType), | ||
slog.F("user_id", roles.ID), | ||
slog.F("username", roles.Username), | ||
slog.F("route", r.URL.Path), | ||
slog.F("action", action), | ||
) | ||
// Hide the underlying error in case it has sensitive information | ||
return nil, xerrors.Errorf("failed to filter requested objects") | ||
Emyrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return objects, nil | ||
} | ||
|
||
// Authorize will return false if the user is not authorized to do the action. | ||
|
Uh oh!
There was an error while loading. Please reload this page.