Skip to content

OIDC Enhancements #5637

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

Merged
merged 7 commits into from
Apr 30, 2025
Merged

OIDC Enhancements #5637

merged 7 commits into from
Apr 30, 2025

Conversation

kumo-rn5s
Copy link
Contributor

@kumo-rn5s kumo-rn5s commented Mar 8, 2025

What this PR does:

  • Adds support for custom claim keys for roles, usernames, and avatar URLs in OIDC configuration.
  • Enables the use of custom authorization, token, and user info endpoints.
  • Allows the OIDC client to retrieve additional user information from the UserInfo endpoint.
  • Adds an example for the Okta provider.

Why we need it:

  • Provides greater flexibility in configuring OIDC providers, especially when the default claim keys or endpoints do not match the user's setup.
  • Ensures the OIDC client can retrieve more user information from the UserInfo endpoint.
  • Enhances compatibility with various OIDC providers.

Which issue(s) this PR fixes:
Fixes #5330

Does this PR introduce a user-facing change?:
Yes

  • How are users affected by this change:

    • Users can now specify custom claim keys for roles, usernames, and avatar URLs in their OIDC configuration. They can also set custom endpoints for authorization, token, and user info.
    • The UserInfo endpoint will be automatically used to get additional claim fields.
    • Users can now specify custom userinfo/authorize/token endpoints on the prerequisites of issuer discovery.
  • Something to note:

    • Most OIDC providers support Discovery, so typically users only need to provide the issuer URL — the client will automatically fetch the necessary endpoints (authorization_endpoint, token_endpoint, userinfo_endpoint). This PR adds the ability to override specific values even after discovery, which is useful when:
      • You're using a custom OIDC provider that doesn't support Discovery.
      • You want to override one or more endpoints (e.g., userinfo_endpoint) from what Discovery provides.
    • While this feature improves flexibility, it's expected to be a niche use case. Testing it thoroughly may also be difficult without a non-standard provider.
  • Is this a breaking change:
    No

  • How to migrate (if breaking change):
    Not applicable

@kumo-rn5s kumo-rn5s force-pushed the auth/oidc-expansion branch from fc3352a to 00324ea Compare March 8, 2025 15:57
@kumo-rn5s kumo-rn5s changed the title OIDC expansion OIDC Enhancements Mar 8, 2025
@t-kikuc t-kikuc self-assigned this Mar 9, 2025
@t-kikuc
Copy link
Member

t-kikuc commented Mar 10, 2025

Thank you! Let me check for some weeks

Copy link
Contributor

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 10, 2025
Copy link
Contributor

This PR was closed because it has been stalled for 7 days with no activity. Feel free to reopen if still applicable.

@github-actions github-actions bot closed this Apr 17, 2025
@khanhtc1202 khanhtc1202 reopened this Apr 17, 2025
@github-actions github-actions bot removed the Stale label Apr 18, 2025
@kumo-rn5s kumo-rn5s force-pushed the auth/oidc-expansion branch 2 times, most recently from 6d65f31 to e510d4e Compare April 22, 2025 07:16
t-kikuc
t-kikuc previously approved these changes Apr 22, 2025
Copy link
Member

@t-kikuc t-kikuc left a comment

Choose a reason for hiding this comment

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

LGreatTM

Tested

It worked well. With the following control-plane-config.yaml and AWS Cognito configs, I could successfully use given_name instead of username.

spec:
  sharedSSOConfigs:
    - name: cognito
      provider: OIDC
      oidc:
        clientId: xxx
        clientSecret: xxx
        issuer: https://cognito-idp.xxx
        redirect_uri: xxx
        scopes:
          - openid
          - profile
        usernameClaimKey: given_name #HERE
        avatarUrlClaimKey: picture #HERE

image

Result: (the name is from given_name!)
image

For reviewers

Let me explain this issue & PR in short:

  • Needs: Users want to assign custom claims for username/role/avatarImage on PipeCD UI
  • Before this PR: It was unable
  • The reasons:
    [1] There was no mapping between custom claims and username/role/avatarImage
    [2] IDToken does not have custom claims in some IdPs such as Okta
    - To get them, pipecd needs to access UserInfoEndpoint
  • The solution:
    [1] Add mapping for custom claims by usernameClaimKey etc. and defaultUsernameClaimKeys etc.
    [2] Fetch custom claims from UserInfoEndpoint (here)

