5

We are setting up an AKS cluster on Azure, following this guide

We are running 5 .Net Core API's behind an ingress controller, everything works fine, requests are being routed nicely. However, in our SPA Frontend, we are sending a custom http header to our API's, this header never seems to make it to the API's, when we inspect the logging in AKS we see the desired http header is empty. In development, everything works fine, we also see the http header is filled in our test environment in AKS, so i'm guessing ingress is blocking these custom headers.

Is there any configuration required to make ingress pass through custom http headers?

EDIT:

{
  "kind": "Ingress",
  "apiVersion": "extensions/v1beta1",
  "metadata": {
    "name": "myappp-ingress",
    "namespace": "myapp",
    "selfLink": "/apis/extensions/v1beta1/namespaces/myapp/ingresses/myapp-ingress",
    "uid": "...",
    "resourceVersion": "6395683",
    "generation": 4,
    "creationTimestamp": "2018-11-23T13:07:47Z",
    "annotations": {
      "kubernetes.io/ingress.class": "nginx",
      "nginx.ingress.kubernetes.io/allow-headers": "My_Custom_Header", //this doesn't work
      "nginx.ingress.kubernetes.io/proxy-body-size": "8m",
      "nginx.ingress.kubernetes.io/rewrite-target": "/"
    }
  },
  "spec": {
    "tls": [
      {
        "hosts": [
          "myapp.com"
        ],
        "secretName": "..."
      }
    ],
    "rules": [
      {
        "host": "myapp.com",
        "http": {
          "paths": [
            {
              "path": "/api/tenantconfig",
              "backend": {
                "serviceName": "tenantconfig-api",
                "servicePort": 80
              }
            },
            {
              "path": "/api/identity",
              "backend": {
                "serviceName": "identity-api",
                "servicePort": 80
              }
            },
            {
              "path": "/api/media",
              "backend": {
                "serviceName": "media-api",
                "servicePort": 80
              }
            },
            {
              "path": "/api/myapp",
              "backend": {
                "serviceName": "myapp-api",
                "servicePort": 80
              }
            },
            {
              "path": "/app",
              "backend": {
                "serviceName": "client",
                "servicePort": 80
              }
            }
          ]
        }
      }
    ]
  },
  "status": {
    "loadBalancer": {
      "ingress": [
        {}
      ]
    }
  }
}
Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Arne Deruwe
  • 1,100
  • 2
  • 11
  • 25

3 Answers3

8

I ended up using the following configuration snippet:

nginx.ingress.kubernetes.io/configuration-snippet: |
  proxy_set_header My-Custom-Header $http_my_custom_header;

nginx makes all custom http headers available as embedded variable via the $http_ prefix, see this

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Arne Deruwe
  • 1,100
  • 2
  • 11
  • 25
4

If I want my ingress controller pass a custom header to my backend service, I can use this annotation in my ingress rule

nginx.ingress.kubernetes.io/configuration-snippet: |
  more_set_headers "Request-Id: $req_id";
c4f4t0r
  • 1,563
  • 15
  • 24
  • Thanks, can you clarify this a bit? Request-Id would then be My_Custom_Header in my specific case? And what is the $req_id variable? I tried setting this with My_Custom_Header: test, no luck unfortunately – Arne Deruwe Jan 18 '19 at 07:41
  • this is an example, you need to pute the name of your custom header $my_costum_header and the desired name. – c4f4t0r Jan 18 '19 at 10:54
  • 1
    It put me in the right direction, I ended up using a configuration snippet for proxy_set_header – Arne Deruwe Jan 22 '19 at 09:50
  • where does th $req_id come from. Does nginx controller set this variable for each request – PraveenMak Jun 01 '23 at 23:38
  • https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/log-format/ – c4f4t0r Jun 03 '23 at 15:47
2

By default ingress doesn’t pass through headers with underscores. You could set

enable-underscores-in-headers: true

See https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#enable-underscores-in-headers

Also Ingress doesn’t pass through Authorization header

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170