Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

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

With ingress-nginx no longer maintained, plenty of teams are moving to Traefik. Its kubernetesIngressNGINX provider reads your existing nginx.ingress.kubernetes.io/* annotations, so in theory you swap the controller and

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

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

In August someone did that on AKS with Traefik v3.7.1. One Ingress had oauth2-proxy in front of a dashboard:

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, which only resolves inside the cluster.

They opened traefik/traefik#13680 with two A/B tests that pointed straight at upstream-vhost. I sent the fix, #13787, and it shipped in Traefik v3.7.20 and v3.8.0 on 23 November.

The sign-in redirect, before and after

Why it happened

The provider turns each annotation into a middleware and chains them. upstream-vhost overwrites req.Host. The auth middleware calls your auth server and, on a 401, builds the sign-in URL by filling in $host from the request.

In v3.7.0 to v3.7.19 the vhost middleware came first. By the time auth ran, the host was already web.application.svc.cluster.local:8084.

Middleware order in v3.7.19 and v3.7.20

ingress-nginx doesn't work that way. There, upstream-vhost is only proxy_set_header Host on the location that proxies to the backend, so the auth subrequest and the sign-in redirect still see the client's host. The fix moves the vhost middleware to after auth, which matches it.

Your auth server sees it too

I reproduced this on kind with v3.7.19 and v3.7.20. Besides the redirect, the auth middleware sends X-Forwarded-Host to your auth server, and on v3.7.19 that was the internal name as well. If your auth server builds redirects or rules from the forwarded host, it was working with the wrong one.

Who sees which host

It isn't an auth bypass. The auth server is still called and a 401 still stops the request.

Check yours

You're affected on Traefik v3.7.0 to v3.7.19 with the kubernetesIngressNGINX provider and upstream-vhost on an Ingress. The broken redirect also needs auth-signin; the wrong forwarded host only needs auth-url (or the provider's globalAuthURL).

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

If the location contains svc.cluster.local, upgrade to v3.7.20 or v3.8.0. Until you can, hardcoding the public host in auth-signin works as long as you keep the explicit rd. Drop the rd and Traefik adds a default one that still points inside the cluster.

The full post has the jq command to find affected Ingresses, all the workarounds I tested, and the code change.

Read the full post on saipisey.com →

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.