We use k8s to deploy our applications and encountered unexpected behavior. We have a microservice written in java 21 using the spring framework. This microservice provides an HTTP API for external consumers.
The microservice is deployed in k8s using helm chart, in the configuration it is specified that it will use a Service with the ClusterIP
type. Everything works fine, but we encountered a problem: when sending the X-Forwarded-For
header with the client's IP address to the microservice, this header is "automatically" cut off.
That is, we go to the deployed pod of the microservice and execute the request:
wget --no-check-certificate -S \
--timeout=0 \
--header 'X-Forwarded-For: 10.100.10.100' \
--header 'X-Forwarded-Host: example' \
--header 'X-CustomHeader: custom-header' \
--header 'Content-Type: application/json' \
-q 'http://127.0.0.1:8080/api/v1/test'
In the microservice logs, we see:
POST "/api/v1/test", parameters={}, headers={host:[127.0.0.1:8080], user-agent:[Wget], accept:[*/*], connection:[close], x-forwarded-host:[example], x-customheader:[custom-header], content-type:[application/json], content-length:[102]} in DispatcherServlet 'dispatcherServlet'
As you can see, the manually transmitted X-Forwarded-For
header did not reach the microservice.
We found this answer on SO, but the question itself is quite old and there is no explicit information that the header will be removed.
Can someone tell me why this is happening?