- Notifications
You must be signed in to change notification settings - Fork927
feat: Implement RBAC checks on /templates endpoints#1678
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
291b35b
feat: Generic Filter method for rbac objects
Emyrkb825ce9
Make filter easier to use"
Emyrk561b981
Linting changes
Emyrk3587963
fix unit tests sharing slice
Emyrkbf74b4c
Use authorize filter in more places
Emyrke3a63ad
RBAC template endpoints
Emyrkf401432
Allocate new slice for RBAC filter instead
Emyrk555f815
Merge remote-tracking branch 'origin/main' into stevenmasley/rbac_tem…
EmyrkFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
9 changes: 7 additions & 2 deletionscoderd/authorize.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -12,9 +12,14 @@ import ( | ||
"github.com/coder/coder/coderd/rbac" | ||
) | ||
funcAuthorizeFilter[O rbac.Objecter](api *api, r *http.Request, action rbac.Action,objects []O) []O { | ||
roles := httpmw.UserRoles(r) | ||
return rbac.Filter(r.Context(), api.Authorizer, roles.ID.String(), roles.Roles, action, objects) | ||
} | ||
func (api *api) Authorize(rw http.ResponseWriter, r *http.Request, action rbac.Action, object rbac.Objecter) bool { | ||
roles := httpmw.UserRoles(r) | ||
err := api.Authorizer.ByRoleName(r.Context(), roles.ID.String(), roles.Roles, action, object.RBACObject()) | ||
Emyrk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if err != nil { | ||
httpapi.Write(rw, http.StatusForbidden, httpapi.Response{ | ||
Message: err.Error(), | ||
1 change: 1 addition & 0 deletionscoderd/coderd.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
23 changes: 18 additions & 5 deletionscoderd/coderd_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletionscoderd/database/modelmethods.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package database | ||
import "github.com/coder/coder/coderd/rbac" | ||
func (t Template) RBACObject() rbac.Object { | ||
return rbac.ResourceTemplate.InOrg(t.OrganizationID).WithID(t.ID.String()) | ||
} | ||
func (w Workspace) RBACObject() rbac.Object { | ||
return rbac.ResourceWorkspace.InOrg(w.OrganizationID).WithID(w.ID.String()).WithOwner(w.OwnerID.String()) | ||
} | ||
func (m OrganizationMember) RBACObject() rbac.Object { | ||
return rbac.ResourceOrganizationMember.InOrg(m.OrganizationID).WithID(m.UserID.String()) | ||
} | ||
func (o Organization) RBACObject() rbac.Object { | ||
return rbac.ResourceOrganization.InOrg(o.ID).WithID(o.ID.String()) | ||
} | ||
Emyrk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
19 changes: 18 additions & 1 deletioncoderd/rbac/authz.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
93 changes: 90 additions & 3 deletionscoderd/rbac/authz_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletionscoderd/rbac/fake_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package rbac_test | ||
import ( | ||
"context" | ||
"github.com/coder/coder/coderd/rbac" | ||
) | ||
type fakeAuthorizer struct { | ||
AuthFunc func(ctx context.Context, subjectID string, roleNames []string, action rbac.Action, object rbac.Object) error | ||
} | ||
func (f fakeAuthorizer) ByRoleName(ctx context.Context, subjectID string, roleNames []string, action rbac.Action, object rbac.Object) error { | ||
return f.AuthFunc(ctx, subjectID, roleNames, action, object) | ||
} |
9 changes: 9 additions & 0 deletionscoderd/rbac/object.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletioncoderd/templates.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.