traefik-forward-auth: Endless login loop
Hi,
First of all, it is the first time I am using Oauth so I might have done something wrong in my setup. I am redirected to google for auth but every time I click on my email address (once connected to google), the same google screen is showing up and I am not redirected to my website.
At the moment, I set DOMAIN=gmail.com in my docker-compose.yml as I don’t have an address @DOMAIN.COM on google.
Any idea?
Forward-auth log shows
forward-oauth | 2018-10-31T13:42:40.440721148Z 2018/10/31 13:42:40 Set CSRF cookie and redirecting to google login
Traefik log shows (on hitting the URL):
traefik | 2018-10-31T13:45:40.019947588Z time="2018-10-31T13:45:40Z" level=debug msg="Remote error http://forward-oauth:4181. StatusCode: 307"
and it shows this on hitting my email address on google auth webpage:
traefik | 2018-10-31T13:45:54.929432773Z time="2018-10-31T13:45:54Z" level=debug msg="vulcand/oxy/roundrobin/rr: begin ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/_oauth\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"state=993f242d01:https://hydra.DOMAIN.COM/\\u0026code=4/hD4PkUroE8\\u0026scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"en-GB,en-US;q=0.9,en;q=0.8\"],\"Cookie\":[\"_forward_auth_csrf=993f242d01\"],\"Referer\":[\"https://accounts.google.com/signin/oauth/oauthchooseaccount?client_id=b5q0.apps.googleusercontent.com\\u0026as=4uOMLWOVQ\\u0026destination=https%3A%2F%2FauthDOMAIN.COOM\u0026approval_state=!ChQxMHdtX2kNd\\u0026oauthgdpr=1\\u0026xsrfsig=AHgIfE_SkNq7B213FkQ\\u0026flowName=GeneralOAuthFlow\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"auth.DOMAIN.COM\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"188.60.195.90:59429\",\"RequestURI\":\"/_oauth?state=993f2e4c48042d01:https://hydra.DOMAIN.COM/\\u0026code=4/hgAMuUroE8\\u0026scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email\",\"TLS\":null}"
traefik | 2018-10-31T13:45:54.929841936Z time="2018-10-31T13:45:54Z" level=debug msg="vulcand/oxy/roundrobin/rr: Forwarding this request to URL" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/_oauth\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"state=993f2e4c042d01:https://hydra.DOMAIN.COM/\\u0026code=4/PkUroE8\\u0026scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"en-GB,en-US;q=0.9,en;q=0.8\"],\"Cookie\":[\"_forward_auth_csrf=993f2e4cff14042d01\"],\"Referer\":[\"https://accounts.google.com/signin/oauth/oauthchooseaccount?client_id=pq0.apps.googleusercontent.com\\u0026as=4OVQ\\u0026destination=https%3A%2F%2Fauth.DOMAIN.COM\\u0026approval_state=!ChQxMFdtX2kNd\\u0026oauthgdpr=1\\u0026xsrfsig=AHgIQ\\u0026flowName=GeneralOAuthFlow\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"auth.DOMAIN.COM\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"188.60.195.90:59429\",\"RequestURI\":\"/_oauth?state=993f242d01:https://hydra.DOMAIN.COM/\\u0026code=4/hD4PkUroE8\\u0026scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email\",\"TLS\":null}" ForwardURL="http://172.18.0.11:4181"
traefik | 2018-10-31T13:45:54.930209893Z time="2018-10-31T13:45:54Z" level=debug msg="vulcand/oxy/forward: begin ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"http\",\"Opaque\":\"\",\"User\":null,\"Host\":\"172.18.0.11:4181\",\"Path\":\"\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"en-GB,en-US;q=0.9,en;q=0.8\"],\"Cookie\":[\"_forward_auth_csrf=993f2d01\"],\"Referer\":[\"https://accounts.google.com/signin/oauth/oauthchooseaccount?client_id=1hbb5q0.apps.googleusercontent.com\\u0026as=4uOMLZVQ\\u0026destination=https%3A%2F%2Fauth.DOMAIN.COM\\u0026approval_state=!ChQxWQlBhbGJCWQ%E2%88%99APNbktkAAAAAW9sDhHgTS3FGyDWs8BWxBCm4HdtX2kNd\\u0026oauthgdpr=1\\u0026xsrfsig=AHgIfB213FkQ\\u0026flowName=GeneralOAuthFlow\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"auth.DOMAIN.COM\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"188.60.195.90:59429\",\"RequestURI\":\"/_oauth?state=993f248042d01:https://hydra.DOMAIN.COM/\\u0026code=4/hgAMuldPkUroE8\\u0026scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email\",\"TLS\":null}"
traefik | 2018-10-31T13:45:54.930525308Z time="2018-10-31T13:45:54Z" level=debug msg="vulcand/oxy/forward/http: begin ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"http\",\"Opaque\":\"\",\"User\":null,\"Host\":\"172.18.0.11:4181\",\"Path\":\"\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"en-GB,en-US;q=0.9,en;q=0.8\"],\"Cookie\":[\"_forward_auth_csrf=993f42d01\"],\"Referer\":[\"https://accounts.google.com/signin/oauth/oauthchooseaccount?client_id=ohvq0.apps.googleusercontent.com\\u0026as=4uOMOVQ\\u0026destination=https%3A%2F%2Fauth.DOMAIN.COM\\u0026approval_state=!ChcTS3FGyDWs8BWxBCm4HdtX2kNd\\u0026oauthgdpr=1\\u0026xsrfsig=AHFkQ\\u0026flowName=GeneralOAuthFlow\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"auth.DOMAIN.COM\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"188.60.195.90:59429\",\"RequestURI\":\"/_oauth?state=993f2e4042d01:https://hydraDOMAIN.COM/\\u0026code=4/hgoE8\\u0026scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email\",\"TLS\":null}"
traefik | 2018-10-31T13:45:54.930641362Z time="2018-10-31T13:45:54Z" level=debug msg="Upstream ResponseWriter of type *pipelining.writerWithoutCloseNotify does not implement http.CloseNotifier. Returning dummy channel."
traefik | 2018-10-31T13:45:54.932439662Z time="2018-10-31T13:45:54Z" level=debug msg="vulcand/oxy/forward/http: Round trip: http://172.18.0.11:4181, code: 307, Length: 434, duration: 1.606526ms tls:version: 303, tls:resume:true, tls:csuite:c02f, tls:server:hydra.DOMAIN.COM"
traefik | 2018-10-31T13:45:54.932707222Z time="2018-10-31T13:45:54Z" level=debug msg="vulcand/oxy/forward/http: completed ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"http\",\"Opaque\":\"\",\"User\":null,\"Host\":\"172.18.0.11:4181\",\"Path\":\"\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"en-GB,en-US;q=0.9,en;q=0.8\"],\"Cookie\":[\"_forward_auth_csrf=993f2e448042d01\"],\"Referer\":[\"https://accounts.google.com/signin/oauth/oauthchooseaccount?client_id=qpdjq1hbb5q0.apps.googleusercontent.com\\u0026as=4uQ\\u0026destination=https%3A%2F%2Fauth.DOMAIN.COM\\u0026approval_state=!ChQxkNd\\u0026oauthgdpr=1\\u0026xsrfsig=AHgIfE_SkNz41NQjL1AlzKR5Mq7B213FkQ\\u0026flowName=GeneralOAuthFlow\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"auth.DOMAIN.COm\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"188.60.195.90:59429\",\"RequestURI\":\"/_oauth?state=993f2ed548042d01:https://hydra.DOMAIN.COM/\\u0026code=4/hgAMuldpxs8Wy0NOWtxskTUroE8\\u0026scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email\",\"TLS\":null}"
traefik | 2018-10-31T13:45:54.932886522Z time="2018-10-31T13:45:54Z" level=debug msg="vulcand/oxy/forward: completed ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"http\",\"Opaque\":\"\",\"User\":null,\"Host\":\"172.18.0.11:4181\",\"Path\":\"\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"en-GB,en-US;q=0.9,en;q=0.8\"],\"Cookie\":[\"_forward_auth_csrf=993f2042d01\"],\"Referer\":[\"https://accounts.google.com/signin/oauth/oauthchooseaccount?client_id=b5q0.apps.googleusercontent.com\\u0026as=4uORWOVQ\\u0026destination=https%3A%2F%2Fauth.DOMAIN.COM\\u0026approval_state=!CCm4HdtX2kNd\\u0026oauthgdpr=1\\u0026xsrfsig=AHgI13FkQ\\u0026flowName=GeneralOAuthFlow\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"auth.DOMAIN.COM\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"188.60.195.90:59429\",\"RequestURI\":\"/_oauth?state=9901:https://hydra.DOMAIN.COM/\\u0026code=4/hgAMroE8\\u0026scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email\",\"TLS\":null}"
traefik | 2018-10-31T13:45:54.933021455Z time="2018-10-31T13:45:54Z" level=debug msg="vulcand/oxy/roundrobin/rr: completed ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/_oauth\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"state=99301:https://hydra.DOMAIN.COM/\\u0026code=4/hgAroE8\\u0026scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"en-GB,en-US;q=0.9,en;q=0.8\"],\"Cookie\":[\"_forward_auth_csrf=99301\"],\"Referer\":[\"https://accounts.google.com/signin/oauth/oauthchooseaccount?client_id=bb5q0.apps.googleusercontent.com\\u0026as=4uOVQ\\u0026destination=https%3A%2F%2Fauth.DOMAIN.COM\\u0026approval_state=!Ch2kNd\\u0026oauthgdpr=1\\u0026xsrfsig=AH3FkQ\\u0026flowName=GeneralOAuthFlow\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"auth.DOMAIN.COM\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"188.60.195.90:59429\",\"RequestURI\":\"/_oauth?state=993f201:https://hydra.DOMAIN.COM/\\u0026code=4/hgroE8\\u0026scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email\",\"TLS\":null}"
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 34 (12 by maintainers)
Commits related to this issue
- Bump github.com/stretchr/testify from 1.8.0 to 1.8.1 (#11) Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.0 to 1.8.1. - [Release notes](https://github.com/stretchr... — committed to mkska/traefik-forward-auth by dependabot[bot] 2 years ago
- Merge from jordemort/traefik-forward-auth (#5) * Allow custom key to be used for whitelist and X-Forwarded-User instead of the hardcoded email (#1) * init commit * add github workflow * fix ... — committed to mkska/traefik-forward-auth by mkska 10 months ago
I was able to get this working with Kubernetes. I run traefik-forward-auth in the same pod as my traefik ingress controller (I then run several of these in a deployment). Hence the usage of “localhost” in my forward URL. I also did not need the auth-trust-headers annotation but maybe your case is different.
The key is applying the auth-* annotations to the auth ingress as it’s the auth forwarder module in Traefik which provides the X-Forwarded-Uri. Without the annotations, the auth ingress misses the forwarded URL and ends up in a loop.
You’ll notice there is no traefik.toml. Everything is accomplished with annotations, command line arguments and secrets/environment variables.
My auth host ingress:
A protected service example (Traefik’s dashboard)
Here’s a very stripped down deployment example:
And finally a service definition to power our ingress backend services:
The only allowed redirect URL in my Google Developer console is: https://auth.mydomain.com/auth/_oauth
It took quite a bit of fiddling and research to get this working; feel free to include it as an example somewhere if it’s useful to others.
I was also having an authentication loop issue using
AUTH_HOSTwith docker-compose. I solved it and thought I’d post my solution here since this is one of the top post when you search for this issue on Google 😃 . In my case, the problem was due to the fact that I didn’t enabledtraefik-forward-auth.middlewaresusingtraefik-forward-authglobally for my https entrypoint, I was under the assumption that I could make it work by only adding it to the service I wanted authenticated, and that was a mistake. Thetraefik-forward-auth.middlewaresalso needs to be set on thetraefik-forward-authservice.something like this :
Maybe pointing in the docs that the
forwardauthmiddleware needs to be applied to thetraefik-forward-authservice too would be good ?This is indeed a solution that worked for me too, however I suspect this masks something deeper. Looking at how
it seems that adding the middleware is allowing a successful redirect that otherwise isn’t working.
I initially thought the “callback URL” on GitHub had to be
traefikrepresents traffic:https://auth.domain.com/_oauthwith the explicit path, but it seems to work without. Any thoughts @thomseddon ?Here the log from my side:
There doesn’t seem to be a
X-Forwarded-Uriheader when the request hits ssoauth.mydomain.com, so the server doesn’t know to call the auth callback.Can you post full toml config?
I’m haven’t looked into the way these variables are parsed, but it might be worth trying:
as opposed to:
**also, could you post the annotations for the prometheus.mydomain.com container as this correctly passes
X-Forwarded-Uri@thomseddon It is not self explanatory as I am trying to setup AUTH_HOST. It indeed works if I add
hydra.DOMAIN.COM/_oauthin Google but that is not what I want. It is a bit annoying to add every subdomain to Google but if that is what it takes I can live with it.