@@ -3,11 +3,10 @@ package authzquery
3
3
import (
4
4
"context"
5
5
6
- "github.com/coder/coder/coderd/rbac"
7
-
8
6
"github.com/google/uuid"
9
7
10
8
"github.com/coder/coder/coderd/database"
9
+ "github.com/coder/coder/coderd/rbac"
11
10
)
12
11
13
12
func (q * AuthzQuerier ) DeleteGroupByID (ctx context.Context , id uuid.UUID ) error {
@@ -34,9 +33,8 @@ func (q *AuthzQuerier) InsertUserGroupsByName(ctx context.Context, arg database.
34
33
35
34
func (q * AuthzQuerier ) DeleteGroupMembersByOrgAndUser (ctx context.Context , arg database.DeleteGroupMembersByOrgAndUserParams ) error {
36
35
// This will remove the user from all groups in the org. This counts as updating a group.
37
- // Authorizing this 100% correctly requires fetching all groups in the org, and checking if the user is a member.
38
- // If so, we then need to check if the caller has permission to update those groups.
39
- // This is prohibitively expensive, so we instead check if the caller has permission to update *a* group in the org.
36
+ // NOTE: instead of fetching all groups in the org with arg.UserID as a member, we instead
37
+ // check if the caller has permission to update any group in the org.
40
38
fetch := func (ctx context.Context , arg database.DeleteGroupMembersByOrgAndUserParams ) (rbac.Objecter , error ) {
41
39
return rbac .ResourceGroup .InOrg (arg .OrganizationID ), nil
42
40
}
@@ -52,15 +50,10 @@ func (q *AuthzQuerier) GetGroupByOrgAndName(ctx context.Context, arg database.Ge
52
50
}
53
51
54
52
func (q * AuthzQuerier ) GetGroupMembers (ctx context.Context , groupID uuid.UUID ) ([]database.User , error ) {
55
- group , err := q .database .GetGroupByID (ctx , groupID )
56
- if err != nil {
57
- return nil , err
53
+ relatedFunc := func (_ []database.User , groupID uuid.UUID ) (database.Group , error ) {
54
+ return q .database .GetGroupByID (ctx , groupID )
58
55
}
59
- if err := q .authorizeContext (ctx , rbac .ActionRead , group ); err != nil {
60
- return nil , err
61
- }
62
-
63
- return q .database .GetGroupMembers (ctx , groupID )
56
+ return authorizedQueryWithRelated (q .logger , q .authorizer , rbac .ActionRead , relatedFunc , q .database .GetGroupMembers )(ctx , groupID )
64
57
}
65
58
66
59
func (q * AuthzQuerier ) InsertAllUsersGroup (ctx context.Context , organizationID uuid.UUID ) (database.Group , error ) {
0 commit comments