Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add-headers does not seem to work #4359

Closed
ilya-spv opened this issue Jul 26, 2019 · 0 comments · Fixed by #4463
Closed

Add-headers does not seem to work #4359

ilya-spv opened this issue Jul 26, 2019 · 0 comments · Fixed by #4463

Comments

@ilya-spv
Copy link

ilya-spv commented Jul 26, 2019

BUG REPORT

NGINX Ingress controller version:
0.21.0 (installed via helm chart version 1.1.1)

Kubernetes version (use kubectl version):
1.12.6

Environment:

  • Azure AKS:

What happened:
I have an nginx ingress controller via helm with add-header config options.

I have one ingress definition that sends traffic to my api service, but the headers are not applied (I do not see headers in the response).

What you expected to happen:

Expect to see all headers that are added via add-header

How to reproduce it (as minimally and precisely as possible):

Create an nginx ingress controller with the following definitions:

ingress controller config map

data:
  add-headers: my-system/custom-headers
  enable-vts-status: "true"
  log-format-upstream: timestamp="$time_local" ...
  proxy-set-headers: my-system/my-ingress-controller-nginx-ingress-custom-headers

my-system/my-ingress-controller-nginx-ingress-custom-headers

data:
  Request-ID: $request_id

my-system/custom-headers

data:
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  X-Content-Type-Options: nosniff
  X-Frame-Options: Deny

Anything else we need to know:

I have checked the nginx.conf file on the pod and that one does indeed include 3 add_header lines, so this part of the config seems to be correct. But it does not result in headers being sent in the response.

Now according to this SO question what can happen is that add_header is being overridden if it is found in the location part of the nginx configuration.

I have located some that could affect it:

  1. Option nginx.ingress.kubernetes.io/auth-url seems to add this:
    add_header Set-Cookie $auth_cookie;

  2. Default hsts has this:

  if ($scheme = https) {
         more_set_headers   "Strict-Transport-Security: max-age=15724800; includeSubDomains";
  }
  1. $redirect_to_https doe seem to affect the outcome as well

So after I removed all this things I got my headers on a plain HTTP request but HTTPS request still did not return the headers, so there is something that is still overriding this setting.

I think add-header options should work regardless of all this all the time (or at least document the limitations, though it's best that it works).

I am not quite sure how this can be achieved, I am not an nginx expert, but perhaps duplicating add-header under all locations in the appropriate place rather than putting it on top can do the trick.

P.S. I have just updated to the latest helm (with nginx-ingress 0.25.0 and there is still same issue there).

zerda added a commit to zerda/ingress-nginx that referenced this issue Aug 18, 2019
zerda added a commit to zerda/ingress-nginx that referenced this issue Aug 18, 2019
It should work regardless response code or add_header directive in location, fixes kubernetes#4359
zerda added a commit to zerda/ingress-nginx that referenced this issue Aug 18, 2019
It should work regardless of the response code or add_header directive in location, fixes kubernetes#4359
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant