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

github broken in 7.3.0 #1724

Closed
masterkain opened this issue Jul 13, 2022 · 28 comments
Closed

github broken in 7.3.0 #1724

masterkain opened this issue Jul 13, 2022 · 28 comments
Labels

Comments

@masterkain
Copy link

works in 7.2.1

[oauthproxy.go:775] Error creating session during OAuth2 callback: unexpected status "404": {"message":"Not Found","documentation_url":"https://docs.github.com/rest/reference/users#list-email-addresses-for-the-authenticated-user"}

@sergeyshaykhullin
Copy link

Also got same issue

@rpardini
Copy link

indeed, 7.3.0 does not work but 7.2.1 does.
using github_org config, not team or user.
seems to be related to scopes: after downgrade, GH authorization page says "would like additional permissions to... Email addresses (read-only)" -- so possibly user:email scope is not being included when used with orgs in 7.3.0.

@multani
Copy link

multani commented Jul 29, 2022

I quickly checked this morning, and it seems to be coming from around 1f992b3 or 82710a7 (1f992b3 doesn't build here). #1555 and/or #1560 when the provider's initialization code was refactored.

The scope that was asked before was only user:email:

https://github.com/login/oauth/authorize?approval_prompt=force&client_id=XXX&redirect_uri=http://127.0.0.1:8000/oauth2/callback&response_type=code&scope=user:email&state=YYY

but now, OIDC-like scopes are requested instead (openid email profile):

https://github.com/login/oauth/authorize?approval_prompt=force&client_id=XXX&redirect_uri=http://127.0.0.1:8000/oauth2/callback&response_type=code&scope=openid email profile&state=YYY

@multani
Copy link

multani commented Jul 29, 2022

For now, it seems it can be fixed by explicitly configuring the user:email scope with either:

  • the configuration flag --scope="user:email"
  • the environment variable OAUTH2_PROXY_SCOPE="user:email"
  • or the configuration file's setting scope = "user:email"

@JoelSpeed
Copy link
Member

We broke the defaulting of provider configuration in 7.3.0 so a lot of options are needed to be set manually for now. Looking to fix this for the next release, though it's good practice to set them explicitly anyway so bugs like this don't break your config

@JoelSpeed JoelSpeed added the bug label Aug 8, 2022
tbouska added a commit to buvis/clusters that referenced this issue Aug 11, 2022
@multani
Copy link

multani commented Aug 15, 2022

though it's good practice to set them explicitly anyway so bugs like this don't break your config

It would be great to document the right settings somewhere then, I haven't try but I'm not sure the proxy works with a different set of scopes (or at least, if this one for GitHub user:email is missing) and it can be a bit hard to guess which values are supposed to be there (and I suppose they are different for every authentication providers...)

@BrynM
Copy link

BrynM commented Sep 15, 2022

Setting the scope to user:email as a workaround in the config did not work for a GH Enterprise (v3.5.5) install. I had to revert to 7.2.1 and remove that setting completely.

@kodeine
Copy link

kodeine commented Nov 14, 2022

scope to user:email did not work for me.

@jimeh
Copy link

jimeh commented Nov 14, 2022

I've restricted access to a specific team within a specific org. Setting scope to user:email read:user read:org worked for me.

@tuunit
Copy link
Member

tuunit commented Dec 14, 2022

I've checked the current implementation and indeed the issue is described quite well in the #1903 bug ticket. Unfortunately, when not setting the scope to "user:email read:org" inside your config file, the default scope will be set to "openid email profile" which are not recognized by Github. Therefore the access does not work as your tokens will be created with insufficient permissions.

As of now, it is necessary to set the scope manually in your config file:
scope = "user:email read:org"

@tuunit
Copy link
Member

tuunit commented Dec 14, 2022

PR with fix: #1927

@ghost
Copy link

ghost commented Feb 2, 2023

Hello,

Is this resolved in 7.4.0?

@tuunit
Copy link
Member

tuunit commented Feb 2, 2023

Hello,

Is this resolved in 7.4.0?

No the fix will be part of the next release. Until then you will have to hardcode the default scope for GitHub.

Changelog:
https://github.com/oauth2-proxy/oauth2-proxy/blob/master/CHANGELOG.md

axeal added a commit to axeal/manifests that referenced this issue Feb 9, 2023
Sanqui added a commit to Sanqui/oauth2-proxy that referenced this issue Feb 9, 2023
matiasgarciaisaia added a commit to instedd/rancher-catalog that referenced this issue Feb 10, 2023
Both in Adminer & Logging templates.

See oauth2-proxy/oauth2-proxy#1724
@chunjiw
Copy link

chunjiw commented Mar 2, 2023

Neither "user:email read:org" nor "user:email" works for me.

@tuunit
Copy link
Member

tuunit commented Mar 2, 2023

@chunjiw could you provide some more detail how you configure your environment and maybe share the code snippets of your configuration files?

@chunjiw
Copy link

chunjiw commented Mar 2, 2023

@tuunit Sure!
oauth2-proxy is installed as a deployment in a kubernetes cluster, running in a container:

        - args:
            - --provider=github
            - --email-domain=*
            - --cookie-domain=.int.company.com
            - --whitelist-domain=.int.company.com
            - --upstream=file:///dev/null
            - --http-address=0.0.0.0:4180
          image: quay.io/oauth2-proxy/oauth2-proxy:v7.2.1

The ingress to oauth2-proxy spec:

spec:
  rules:
    - host: "auth.int.company.com"

The ingress to my application:

metadata:
  name: app-name
  annotations:
    nginx.ingress.kubernetes.io/auth-url: "https://auth.int.company.com/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: "https://auth.int.company.com/oauth2/start?rd=https://app.int.company.com"

I largely followed a Digital Ocean tutorial.

This is working, until I change to v7.3.0 or v7.4.0, even with user:email read:org

@tuunit
Copy link
Member

tuunit commented Mar 2, 2023

@chunjiw the issue with v7.3.0 and v7.4.0 is that the scope is always overwritten with the default oidc scope if it has not been set via a config file. Therefore, if you want to use v7.3/4.0 in Kubernetes you will have to create a ConfigMap including a oauth2-proxy config file and mount it in your deployment and replace the arguments in your deployment with the config file.

@chunjiw
Copy link

chunjiw commented Mar 2, 2023

I see, thank you for your explanation! I will try it out later.

@chunjiw
Copy link

chunjiw commented Mar 2, 2023

I confirm that adding user:email to config file instead of using args works without issue. Thank you!

@someburner
Copy link

Prefacing this comment: This is a great project and I appreciate all the work going into it! It's been so useful for me.

... but something like this should really really be noted somewhere more visible. I'm coming from a very old oauth2_proxy version and spent hours trying to figure out what was wrong with my config, hitting github rate limits due to this, etc, only to finally find this issue...

Just sayin' if there is a (rather major) problem with something for well over a year, maybe add a little blurb in the docs somewhere?

@batazor
Copy link

batazor commented May 24, 2023

I understand this problem was solved in #1927
Maybe a new release of a new version should be released?

@github-actions
Copy link
Contributor

This issue has been inactive for 60 days. If the issue is still relevant please comment to re-activate the issue. If no action is taken within 7 days, the issue will be marked closed.

@github-actions github-actions bot added the Stale label Jul 25, 2023
@tedder
Copy link

tedder commented Jul 25, 2023

I think this is still a problem in the released version.

@tuunit
Copy link
Member

tuunit commented Jul 25, 2023

Hello,
Is this resolved in 7.4.0?

No the fix will be part of the next release. Until then you will have to hardcode the default scope for GitHub.

Changelog: https://github.com/oauth2-proxy/oauth2-proxy/blob/master/CHANGELOG.md

Hi @tedder,

as describe here, the fix is unfortunately not yet released and 7.4.0 is also broken.

The fix is on master but in no release as of now:

PR with fix: #1927

@github-actions github-actions bot removed the Stale label Jul 26, 2023
@bit-herder
Copy link

Can we please have a release with the fix in it?

@BnJam
Copy link

BnJam commented Sep 22, 2023

I have created OAuth2 Proxy as a deployment

containers:
 - image: quay.io/oauth2-proxy/oauth2-proxy:v7.5.0

Like everyone else, was struggling to get get it working and getting the same 404 Error, but for repositories, until I gave it the correct scope.

env:
- name: OAUTH2_PROXY_SCOPE
  value: "read:user user:email repo"

Since we didn't want to add external users to our Org and only as collaborators to a repository - this worked for me on v7.5.0

GH's Scope doc page was helpful - although I do with the repo scope was more restrictive.
https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps

As for my args, in case it's helpful:

args:
        - --http-address=0.0.0.0:4180
        - --upstream=file:///dev/null
        - --redirect-url=https://$host/oauth2/callback
        - --provider=github
        - --email-domain=*
        - --github-repo=OrgName/RepoName
        - --code-challenge-method=S256
        - --cookie-secure=true
        - --cookie-refresh=1h
        - --cookie-expire=24h
        - --cookie-name=proxy-cookie-name
        - --auth-logging=true

where $host, OrgName/RepoName, and proxy-cookie-name are filled in with my specific values ($host is my proxy address)

Hopefully this helps 🤞

@tuunit
Copy link
Member

tuunit commented Sep 22, 2023

the issue was fixed with version 7.5.1

@tuunit tuunit closed this as completed Sep 22, 2023
@tuunit
Copy link
Member

tuunit commented Sep 22, 2023

I have created OAuth2 Proxy as a deployment

containers:
 - image: quay.io/oauth2-proxy/oauth2-proxy:v7.5.0

Like everyone else, was struggling to get get it working and getting the same 404 Error, but for repositories, until I gave it the correct scope.

env:
- name: OAUTH2_PROXY_SCOPE
  value: "read:user user:email repo"

Since we didn't want to add external users to our Org and only as collaborators to a repository - this worked for me on v7.5.0

GH's Scope doc page was helpful - although I do with the repo scope was more restrictive. https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps

As for my args, in case it's helpful:

args:
        - --http-address=0.0.0.0:4180
        - --upstream=file:///dev/null
        - --redirect-url=https://$host/oauth2/callback
        - --provider=github
        - --email-domain=*
        - --github-repo=OrgName/RepoName
        - --code-challenge-method=S256
        - --cookie-secure=true
        - --cookie-refresh=1h
        - --cookie-expire=24h
        - --cookie-name=proxy-cookie-name
        - --auth-logging=true

where $host, OrgName/RepoName, and proxy-cookie-name are filled in with my specific values ($host is my proxy address)

Hopefully this helps 🤞

I'll have to check if we need to add additional logic to add the correct scope for repositories when using the repository restriction flag. If so that is a different issue.

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

No branches or pull requests