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

Add groups claims to openid idp #454

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions cmd/ocm/create/idp/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var args struct {
openidEmail string
openidName string
openidUsername string
openidGroups string
openidExtraScopes string

// HTPasswd
Expand Down Expand Up @@ -227,6 +228,12 @@ func init() {
"",
"OpenID: List of claims to use as the preferred username when provisioning a user.\n",
)
flags.StringVar(
&args.openidGroups,
"groups-claims",
"",
"OpenID: List of claims to use as the groups names.\n",
)
flags.StringVar(
&args.openidExtraScopes,
"extra-scopes",
Expand Down
19 changes: 17 additions & 2 deletions cmd/ocm/create/idp/openid.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func buildOpenidIdp(cluster *cmv1.Cluster, idpName string) (idpBuilder cmv1.Iden
email := args.openidEmail
name := args.openidName
username := args.openidUsername
groups := args.openidGroups
extraScopes := args.openidExtraScopes

isInteractive := clientID == "" || clientSecret == "" || issuerURL == "" ||
Expand Down Expand Up @@ -109,6 +110,16 @@ func buildOpenidIdp(cluster *cmv1.Cluster, idpName string) (idpBuilder cmv1.Iden
}
}

if groups == "" {
prompt := &survey.Input{
Message: "Claim mappings to use as the groups:",
}
err = survey.AskOne(prompt, &groups)
if err != nil {
return idpBuilder, errors.New("Expected a list of claims to use as the groups")
}
}

if extraScopes == "" {
prompt := &survey.Input{
Message: "Extra scopes to request:",
Expand All @@ -120,8 +131,9 @@ func buildOpenidIdp(cluster *cmv1.Cluster, idpName string) (idpBuilder cmv1.Iden
}
}

if email == "" && name == "" && username == "" {
return idpBuilder, errors.New("At least one claim is required: [email-claims name-claims username-claims]")
if email == "" && name == "" && username == "" && groups == "" {
return idpBuilder, errors.New("At least one claim is required: [email-claims name-claims username-claims " +
"groups-claims]")
}

parsedIssuerURL, err := url.ParseRequestURI(issuerURL)
Expand Down Expand Up @@ -149,6 +161,9 @@ func buildOpenidIdp(cluster *cmv1.Cluster, idpName string) (idpBuilder cmv1.Iden
if username != "" {
openIDClaims = openIDClaims.PreferredUsername(strings.Split(username, ",")...)
}
if groups != "" {
openIDClaims = openIDClaims.Groups(strings.Split(groups, ",")...)
}

// Create OpenID IDP
openIDIDP := cmv1.NewOpenIDIdentityProvider().
Expand Down