最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring - Loss of x-forwarded-for header when using service=ClusterIP - Stack Overflow

programmeradmin2浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论