Skip to content

Commit a18554d

Browse files
committed
feat(oidc): Add flag to forward all logs, even if allowedGroups is set
Signed-off-by: Mathias Petermann <mathias.petermann@swisscom.com>
1 parent 7ec1760 commit a18554d

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

connector/oidc/oidc.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ type Config struct {
7575
InsecureSkipEmailVerified bool `json:"insecureSkipEmailVerified"`
7676

7777
// InsecureEnableGroups enables groups claims. This is disabled by default until https://github.com/dexidp/dex/issues/1065 is resolved
78-
InsecureEnableGroups bool `json:"insecureEnableGroups"`
79-
AllowedGroups []string `json:"allowedGroups"`
78+
InsecureEnableGroups bool `json:"insecureEnableGroups"`
79+
// Restricts login to users that are members of at least one of the specified groups. This is only effective if groups claims are enabled.
80+
AllowedGroups []string `json:"allowedGroups"`
81+
// ForwardAllGroups, if true, will forward all groups from the IdP instead of only the allowed groups when AllowedGroups is set. This is only effective if groups claims are enabled.
82+
ForwardAllGroups bool `json:"forwardAllGroups"`
8083

8184
// AcrValues (Authentication Context Class Reference Values) that specifies the Authentication Context Class Values
8285
// within the Authentication Request that the Authorization Server is being requested to use for
@@ -361,6 +364,7 @@ func (c *Config) Open(id string, logger *slog.Logger) (conn connector.Connector,
361364
insecureSkipEmailVerified: c.InsecureSkipEmailVerified,
362365
insecureEnableGroups: c.InsecureEnableGroups,
363366
allowedGroups: c.AllowedGroups,
367+
forwardAllGroups: c.ForwardAllGroups,
364368
acrValues: c.AcrValues,
365369
getUserInfo: c.GetUserInfo,
366370
promptType: promptType,
@@ -395,6 +399,7 @@ type oidcConnector struct {
395399
insecureSkipEmailVerified bool
396400
insecureEnableGroups bool
397401
allowedGroups []string
402+
forwardAllGroups bool
398403
acrValues []string
399404
getUserInfo bool
400405
promptType string
@@ -675,7 +680,10 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I
675680
return identity, fmt.Errorf("user not a member of allowed groups")
676681
}
677682

678-
groups = groupMatches
683+
// By default only the `allowedGroups` are sent in the token
684+
if !c.forwardAllGroups {
685+
groups = groupMatches
686+
}
679687
}
680688
}
681689

connector/oidc/oidc_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func TestHandleCallback(t *testing.T) {
6363
expectPreferredUsername string
6464
expectedEmailField string
6565
token map[string]interface{}
66+
allowedGroups []string
67+
forwardAllGroups bool
6668
groupsRegex string
6769
newGroupFromClaims []NewGroupFromClaims
6870
groupsPrefix string
@@ -485,6 +487,41 @@ func TestHandleCallback(t *testing.T) {
485487
"email_verified": true,
486488
},
487489
},
490+
{
491+
name: "allowedGroups",
492+
userIDKey: "", // not configured
493+
userNameKey: "", // not configured
494+
expectUserID: "subvalue",
495+
expectUserName: "namevalue",
496+
allowedGroups: []string{"group1", "group2"},
497+
expectGroups: []string{"group1", "group2"},
498+
expectedEmailField: "emailvalue",
499+
token: map[string]interface{}{
500+
"sub": "subvalue",
501+
"name": "namevalue",
502+
"groups": []string{"group1", "group2", "groupA", "groupB"},
503+
"email": "emailvalue",
504+
"email_verified": true,
505+
},
506+
},
507+
{
508+
name: "allowedGroupsForwardAllGroups",
509+
userIDKey: "", // not configured
510+
userNameKey: "", // not configured
511+
expectUserID: "subvalue",
512+
expectUserName: "namevalue",
513+
allowedGroups: []string{"group1", "group2"},
514+
forwardAllGroups: true,
515+
expectGroups: []string{"group1", "group2", "groupA", "groupB"},
516+
expectedEmailField: "emailvalue",
517+
token: map[string]interface{}{
518+
"sub": "subvalue",
519+
"name": "namevalue",
520+
"groups": []string{"group1", "group2", "groupA", "groupB"},
521+
"email": "emailvalue",
522+
"email_verified": true,
523+
},
524+
},
488525
{
489526
name: "S256PKCEChallenge",
490527
userIDKey: "", // not configured
@@ -548,6 +585,8 @@ func TestHandleCallback(t *testing.T) {
548585
UserNameKey: tc.userNameKey,
549586
InsecureSkipEmailVerified: tc.insecureSkipEmailVerified,
550587
InsecureEnableGroups: true,
588+
AllowedGroups: tc.allowedGroups,
589+
ForwardAllGroups: tc.forwardAllGroups,
551590
BasicAuthUnsupported: &basicAuth,
552591
OverrideClaimMapping: tc.overrideClaimMapping,
553592
PKCEChallenge: tc.pkceChallenge,

0 commit comments

Comments
 (0)