Search code examples
kubernetesnginxnginx-ingress

Not being able to use Basic Auth in NGINX Ingress Controller


I'm using NGINX Ingress Controller and I want to use Basic Authentication, but I'm getting a 403 Error in the browser. I created a secret with data.auth base64 obtained from a file created with htpasswd and in the Ingress, I've added the annotations

annotations:
  nginx.org/basic-auth-secret: htpasswd
  nginx.org/basic-auth-realm: "Authentication Required"

where htpasswd is the name of the secret in the same namespace as the ingress.

Checking the logs of the Nginx-ingress pod, I can find this

[error] 1783#1783: *68296 open() "/etc/nginx/secrets/my-demo-htpasswd" failed (2: No such file or directory)

What should I do to get the secrets loaded in the Ingress Controller?


Solution

  • with "nginx.org" you need to use the secret type: nginx.org/htpasswd

    apiVersion: v1  
    kind: Secret  
    metadata:  
      name: basic-auth  
    type: nginx.org/htpasswd  
    stringData:  
      htpasswd: <copy the contents of the htpasswd file here>
    
      example 
      htpasswd: foo:$apr1$T6zUs/pB$xvCvBUfMvvIk8r12lZz9C0