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

Fix default scope settings for none oidc providers like GitHub #1927

Conversation

tuunit
Copy link
Member

@tuunit tuunit commented Dec 14, 2022

Description

As described in detail in bug #1903 and related to #1724.
The current implementation overrides the default scope for all providers with the default oidc scopes when no scope is set in the configuration file. Which is obviously not the expected behaviour.

As the config file values are loaded before the default values of the providers:

func NewProvider(providerConfig options.Provider) (Provider, error) {
providerData, err := newProviderDataFromConfig(providerConfig)
if err != nil {
return nil, fmt.Errorf("could not create provider data: %v", err)
}
switch providerConfig.Type {
case options.ADFSProvider:
return NewADFSProvider(providerData, providerConfig.ADFSConfig), nil
case options.AzureProvider:
return NewAzureProvider(providerData, providerConfig.AzureConfig), nil
case options.BitbucketProvider:
return NewBitbucketProvider(providerData, providerConfig.BitbucketConfig), nil
case options.DigitalOceanProvider:
return NewDigitalOceanProvider(providerData), nil
case options.FacebookProvider:
return NewFacebookProvider(providerData), nil
case options.GitHubProvider:
return NewGitHubProvider(providerData, providerConfig.GitHubConfig), nil
case options.GitLabProvider:
return NewGitLabProvider(providerData, providerConfig.GitLabConfig)
case options.GoogleProvider:
return NewGoogleProvider(providerData, providerConfig.GoogleConfig)
case options.KeycloakProvider:
return NewKeycloakProvider(providerData, providerConfig.KeycloakConfig), nil
case options.KeycloakOIDCProvider:
return NewKeycloakOIDCProvider(providerData, providerConfig.KeycloakConfig), nil
case options.LinkedInProvider:
return NewLinkedInProvider(providerData), nil
case options.LoginGovProvider:
return NewLoginGovProvider(providerData, providerConfig.LoginGovConfig)
case options.NextCloudProvider:
return NewNextcloudProvider(providerData), nil
case options.OIDCProvider:
return NewOIDCProvider(providerData, providerConfig.OIDCConfig), nil
default:
return nil, fmt.Errorf("unknown provider type %q", providerConfig.Type)
}
}

if p.Scope == "" {
p.Scope = "openid email profile"
if len(providerConfig.AllowedGroups) > 0 {
p.Scope += " groups"
}
}
if providerConfig.OIDCConfig.UserIDClaim == "" {
providerConfig.OIDCConfig.UserIDClaim = "email"
}
p.setAllowedGroups(providerConfig.AllowedGroups)
return p, nil
}

The scope is overwritten with "openid email profile" which leads to issues later on in the setProviderDefaults method. As the p.Scope will never be empty, therefore all provider default scopes are ignored.

if p.Scope == "" {
p.Scope = defaults.scope
}

I added a check for the providerName as an additional condition in the default setter while loading the data from config file.

How Has This Been Tested?

I tested it locally with GitHub and dex, to ensure both implementations still work and I extended the unit test cases.

Checklist:

  • My change requires a change to the documentation or CHANGELOG.
  • I have updated the documentation/CHANGELOG accordingly.
  • I have created a feature (non-master) branch for my PR.

@tuunit tuunit requested a review from a team as a code owner December 14, 2022 11:24
@tuunit tuunit force-pushed the bugfix/default-scope-for-none-oidc-providers branch from d7aaa29 to 103bd6e Compare December 14, 2022 11:26
@tuunit
Copy link
Member Author

tuunit commented Dec 14, 2022

@JoelSpeed as this seems to be blocking quite a few people and it has been a bug for nearly a year now. I would like to ask you directly to have a look at this PR, if anything is missing to get it merged.

@tuunit tuunit changed the title Fix default scope settings for none oidc providers Fix default scope settings for none oidc providers like GitHub Dec 19, 2022
@tuunit
Copy link
Member Author

tuunit commented Dec 19, 2022

Resolves #1903, resolves #1724

JoelSpeed
JoelSpeed previously approved these changes Dec 19, 2022
Copy link
Member

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, long term I intend to get this section rewritten and the provider settings will come before this defaulting code, but this certainly resolves the issue for now, so thanks!

@JoelSpeed
Copy link
Member

Looks like the test updates aren't quite right as one of the scope tests failed, can you please look into that?

@tuunit
Copy link
Member Author

tuunit commented Dec 19, 2022

Looks like the test updates aren't quite right as one of the scope tests failed, can you please look into that?

@JoelSpeed my mistake! I had another look at it and it should now work as expected.

@tuunit
Copy link
Member Author

tuunit commented Dec 22, 2022

@JoelSpeed can you retrigger the build and tests? 😄

Copy link
Member

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

Lets see if the tests pass! LGTM, thanks

@JoelSpeed JoelSpeed merged commit 8b77c97 into oauth2-proxy:master Dec 23, 2022
@bit-herder
Copy link

can we get a release of this? Theres no release since october of 2022. Is this project still maintained?

@tuunit
Copy link
Member Author

tuunit commented Aug 4, 2023

@bit-herder unfortunately, @JoelSpeed has been looking for successors for a while now. There is an issue open for this very purpose. He moved to another job and doesn't have the time anymore to actively maintain this project. I'll be trying to get in contact with him as I've been interested in helping out this amazing project for a while now.

@tuunit
Copy link
Member Author

tuunit commented Aug 24, 2023

@bit-herder we are currently working on getting a new release finalized.

@sstidl
Copy link

sstidl commented Sep 6, 2023

#2222 could this be related? how do i migrate my config?

@kvanzuijlen
Copy link
Member

#2222 could this be related? how do i migrate my config?

That seems to be the case, see https://github.com/oauth2-proxy/oauth2-proxy/pull/1927/files#r1086869386

@tuunit can you link the PRs please? Are these still open or have these been used?
@JoelSpeed I think we'll need to add this as a known issue for this release and see if we can get it resolved asap.

@tuunit
Copy link
Member Author

tuunit commented Sep 7, 2023

Hi @kvanzuijlen I'll check the issue and a possible fix tomorrow.

@kvanzuijlen
Copy link
Member

@tuunit just saw #2197 that should fix this, @sstidl fyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants