Closed ba1dr closed 4 years ago
Well, it seems I figured this out. The line below causes this redirect:
location /oauth2/ {
...
proxy_set_header X-Auth-Request-Redirect $request_uri;
}
Removing this line from that location fixes the main issue. But after login I get redirected to /
. This refers us to #695 - is it fixed right?
/oauth2/start
can take a rd
redirect parameter to get you redirected back to the right spot. I have something similar to the above using this annotation in a Kubernetes nginx ingress:
nginx.ingress.kubernetes.io/auth-signin: https://<HOSTNAME>/oauth2/start?rd=https%3A%2F%2F$host$escaped_request_uri
In my case, I'm hosting the oauth2 proxy on a separate domain, so I have $host
in the rd
parameter (and have whitelist-domains
option set appropriately for the security precaution of a redirect to a different domain).
Otherwise you can do /oauth2/start?rd=$escaped_request_uri
Well, ok, but I do not manage /oauth2/start
URL. Redirect is made by oauth2-proxy itself.
I only put auth_request /oauth2/auth;
in nginx's config.
oauth2-proxy is in action where it receives a callback after google login. It looks like it does not handle it properly.
Try replacing this error_page 401 = /oauth2/sign_in;
with error_page 401 = /oauth2/start?rd=$escaped_request_uri
Either rd
or the header you removed controls the redirect process, see here: https://github.com/oauth2-proxy/oauth2-proxy/blob/7b21f53aad1aa2490c124b703ee4b3522d07712e/oauthproxy.go#L260
You can also try adding rd
as a parameter to the /oauth2/sign_in
URL, it looks like it is valid there too upon looking at the code.
Thanks! That seems to work.
Hello @ba1dr , @NickMeves ,
I am using below ingress on kubernetes, whenever i login with htppass credentials, i am getting redirect to login page again. could you please help
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx
namespace: oauth2
annotations:
nginx.ingress.kubernetes.io/auth-signin: http://oauth2.test.shiva.com/oauth2/start?rd=http://nginx.test.shiva.com
nginx.ingress.kubernetes.io/auth-url: http://oauth-oauth2-proxy.oauth2.svc.cluster.local/oauth2/auth
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: nginx.test.shiva.com
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: nginx
port:
number: 80
When i open the nginx.test.shiva.com url initially from browser, it is redirecting to http://oauth2.test.shiva.com/oauth2/sign_in?rd=http://nginxnew.test.shiva.com. here i am entering the htpasswd credentials and after signing in it is again redirecting to http://oauth2.test.shiva.com/oauth2/sign_in?rd=http://nginxnew.test.shiva.com page in a loop
How can i make it work. after login is succeeded it should redirect to my FQDN correctly without asking to signin again
@rshiva777 The infinite redirect issue is normally a result of misconfigured cookie domains, can you check that the cookie domain is configured to allow access to both OAuth2 Proxy and the nginx instance, you'll probably want .test.shiva.com
based on your examples
What I see: upon opening website I get redirected to
/start
endpoint and then immediately to Google "Sign In" page. After logging in with google I am redirected to/callback?state=blabla
page with positive record in the log (I see my email in the oauth2-proxy's log). But then I immediately get redirected to/start
and to Google "Sign In" page again and so on. If I enter my website's address I can open its pages and I am logged in. Just redirect does not work. Cookies seem to be set correctly.Version: commit
bbf00bc92b6c5ab8906c14021a1a4eecf44407c3
frommaster
(by Wed Jul 29 12:23:08 2020 +0100) Ubuntu 20.04Cookies from
/callback
:From
/start
there is only cookie_oauth2_proxy_csrf
:oauth2-proxy.cfg:
nginx config:
nginx-access.log:
oauth2-proxy log: