Skip to content
← cd ../blog

Moving off ingress-nginx to Traefik? Your login redirect may point at svc.cluster.local

Sai Pisey3 min readTraefik · ingress-nginx · Kubernetes

In short

  • Traefik's kubernetesIngressNGINX provider lets you keep your ingress-nginx annotations. In v3.7.0 to v3.7.19, an Ingress with auth-url, auth-signin and upstream-vhost together sent logged-out users to the internal service name, like https://web.application.svc.cluster.local/oauth2/start.
  • The upstream-vhost middleware ran before the auth middleware, so $host in auth-signin and the X-Forwarded-Host sent to your auth server both read the rewritten host. In ingress-nginx, upstream-vhost only touches the request to the backend.
  • It's fixed in Traefik v3.7.20 and v3.8.0. On older versions, hardcode the public host in auth-signin and keep an explicit rd, or drop upstream-vhost.

With ingress-nginx no longer maintained, plenty of teams are moving to Traefik. Its kubernetesIngressNGINX provider is the easy path: it reads your existing nginx.ingress.kubernetes.io/* annotations, so in theory you change the controller and leave the Ingress objects alone.

In August someone did exactly that on AKS, running Traefik v3.7.1 next to ingress-nginx and pointing a test request at it. One Ingress had oauth2-proxy in front of a dashboard, with these three annotations:

yaml
nginx.ingress.kubernetes.io/auth-url: "http://oauth-proxy.infrastructure.svc.cluster.local:4180/oauth2/auth"
nginx.ingress.kubernetes.io/auth-signin: "https://$host/oauth2/start?rd=$escaped_request_uri"
nginx.ingress.kubernetes.io/upstream-vhost: "$service_name.$namespace.svc.cluster.local:8084"

ingress-nginx sent logged-out users to https://dashboard.example.internal/oauth2/start. Traefik sent them to https://web.application.svc.cluster.local/oauth2/start, a name that only resolves inside the cluster. Login was broken for everyone outside it.

They opened traefik/traefik#13680 with the repro and two A/B tests that narrowed it down to upstream-vhost. I sent the fix, #13787. It shipped in Traefik v3.7.20 and v3.8.0 on 23 November 2026.

What you see

I rebuilt the reporter's setup on a kind cluster, with a stub auth server that always returns 401, and sent the same request to v3.7.19 and v3.7.20:

terminal
curl -skI https://dashboard.example.internal/private | grep -i location

v3.7.19  location: https://web.application.svc.cluster.local/oauth2/start?rd=%2Fprivate
v3.7.20  location: https://dashboard.example.internal/oauth2/start?rd=%2Fprivate

request

GET https://dashboard.example.internal/private
v3.7.19
302 location: https://web.application.svc.cluster.local/oauth2/start?rd=%2Fprivateunreachable outside the cluster
v3.7.20
302 location: https://dashboard.example.internal/oauth2/start?rd=%2Fprivateback to the public host
A logged-out GET https://dashboard.example.internal/private, with auth-url, auth-signin and upstream-vhost on the same Ingress. Both versions return 302. Only the host in the Location header differs.

If you're already signed in, you never see the sign-in redirect. It only shows up for someone who isn't, like a new user or an expired session, which makes it easy to miss in a quick migration test.

Why it happened

The provider turns each annotation into a Traefik middleware and chains them on the router. upstream-vhost becomes a middleware that overwrites req.Host. auth-url and auth-signin become the auth middleware, which calls your auth server and, on a 401, builds the redirect by filling in $host from the request.

In v3.7.19 the chain was built with the vhost middleware first:

go
// translator.go, applyMiddlewares, v3.7.19
if loc.UpstreamVhost != nil {
	name := routerKey + "-vhost"
	conf.HTTP.Middlewares[name] = &dynamic.Middleware{UpstreamVHost: loc.UpstreamVhost}
	rt.Middlewares = append(rt.Middlewares, name)
}
// ... rate limits, connection limits, custom headers ...
// ... then the auth snippet (auth-url, auth-signin)

So by the time the auth middleware ran, the request's host was already web.application.svc.cluster.local:8084. $host in the sign-in URL picked that up.

v3.7.0 to v3.7.19

clientHost: dashboard.example.internal
upstream-vhostrewrites Host first
auth (auth-url, auth-signin)$host = web.application.svc…
backendHost: web.application.svc…:8084

v3.7.20 and v3.8.0

clientHost: dashboard.example.internal
auth (auth-url, auth-signin)$host = dashboard.example.internal
upstream-vhostrewrites Host for the backend
backendHost: web.application.svc…:8084
The provider chains one middleware per annotation. In v3.7.19 the vhost rewrite ran first, so the auth step built the redirect and the forwarded host from the internal name. v3.7.20 runs auth first and rewrites the host only for the request that goes on to the backend, which is what ingress-nginx does.

That isn't what ingress-nginx does. There, upstream-vhost is just proxy_set_header Host on the location that proxies to the backend. The auth subrequest and the sign-in redirect are built from the client's own host header, so they never see the rewrite.

Your auth server sees it too

The redirect isn't the only thing that reads the host. The auth middleware also sends X-Forwarded-Host to your auth server. I swapped the stub for an echo server that returns 200 and logged what it received:

client, in the 302 Location
v3.7.19web.application.svc.cluster.localv3.7.20dashboard.example.internal
auth server, X-Forwarded-Host
v3.7.19web.application.svc.cluster.local:8084v3.7.20dashboard.example.internal
backend, Host
v3.7.19web.application.svc.cluster.local:8084v3.7.20web.application.svc.cluster.local:8084
Measured on kind. The sign-in redirect used a 401 stub as the auth server, the forwarded host came from an echo server returning 200, and the backend Host from whoami's response. My port-forward added :18443 to the v3.7.20 forwarded host; it's left out here. The backend getting the upstream host is intended, and it's the same in both versions.

On v3.7.19 your auth server is told the request was for web.application.svc.cluster.local:8084. If it builds redirects or applies rules based on the forwarded host, it's working with the wrong name. The backend gets the rewritten host in both versions, which is the whole point of upstream-vhost.

This isn't a way around authentication. The auth server is still called on every request and a 401 still stops it. The internal service name does leak into the redirect, and the port too when Traefik builds the default rd.

The fix

The PR moves the vhost middleware to after the auth middleware, still before retry and the backend:

go
// Apply upstream-vhost after auth so auth-signin uses the original request host.
if loc.UpstreamVhost != nil {
	name := routerKey + "-vhost"
	conf.HTTP.Middlewares[name] = &dynamic.Middleware{UpstreamVHost: loc.UpstreamVhost}
	rt.Middlewares = append(rt.Middlewares, name)
}

I added a test that the vhost middleware comes after the auth snippet in the chain. A Traefik reviewer added a second one that runs the real auth and vhost middlewares together, checking both cases: a 401 redirects to the original host, and a 200 reaches the backend with the upstream host.

Am I affected?

You need Traefik v3.7.0 to v3.7.19 with the kubernetesIngressNGINX provider, and an Ingress with upstream-vhost. Then:

  • The broken redirect needs auth-signin too, along with auth-url.
  • The wrong X-Forwarded-Host only needs external auth: auth-url on the Ingress, or the provider's globalAuthURL.
  • $host in auth-url itself, or in a configuration or server snippet, also reads the rewritten host.

basic-auth and digest-auth always ran before the vhost middleware, so they were never affected.

To find Ingresses with both annotations (if you use globalAuthURL, every Ingress with upstream-vhost counts):

bash
kubectl get ingress -A -o json | jq -r '.items[]
  | select(.metadata.annotations["nginx.ingress.kubernetes.io/upstream-vhost"]
       and .metadata.annotations["nginx.ingress.kubernetes.io/auth-url"])
  | "\(.metadata.namespace)/\(.metadata.name)"'

Then send a logged-out request and look at the redirect:

bash
curl -skI --resolve app.example.com:443:<traefik-ip> https://app.example.com/ | grep -i location

If it contains svc.cluster.local, you have it.

If you can't upgrade yet

Upgrading to v3.7.20 or v3.8.0 is the real fix. Until then, I tested two workarounds on v3.7.19:

nothing (original annotations)brokenlocation: https://web.application.svc.cluster.local/oauth2/start?rd=%2Fprivate
hardcode host in auth-signin, keep rd=$escaped_request_uriworkslocation: https://dashboard.example.internal/oauth2/start?rd=%2Fprivate
remove upstream-vhostworkslocation: https://dashboard.example.internal/oauth2/start?rd=%2Fprivate
hardcode host, drop rd (Traefik adds a default)redirect back is brokenrd=https://web.application.svc.cluster.local:8084%2Fprivate
Each row is a change to the same Ingress on Traefik v3.7.19, followed by the same logged-out request. The last one fixes the sign-in host but not where users land after signing in, because the default rd is built from the rewritten host.
  • Hardcode the public host in auth-signin and keep rd=$escaped_request_uri. The redirect is correct. Your auth server still gets the wrong X-Forwarded-Host, though.
  • Drop upstream-vhost if your backend doesn't really need a specific Host header. Both the redirect and the auth server see the right host.

Don't also remove rd. If you hardcode the host and also remove rd from auth-signin, Traefik adds a default rd built from the request host. On v3.7.19 that default points back at https://web.application.svc.cluster.local:8084/private, so users sign in and get sent somewhere they can't reach. Keep the explicit rd.

The report that started this is traefik/traefik#13680, and the fix is #13787.

Ready to Build Something Resilient?

Whether it's hardening your platform, untangling a messy CI/CD setup, or just talking infrastructure over a call, let's connect. I'm always up for a good systems conversation.

Book a call

$ ./contact.sh

Get in Touch

I only use these details to reply to you. Ask and I'll delete them.