oauth2-proxy: Invalid scope when specifying allowed groups

Invalid scope when specifying allowed groups

Context

Using Keycloak and oauth2-proxy, I’m trying to restrict access to specific groups. I’m using the following configuration:

providers:
  - approvalPrompt: force
    clientID: AuthProvider
    clientSecret: xxxxxx
    allowedGroups: ["bananas"]
    id: keycloak-oidc=AuthProvider
    oidcConfig:
      emailClaim: email
      groupsClaim: groups
      insecureSkipNonce: true
      issuerURL: https://xxxxx/auth/realms/kubernetes
      userIDClaim: email
      insecureAllowUnverifiedEmail: true
    provider: keycloak-oidc

I get this error Login Failed: The upstream identity provider returned an error: invalid_scope

Logs:

[2022/03/25 19:33:32] [oauthproxy.go:714] Error while parsing OAuth2 callback: invalid_scope
10.92.142.166 - 029927d7d734cd842740e61e2d51a27a - - [2022/03/25 19:33:32] argocd-customer.apps.domain.azure.cloud.example GET - "/oauth2/callback?error=invalid_scope&error_description=Invalid+scopes%3A+openid+email+profile+groups&state=NF9RFeZk44HwCdTDH9cavXrhaU1wprJ5ZZqxhAWwE1E%3Ahttps%3A%2F%2Fargocd-customer.apps.domain.azure.cloud.example%2F" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36" 403 2801 0.000
10.244.2.145 - fe4209c66b6e6abe268710d60219cc2a - - [2022/03/25 19:33:32] argocd-customer.apps.domain.azure.cloud.example GET - "/oauth2/auth" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36" 401 13 0.000
10.92.142.166 - 17388fa65b8041834c133c1eef6ef370 - - [2022/03/25 19:33:33] argocd-customer.apps.domain.azure.cloud.example GET - "/oauth2/start?rd=https://argocd-customer.apps.domain.azure.cloud.example%2Ffavicon.ico" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36" 302 524 0.000
10.92.142.166 - 92748bce8450cf77555c1fbc4a27411a - - [2022/03/25 19:33:33] argocd-customer.apps.domain.azure.cloud.example GET - "/oauth2/callback?error=invalid_scope&error_description=Invalid+scopes%3A+openid+email+profile+groups&state=GSJPPvtLJF28mryHUPP9oBcfNGGn0xlTo1WPB1BKFHY%3Ahttps%3A%2F%2Fargocd-customer.apps.domain.azure.cloud.example%2Ffavicon.ico" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36" 403 2801 0.000
[2022/03/25 19:33:33] [oauthproxy.go:714] Error while parsing OAuth2 callback: invalid_scope

Your Environment

  • Version used: oauth2-proxy: 7.2.0 keycloak: 15.0.2

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (14 by maintainers)

Most upvoted comments

Found the problem. Somehow after enabling allowedGroups option the default scope is overridden. Fixed by adding scope: openid email profile

Ah yes I see the confusion, you can see here we add groups to the scopes if you have allowedGroups set https://github.com/oauth2-proxy/oauth2-proxy/blob/ce750e9b301ac66b3b8cbdbd0bc8ac7415bfed79/providers/providers.go#L159

I’m not sure if this is a great default behaviour to be honest. That scope may not be defined for all providers. groups is not like openid email profile which are agreed upon in the standard.

Thoughts? @JoelSpeed

Then I think we are ok, but should document this. If you haven’t specified an opinion, and we think that for the majority of people, we can choose a sensible default, and that default is not ok for you, then, specify an opinion! 😅

Something we use a lot at work when designing APIs (to configure operators and applications so similar in a way)

When omitted, this means no opinion, and the platform is left to choose a reasonable default, subject to change over time.

I think we can also embody that mantra.

I had meant option 1.

If you have an opinion about scope, we should not mess with that.

If you have no opinion about scope, we can choose your default scope based on the other options you provided

Bump, this is a bad user experience since it is not documented well in the options section for either scope or Allow groups. Especially since there is a usually an upstream that handles the authorization based on login response from the proxy. FYI if running in containers/kube. --scope=openid profile email groups Other work around is specify Allow Groups but with a widely populated group. --allowed-groups=EVERYUSER