@@ -2,6 +2,7 @@ package enidpsync
2
2
3
3
import (
4
4
"context"
5
+ "net/http"
5
6
6
7
"github.com/golang-jwt/jwt/v4"
7
8
@@ -11,7 +12,6 @@ import (
11
12
12
13
func (e EnterpriseIDPSync ) GroupSyncEnabled () bool {
13
14
return e .entitlements .Enabled (codersdk .FeatureTemplateRBAC )
14
-
15
15
}
16
16
17
17
// ParseGroupClaims parses the user claims and handles deployment wide group behavior.
@@ -23,6 +23,46 @@ func (e EnterpriseIDPSync) ParseGroupClaims(ctx context.Context, mergedClaims jw
23
23
return e .AGPLIDPSync .ParseGroupClaims (ctx , mergedClaims )
24
24
}
25
25
26
+ if e .GroupField != "" && len (e .GroupAllowList ) > 0 {
27
+ groupsRaw , ok := mergedClaims [e .GroupField ]
28
+ if ! ok {
29
+ return idpsync.GroupParams {}, & idpsync.HTTPError {
30
+ Code : http .StatusForbidden ,
31
+ Msg : "Not a member of an allowed group" ,
32
+ Detail : "You have no groups in your claims!" ,
33
+ RenderStaticPage : true ,
34
+ }
35
+ }
36
+ parsedGroups , err := idpsync .ParseStringSliceClaim (groupsRaw )
37
+ if err != nil {
38
+ return idpsync.GroupParams {}, & idpsync.HTTPError {
39
+ Code : http .StatusBadRequest ,
40
+ Msg : "Failed read groups from claims for allow list check. Ask an administrator for help." ,
41
+ Detail : err .Error (),
42
+ RenderStaticPage : true ,
43
+ }
44
+ }
45
+
46
+ inAllowList := false
47
+ AllowListCheckLoop:
48
+ for _ , group := range parsedGroups {
49
+ if _ , ok := e .GroupAllowList [group ]; ok {
50
+ inAllowList = true
51
+ break AllowListCheckLoop
52
+ }
53
+ }
54
+
55
+ if ! inAllowList {
56
+ return idpsync.GroupParams {}, & idpsync.HTTPError {
57
+ Code : http .StatusForbidden ,
58
+ Msg : "Not a member of an allowed group" ,
59
+ Detail : "Ask an administrator to add one of your groups to the allow list." ,
60
+ RenderStaticPage : true ,
61
+ }
62
+ }
63
+
64
+ }
65
+
26
66
return idpsync.GroupParams {
27
67
SyncEnabled : e .OrganizationSyncEnabled (),
28
68
MergedClaims : mergedClaims ,
0 commit comments