Disabling service worker. Reverse proxy auth causes issues

Hi,

Not sure whether this issue is in the right category, please feel free to move it to the more appropriate category.

I’m running HA inside my Kubernetes environment. The installation has been done with the Helm Chart and was easy and straight forwared.

In front of HA I use Trafik 2.1 as the ingress controller (reverse proxy) within my Kubernetes cluster. Until here everythin is working smooth.

To enhance the protection level of my external services as well as to enable SSO capability I use the forward-auth feature of my ingress. The first request to HA works fine as long as the service worker is not in place or the current auth session is still valid. But after a while, when the auth session has expired my reverse proxy redirects me correctly to my auth provider (e.g. Google).
But then, after login, the auth provider redirects to HA with all the auth headers and body. But instead this request can be process by my reverse proxy , the service worker of the browser intercepts this request and with it the possibility to get the cookies set right. The only solutions right now are to login first in another service to get a valid auth-session cookie or to empty everything for that domain (cookie, service worker, cache, localstorage, …) to force the initial flow described before.

I try to show the two flows in detail for a better understanding:

Good Flow

  1. Browser sends request to https://ha.domain.com
  2. Request is sent to the reverse-proxy which is listening for incoming requests on ha.domain.com
  3. Reverse-Proxy checks the auth-session (non available) and triggers the forward-auth workflow
  4. Reverse-Proxy sends a 301/302 to the browser with location https://accounts.google.com/...
  5. I do my regular Google login
  6. Google redirects after successful login to https://ha.domain.com?tokens=xxx&claims=yyy (not the real query param names/values but to show the case)
  7. Reverse-Proxy intercepts this request to evaluate the auth-arguments and if valid sets the cookie
  8. Reverse-Proxy forwards the request to the real HA service on https://ha.domain.com
  9. HA installs the service worker to listen and catch everything the browser sends to https://ha.domain.com
  10. I can use HA as expected, because every request contains the valid auth-session cookie, either the request origins from the service-worker or browser.

Bad Flow

  1. I close the browser or wait for some minutes / hours (depending on the expiration value)
  2. I open the browser and enter https://ha.domain.com
  3. Service-worker is intercepting the request
  4. Not pretty sure what’s really happening inside the service-worker
  5. My browser gets redirected to https://accounts.google.com/...
  6. I do my regular Google login
  7. Google is redirecting to https://ha.domain.com?tokens=xxx&claims=yyy
  8. Service worker is intercepting the request and the cookie cannot be set by the reverse-proxy
  9. Not pretty sure what the service-worker is doing
  10. The browser is displaying Error 503 without any further information and no cookies are set in the browser

What really happens is inclear at the moment, haven’t debugged the service-worker yet. But all the following request which are sent to the reverse-proxy are invalid. I guess because the necessary cookie is missing.
I also tried another forward-auth service (currently external-auth-server), but also tried traefik-forward-auth and oauth2_proxy. With the others I get an infinite redirect flow which causes the browser to stop redirecting after a while (crash prevention).

All my other services aren’t affected by that. Just HA with it’s service-worker.

Possible Solutions

  • Can the service-worker be disabled?
  • Can the service-worker be configured to only intercept certain paths (the ones which are really used)?
  • Can the service-worker be configured to no intercept a certain path (excluding the auth-path)
  • Can HA be operated on a sub-path e.g. https://ha.domain.com/ha?
  • Any other configurations which solved this issue

Thank you all for feedback and suggestions.
Cheers Danny

We’re you able to solve this? Love the SSO idea, I didn’t know traefik could do that!

I’ve recently came across a similar issue.
Yes, you can disable the service worker and won’t lose any functionality (but there might be a slight performance impact)
You need to disable the /service_worker.js URL on your reverse proxy somehow.