Search code examples
nginxkubernetesproxygoogle-kubernetes-enginekubernetes-ingress

GKE ingress pass cookie as header


I would like to use some kubernetes ingress (doesn't matter the ingress type) on google cloud GKE 1.19.7-gke.1302, and nginx ingress deployed by nginx-ingress-0.8.0 helm chart, and my need is to fetch a cookie and use it later to authenticate to our service. When I use nginx as deployment it works, but when I use nginx ingress it seems to ignore the annotation.

I tried using this configuration snippet for the nginx ingress, which works on the nginx deployment but not on the ingress:

nginx.ingress.kubernetes.io/configuration-snippet: |
  proxy_set_header "Authorization" "Basic $cookie_myToken";  

And this is my entire ingress yaml:

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-nginx-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    # enable backend redirections
    kubernetes.io/tls-acme: "true"
    # enable stickiness
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/session-cookie-name: "route"
    nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
    nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header "Authorization" "Basic $cookie_myToken";  
spec:
  tls:
  - secretName: my-tls
    hosts: 
    - "test.com"
  defaultBackend:
    service:
      name: my-nodeport
      port:
        number: 80
  rules:
    - host: "test.com"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: my-nodeport
                port:
                  number: 80

Any ideas?


Solution

  • Posting this answer to make it more visible as issue was identified and solved in comment section.

    Root cause of this issue was Nginx Ingress Controller misconfiguration.

    In the OP's setup Nginx Ingress Controller, v.0.8.0 was used. After redeploying Nginx Ingress to latest version (v0.44.0) from Nginx Ingress Documentation it started working properly.

    Yes, reinstalling nginx ingress to the latest version with helm solved the problem.