apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-basic-auth
  annotations:
    # use the shared ingress-nginx
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    # type of authentication
    nginx.ingress.kubernetes.io/auth-type: basic
    # name of the secret that contains the user/password definitions
    nginx.ingress.kubernetes.io/auth-secret: basic-auth
    # message to display with an appropriate context why the authentication
    # is required. This is returned in the 'WWW-Authenticate' response
    # header.
    nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - foo'
    # nginx snippet to pass through the logged in user in a header.
    nginx.ingress.kubernetes.io/configuration-snippet: proxy_set_header x-remote-user $remote_user;
    
spec:
  rules:
    - host: localhost
      http:
        paths:
          - path: /auth-service
            pathType: Prefix
            backend:
              service:
                name: example-service
                port:
                  number: 3000
            path: /auth-service(/|$)(.*)