-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Composite claims in OIDC connector #3056
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
91cd939
build(deps): bump golang.org/x/crypto from 0.10.0 to 0.11.0 (#3035)
dependabot[bot] 7b29cfa
build(deps): bump helm/kind-action from 1.7.0 to 1.8.0 (#3041)
dependabot[bot] 6c00fe0
Update oauth2.go
Cedric-Magnan a72413d
Update server.go
Cedric-Magnan 139845c
fix: linting with gofmt
Cedric-Magnan 6d143f1
Composite claims in OIDC connector (#3)
Oded-B 316296b
Document each test case
Oded-B 088c380
Merge branch 'dexidp:master' into master
Oded-B a528484
Rename configuration option to include a reference to groups
Oded-B b1f4bd0
Address issues raised in review:
Oded-B 7f0056c
Fix lint issue
Oded-B 6875b64
Address issues raised in review:
Oded-B 033717a
Apply suggestions from code review
Oded-B 1154259
Address issues raised in review:
Oded-B a6a7245
fix some small formatting issue
Oded-B File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,27 @@ type Config struct { | |
// Configurable key which contains the groups claims | ||
GroupsKey string `json:"groups"` // defaults to "groups" | ||
} `json:"claimMapping"` | ||
|
||
// ClaimMutations holds all claim mutations options | ||
ClaimMutations struct { | ||
NewGroupFromClaims []NewGroupFromClaims `json:"newGroupFromClaims"` | ||
} `json:"claimModifications"` | ||
} | ||
|
||
// NewGroupFromClaims creates a new group from a list of claims and appends it to the list of existing groups. | ||
type NewGroupFromClaims struct { | ||
// List of claim to join together | ||
Claims []string `json:"claims"` | ||
|
||
// String to separate the claims | ||
Delimiter string `json:"delimiter"` | ||
|
||
// Should Dex remove the Delimiter string from claim values | ||
// This is done to keep resulting claim structure in full control of the Dex operator | ||
ClearDelimiter bool `json:"clearDelimiter"` | ||
|
||
// String to place before the first claim | ||
Prefix string `json:"prefix"` | ||
} | ||
|
||
// Domains that don't support basic auth. golang.org/x/oauth2 has an internal | ||
|
@@ -189,6 +210,7 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e | |
preferredUsernameKey: c.ClaimMapping.PreferredUsernameKey, | ||
emailKey: c.ClaimMapping.EmailKey, | ||
groupsKey: c.ClaimMapping.GroupsKey, | ||
newGroupFromClaims: c.ClaimMutations.NewGroupFromClaims, | ||
}, nil | ||
} | ||
|
||
|
@@ -216,6 +238,7 @@ type oidcConnector struct { | |
preferredUsernameKey string | ||
emailKey string | ||
groupsKey string | ||
newGroupFromClaims []NewGroupFromClaims | ||
} | ||
|
||
func (c *oidcConnector) Close() error { | ||
|
@@ -427,6 +450,30 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I | |
} | ||
} | ||
|
||
for _, config := range c.newGroupFromClaims { | ||
newGroupSegments := []string{ | ||
config.Prefix, | ||
} | ||
for _, claimName := range config.Claims { | ||
claimValue, ok := claims[claimName].(string) | ||
if !ok { // Non string claim value are ignored, concatenating them doesn't really make any sense | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is obscure for users.
|
||
continue | ||
} | ||
Oded-B marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if config.ClearDelimiter { | ||
// Removing the delimiter string from the concatenated claim to ensure resulting claim structure | ||
// is in full control of Dex operator | ||
claimValue = strings.ReplaceAll(claimValue, config.Delimiter, "") | ||
} | ||
Oded-B marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
newGroupSegments = append(newGroupSegments, claimValue) | ||
} | ||
Oded-B marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if len(newGroupSegments) > 1 { | ||
groups = append(groups, strings.Join(newGroupSegments, config.Delimiter)) | ||
} | ||
} | ||
|
||
cd := connectorData{ | ||
RefreshToken: []byte(token.RefreshToken), | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefix scales badly because people may want to add prefixes, suffixes, or both, or only prefix specific groups.
This is the same problem we are struggling in Kubernetes (that will be fixed in upcoming releases with CEL).