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

Too many redirects #165

Open
vpavlin opened this issue Feb 20, 2018 · 14 comments
Open

Too many redirects #165

vpavlin opened this issue Feb 20, 2018 · 14 comments

Comments

@vpavlin
Copy link
Member

vpavlin commented Feb 20, 2018

Proxy often gets into redirect loop which results in too many redirects error - after showing this error, browser redirects to the Jenkins successfully.

The issue probably lies in how we work with cookies and generally verify if user is logged in

@hferentschik
Copy link
Contributor

@vpavlin do you have any hunch on this?

@vpavlin
Copy link
Member Author

vpavlin commented Feb 22, 2018

It's gonna be connected to how we deal with cookies, but no, not yet...looking in to it now

@vpavlin
Copy link
Member Author

vpavlin commented Feb 22, 2018

Blocked by #174 - cannot be properly debuged at the moment

@hferentschik
Copy link
Contributor

I think the whole problem is also browser related. It seems in particular Chrome where this error comes up. I don't think I have seen it in another browser yet.

@kishansagathiya
Copy link
Member

I also faced this today

@yzainee-zz
Copy link

I am facing this problem since yesterday.

@kishansagathiya
Copy link
Member

I think the whole problem is also browser related. It seems in particular Chrome where this error comes up. I don't think I have seen it in another browser yet.

Saw this even in firefox

@kishansagathiya
Copy link
Member

kishansagathiya commented Apr 6, 2018

got this

2018/04/06 13:18:35 http: multiple response.WriteHeader calls

I think it is a problem with implementation. It keeps redirecting to auth even if logged in. Should be fixable. Don't think it is intermittent anymore. I see it everytime these days.

@kishansagathiya
Copy link
Member

Doesn't seems to create any problems on prod. So this can be done later

@kishansagathiya
Copy link
Member

Ok. I see this happening even on prod and it is quite frequent

@kishansagathiya kishansagathiya self-assigned this Apr 23, 2018
kishansagathiya added a commit to kishansagathiya/fabric8-jenkins-proxy that referenced this issue Apr 23, 2018
	- HandleJenkinsUIRequest code had way too many self-redirect and buggy cookie handling
	- This change to HandleJenkinsUIRequest proposed a much simpler logic and tries to get rid of JenkinsIdled cookie
kishansagathiya added a commit to kishansagathiya/fabric8-jenkins-proxy that referenced this issue Apr 24, 2018
	- Removed inappropriate time.sleep logic
	- Now it is left to the UI to keep checking if the jenkins is unidled
kishansagathiya added a commit to kishansagathiya/fabric8-jenkins-proxy that referenced this issue Apr 24, 2018
	- To fix error of unrecongnized import path
kishansagathiya added a commit to kishansagathiya/fabric8-jenkins-proxy that referenced this issue Apr 24, 2018
kishansagathiya added a commit to kishansagathiya/fabric8-jenkins-proxy that referenced this issue Apr 25, 2018
kishansagathiya added a commit to kishansagathiya/fabric8-jenkins-proxy that referenced this issue Apr 25, 2018
	- One more Attempt at Refactoring HandleJenkinsUIRequest
	- Changed the flow
	- First part makes sure that the User is logged in
	- Second part gets makes sure that the Jenkins pod is up
	- This one as well does get rid of(doesn't use) JenkinsIdled Cookie
@kishansagathiya
Copy link
Member

After #250 this issue is not seen. I will still hang to this for a while before closing this

@kishansagathiya
Copy link
Member

Saw this on my local machine

This might be the reason

{"component":"proxy","level":"info","msg":"Could not find cache, redirecting to re-login","ns":"","request-hash":2960151885,"time":"2018-05-02T16:52:39+05:30"}

@concaf
Copy link

concaf commented May 8, 2018

@sthaha @kishansagathiya - So this is all 🍪 magic!

There are 2 facets to this problem.

  1. The localhost problem!

The whole cookie story is messed up for localhost. Even though the cookies are set for localhost, they are not being sent with the requests to localhost.

So, even though cookies are set at

http.SetCookie(w, cookie)
, no cookie is found at
if len(r.Cookies()) > 0 { //Check cookies and proxy cache to find user info
and this directly redirects to auth because needsAuth remains true and
if needsAuth {
redirAuth := GetAuthURI(p.authURL, redirectURL.String())
requestLogEntry.Infof("Redirecting to auth: %s", redirAuth)
http.Redirect(w, r, redirAuth, http.StatusTemporaryRedirect)
}
yet again, we go in circles.

To fix this, we need to make 2 changes.

  • redirect requests to some other host except localhost that ends in openshift.io (this matters to auth), e.g. local.openshift.io
    This can be done by adding a line to /etc/hosts that looks like
    127.0.0.1 local.openshift.io

Once this is fixed, you will encounter the next problem. Read on 🤷‍♂️

  1. The https:// problem

The cookies will now be set for local.openshift.io, but... your browser will not set all the cookies because the cookies are marked to be only set for secure connections, but do you have a secure connection on your localhost? Well, no! So no cookie, including the session cookie JSESSIONID is set in your browser, which makes this code to not execute

if strings.HasPrefix(cookie.Name, SessionCookie) { //We found a session cookie in cache
cacheKey = cookie.Value
pci := cacheVal.(CacheItem)
r.Host = pci.Route //Configure proxy upstream
r.URL.Host = pci.Route
r.URL.Scheme = pci.Scheme
ns = pci.NS
needsAuth = false //user is probably logged in, do not redirect
noProxy = false
break
, which means cacheKey remains empty and we get
if len(cacheKey) == 0 { //If we do not have user's info cached, run through login process to get it
requestLogEntry.WithField("ns", ns).Info("Could not find cache, redirecting to re-login")
} else {
in the logs followed by redirection to auth
if needsAuth {
redirAuth := GetAuthURI(p.authURL, redirectURL.String())
requestLogEntry.Infof("Redirecting to auth: %s", redirAuth)
http.Redirect(w, r, redirAuth, http.StatusTemporaryRedirect)
}

And hence we go in circles!

This second problem was staring us in the face with #174, but 🤷‍♂️!


The fix for local development definitely lies in generating local certificates, or something of the like. But will this fix the too many redirects in prod preview, and prod, only time will tell!

@vpavlin
Copy link
Member Author

vpavlin commented May 17, 2018

What you describe makes perfect sense for local development, but does not at all explain the stage/prod issue as none of 2 causes you mentioned are present when running in prod/prev clusters. Also, during debugging this, I saw that cookies seemed to be set properly. I still think this is connected to how proxy handles cookies, but I am pretty sure neither https:// nor localhost.openshift.io on localhos will solve this issue:)

@kishansagathiya kishansagathiya removed their assignment Jun 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

5 participants