File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 1
1
package authz
2
2
3
- import "github.com/coder/coder/coderd/authz/rbac"
3
+ import (
4
+ "errors"
5
+
6
+ "github.com/coder/coder/coderd/authz/rbac"
7
+ )
8
+
9
+ var ErrUnauthorized = errors .New ("unauthorized" )
4
10
5
11
// TODO: Implement Authorize
6
- func Authorize (subj Subject , obj Resource , action rbac.Operation ) error {
12
+ func Authorize (subj Subject , res Resource , action rbac.Operation ) error {
7
13
// TODO: Expand subject roles into their permissions as appropriate. Apply scopes.
8
14
9
- return nil
15
+ if SiteEnforcer .RolesHavePermission (subj .Roles (), res .ResourceType (), action ) {
16
+ return nil
17
+ }
18
+
19
+ return ErrUnauthorized
10
20
}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ type Subject interface {
13
13
// object, we can assume the object is owned by this subject.
14
14
ID () string
15
15
16
- Roles () ( rbac.Roles , error )
16
+ Roles () rbac.Roles
17
17
18
18
// OrgRoles only need to be returned for the organization in question.
19
19
// This is because users typically belong to more than 1 organization,
@@ -38,8 +38,8 @@ func (s SubjectTODO) ID() string {
38
38
return s .UserID
39
39
}
40
40
41
- func (s SubjectTODO ) Roles () ( rbac.Roles , error ) {
42
- return s .Site , nil
41
+ func (s SubjectTODO ) Roles () rbac.Roles {
42
+ return s .Site
43
43
}
44
44
45
45
func (s SubjectTODO ) OrgRoles (_ context.Context , orgID string ) (rbac.Roles , error ) {
You can’t perform that action at this time.
0 commit comments