// then pass user-provided URLs to override the existing URLs in the providerConfig struct.
// https://pkg.go.dev/github.com/coreos/go-oidc/[email protected]/oidc#NewProvider
// https://pkg.go.dev/github.com/coreos/go-oidc/[email protected]/oidc#ProviderConfig
func createCustomOIDCProvider(ctx context.Context, sso *model.ProjectSSOConfig_Oidc) (*oidc.Provider, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I got it.

This func is based on https://github.com/coreos/go-oidc/blob/0fe98873951208147e6d412602432038c91cda54/oidc/oidc.go#L208 and basically the changed points are only overriding AuthorizationEndpoint etc. in providerConfig := oidc.ProviderConfig{.

Copy link
Member

Choose a reason for hiding this comment

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

Because this function is based on the code written by other authors, we should include copyright notice in some places.
The go-oidc's notice is here, so please include the copyright notice around this function and the modification summary.
https://github.com/coreos/go-oidc/blob/a7c457eacb849c163a496b29274242474a8f44ab/NOTICE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Warashi Hi, I’ve added the NOTICE. Could you please review it and let me know if it looks okay?

@t-kikuc
Copy link
Member

t-kikuc commented Apr 22, 2025

Needs: Users want to assign custom claims for username/role/avatarImage on PipeCD UI

For example,

  • choose employeeID/userName/userID etc. for the name on UI.
  • decide the role by some custom claim

@t-kikuc t-kikuc removed their assignment Apr 22, 2025
@t-kikuc t-kikuc enabled auto-merge (squash) April 24, 2025 03:50
@t-kikuc
Copy link
Member

t-kikuc commented Apr 30, 2025

@kumo-rn5s
We're sorry, but would you please solve the conflict?
Maybe this is correct:

verifier := c.Verifier(&oidc.Config{ClientID: c.sharedSSOConfig.ClientId})

auto-merge was automatically disabled April 30, 2025 03:47

Head branch was pushed to by a user without write access

@kumo-rn5s kumo-rn5s force-pushed the auth/oidc-expansion branch from 9ff9fb7 to f324d67 Compare April 30, 2025 03:47
@kumo-rn5s kumo-rn5s requested a review from t-kikuc April 30, 2025 03:51
t-kikuc
t-kikuc previously approved these changes Apr 30, 2025
Copy link
Member

@Warashi Warashi left a comment

Choose a reason for hiding this comment

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

The codes are good. I commented on the copyright notice of the codes taken from the go-oidc package.

// then pass user-provided URLs to override the existing URLs in the providerConfig struct.
// https://pkg.go.dev/github.com/coreos/go-oidc/[email protected]/oidc#NewProvider
// https://pkg.go.dev/github.com/coreos/go-oidc/[email protected]/oidc#ProviderConfig
func createCustomOIDCProvider(ctx context.Context, sso *model.ProjectSSOConfig_Oidc) (*oidc.Provider, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Because this function is based on the code written by other authors, we should include copyright notice in some places.
The go-oidc's notice is here, so please include the copyright notice around this function and the modification summary.
https://github.com/coreos/go-oidc/blob/a7c457eacb849c163a496b29274242474a8f44ab/NOTICE

Copy link
Member

@Warashi Warashi left a comment

Choose a reason for hiding this comment

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

Looks Great! Thank you!

@kumo-rn5s kumo-rn5s requested a review from t-kikuc April 30, 2025 05:25
Copy link
Member

@t-kikuc t-kikuc left a comment

Choose a reason for hiding this comment

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

Thank you so much for amazing feature!!!! 👍 🙏

@t-kikuc t-kikuc merged commit e92520b into pipe-cd:master Apr 30, 2025
16 checks passed
@github-actions github-actions bot mentioned this pull request May 15, 2025
@github-actions github-actions bot mentioned this pull request May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support userinfo endpoint for Generic OIDC SSO
4 participants