0

I am working on a kubernetes cluster and problem faced is:

From UI/browser, I can see it is sending a request header called "request_id" please refer to image:

enter image description here

But while checking on backend it is unavailable. While searching through internet, I could see that people are talking about adding following entry to Ingress object:

nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header request_id "$req_id";

But it is generating a new value for this and not passing value submitted by browser.

Any ideas, what might be missing here?

Mark Watney
  • 5,268
  • 2
  • 11
  • 33
Prateek Jain
  • 2,738
  • 4
  • 28
  • 42
  • I used your snippet configuration and one echoserver as backend and I can see the request id as x-request-id=c41db348719aa07093d9df53b2e8c24d – c4f4t0r Dec 15 '19 at 11:29
  • @c4f4t0r, that is a newly generated id by ingress controller. What I am looking for is, the same request-id; as sent by UI/browser. – Prateek Jain Dec 15 '19 at 14:16

2 Answers2

2

If you want to pass a custom header to your backend, you need to use this kind of annotation:

nginx.ingress.kubernetes.io/configuration-snippet: |
  more_set_headers "Request-Id: $request_id

In your configuration you are using the variable $req_id, but you need to pass the variable sent by UI/browser.

c4f4t0r
  • 1,563
  • 15
  • 24
2

Basically, ingress-nginx-controller drops any request headers that contains "_" in them. You can find various threads which discuss this issue like,

Why HTTP servers forbid underscores in HTTP header names

So, I just enabled ingress controller to pass such request headers. This can be done by adding following entry to configmap "nginx-configuration"

data:
  enable-underscores-in-headers: "true"

IMO, this is a much clean solution as there could be many applications that might use "_" in request headers.

Prateek Jain
  • 2,738
  • 4
  • 28
  • 42