- Notifications
You must be signed in to change notification settings - Fork929
feat: Implement list roles & enforce authorize examples#1273
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
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
30e2031
2161f84
54bc054
d083a7c
95b9a14
1498dcd
f36ae37
b831260
db04d67
b76f373
117f838
42b42ab
0efe72c
dba617d
190940f
c86c67c
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -13,23 +13,15 @@ import ( | ||
"github.com/coder/coder/coderd/rbac" | ||
) | ||
// Authorize will enforce if the user roles can complete the action on the AuthObject. | ||
// The organization and owner are found using the ExtractOrganization and | ||
// ExtractUser middleware if present. | ||
func Authorize(logger slog.Logger, auth *rbac.RegoAuthorizer, action rbac.Action) func(http.Handler) http.Handler { | ||
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.
What do you think about renaming this to 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. I think
Another word that comes to mind is "Access". Idk, 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. Fair enough. I'm primarily trying to display that the While it isauthorizing, I'm nervous that this will get conflated with authentication really easily. 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. yea this is classic authorization vs authentication. If you aren't familiar with it, it's easy to mix up. 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. Agreed agreed | ||
return func(next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { | ||
roles := UserRoles(r) | ||
object :=authObject(r) | ||
if object.Type == "" { | ||
panic("developer error: auth object has no type") | ||
} | ||
@@ -80,8 +72,8 @@ func Authorize(logger slog.Logger, auth *rbac.RegoAuthorizer, action rbac.Action | ||
type authObjectKey struct{} | ||
// APIKey returns the API key from the ExtractAPIKey handler. | ||
funcauthObject(r *http.Request)rbac.Object { | ||
obj, ok := r.Context().Value(authObjectKey{}).(rbac.Object) | ||
if !ok { | ||
panic("developer error: auth object middleware not provided") | ||
} | ||
@@ -93,10 +85,7 @@ func GetAuthObject(r *http.Request) AuthObject { | ||
func WithRBACObject(object rbac.Object) func(http.Handler) http.Handler { | ||
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. It might be confusing that this is called | ||
return func(next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { | ||
ctx := context.WithValue(r.Context(), authObjectKey{}, object) | ||
next.ServeHTTP(rw, r.WithContext(ctx)) | ||
}) | ||
} | ||