Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement google group claim in JWT #3449

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion connector/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type Config struct {

// If this field is true, fetch direct group membership and transitive group membership
FetchTransitiveGroupMembership bool `json:"fetchTransitiveGroupMembership"`

// enfore group claim on JWT
EnforceGroupClaim bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EnforceGroupClaim bool
EnforceGroupClaim bool `json:"enforceGroupClaim"`

}

// Open returns a connector which can be used to login users through Google.
Expand Down Expand Up @@ -128,6 +131,7 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e
domainToAdminEmail: c.DomainToAdminEmail,
fetchTransitiveGroupMembership: c.FetchTransitiveGroupMembership,
adminSrv: adminSrv,
EnforceGroupClaim: c.EnforceGroupClaim,
}, nil
}

Expand All @@ -148,6 +152,7 @@ type googleConnector struct {
domainToAdminEmail map[string]string
fetchTransitiveGroupMembership bool
adminSrv map[string]*admin.Service
EnforceGroupClaim bool
}

func (c *googleConnector) Close() error {
Expand Down Expand Up @@ -248,7 +253,13 @@ func (c *googleConnector) createIdentity(ctx context.Context, identity connector
}

var groups []string
if s.Groups && len(c.adminSrv) > 0 {

usingGroup := s.Groups
if c.EnforceGroupClaim {
usingGroup = true
}

if usingGroup && len(c.adminSrv) > 0 {
checkedGroups := make(map[string]struct{})
groups, err = c.getGroups(claims.Email, c.fetchTransitiveGroupMembership, checkedGroups)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions server/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ func (s *Server) newIDToken(clientID string, claims storage.Claims, scopes []str
tok.AuthorizingParty = clientID
}

tok.Groups = append(tok.Groups, claims.Groups...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is a good idea since a user can be member of 1000+ groups. Google sets a limit of ~3000
https://support.google.com/a/answer/6099642

I think DEX should set a reasonable upper limit on number of groups to include in the token and document the same as a limitation.


payload, err := json.Marshal(tok)
if err != nil {
return "", expiry, fmt.Errorf("could not serialize claims: %v", err)
Expand Down
Loading