Why Ingress NGINX removes my response headers
Use following annotations in your ingress to set response header
nginx.ingress.kubernetes.io/configuration-snippet: | more_set_headers "X-Frame-Options: Deny"; more_set_headers "X-Xss-Protection: 1; mode=block"; more_set_headers "X-Content-Type-Options: nosniff";
The you are not able to find those headers as the traffic is flowing from a nginx ingress controller which acts as a proxy. To add some custom headers you can use the following given steps.
create a file and name it as
custom-headers.yml
and add the following data.apiVersion: v1data: X-Frame-Options: "Deny" X-Xss-Protection: "1; mode=block" X-Content-Type-Options: "nosniff" kind: ConfigMapmetadata:name: custom-headersnamespace: ingress-nginx
This file will create a ConfigMap in the ingress-nginx namespace. Apply this ConfigMap:kubectl apply -f custom-headers.yml
Now we need to make our nginx ingress controller to use this new ConfigMap. For that we need to add our config map with the global configs that were being used until now. For that create a file configmap.yml and add the following data. apiVersion: v1 data: proxy-set-headers: "ingress-nginx/custom-headers" kind: ConfigMap metadata: name: nginx-configuration namespace: ingress-nginx labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx
Apply this configuration by :kubectl apply -f configmap.yml
Check your configurations by using : kubectl exec <nginx-controller pod name> -n ingress-nginx cat /etc/nginx/nginx.conf
I have not tried this myself but I think you need to enable this setting.
data: allow-backend-server: "true"
You may try to enable this settings via annotations.