Forward Headers not working in Spring Boot + Kubernetes Forward Headers not working in Spring Boot + Kubernetes kubernetes kubernetes

Forward Headers not working in Spring Boot + Kubernetes


I figured it out. My mistake was assuming that networkCIDR was the IP address returned by request.getRemoteAddr(), when it was actually my k8s internal cluster IP. This makes sense given that the request is coming from Apache, which is also inside the cluster. The internal cluster IP was NOT in the list of internal proxies, and thus RemoteIPValve was not utilizing the forward headers.

By adding the server.tomcat.internal-proxies property to my application.properties with the default values specified in RemoteIpValve AND my internal cluster IP, everything worked as it should.

See https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-servlet-containers.html#howto-customize-tomcat-behind-a-proxy-server