How to keep Authentication header with redirect using NGINX ingress annotations

5,704

This is what I did to overcome the stripping of the Authorization header:

annotations:
  ... your other annotations
  nginx.ingress.kubernetes.io/configuration-snippet: |
    proxy_set_header Authorization $http_authorization;

This will force the setting of a new Authorization header that reads it's value from the actual authorization header.

I have not tried this with the external authorization though, only with basic auth.

Share:
5,704
G. Ball
Author by

G. Ball

Updated on September 18, 2022

Comments

  • G. Ball
    G. Ball almost 2 years

    I have an nginx ingress controller for my kubernetes cluster. I have a need to add a permanent redirect to an ingress which I can successfully do with

    nginx.ingress.kubernetes.io/permanent-redirect: "http://www.example.com"
    

    This works great, except for the fact that path I'm redirecting is used for by users that send POST requests including an Authorization header.

    My understanding is that by default (for security reasons) the header would get stripped out. However, I'm redirecting the post request from one server to another on the same domain.

    Is there a way to add the necessary instructions to pass the Authorization header along with the redirect?

    Thanks!

  • tobias47n9e
    tobias47n9e almost 3 years
    Not sure if this still works. I can set any header this way, but "Authorization" ist still stripped away.