通过nginx入口控制器进行基本身份验证

通过nginx入口控制器进行基本身份验证,nginx,kubernetes,nginx-ingress,Nginx,Kubernetes,Nginx Ingress,我正在AWS上使用nginx入口控制器()。后端服务(来自ECK:的kibana)使用HTTP基本身份验证机制 有没有办法对nginx进行调优,以便它在转发到我的服务的每个请求中都附加Authorization:Basic头,这样用户就不必键入密码 此解决方案不适用于我: nginx.ingress.kubernetes.io/configuration-snippet: | more_set_headers "Authorization: Basic encoded_credent

我正在AWS上使用nginx入口控制器()。后端服务(来自ECK:的kibana)使用HTTP基本身份验证机制

有没有办法对nginx进行调优,以便它在转发到我的服务的每个请求中都附加Authorization:Basic头,这样用户就不必键入密码

此解决方案不适用于我:

nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers "Authorization: Basic encoded_credentals";

因为我仍然被提示输入密码

这里是一个使用包含使用htpasswd生成的文件的机密的入口规则。重要的是,生成的文件名为auth(实际上,这个秘密有一个key data.auth),否则入口控制器返回一个503

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress-with-auth
  annotations:
    # 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
    nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - foo'
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /
        backend:
          serviceName: http-svc
          servicePort: 80
秘密创造

$ htpasswd -c auth foo
New password: <bar>
New password:
Re-type new password:
Adding password for user foo
$ kubectl create secret generic basic-auth --from-file=auth
secret "basic-auth" created
$ kubectl get secret basic-auth -o yaml
apiVersion: v1
data:
  auth: Zm9vOiRhcHIxJE9GRzNYeWJwJGNrTDBGSERBa29YWUlsSDkuY3lzVDAK
kind: Secret
metadata:
  name: basic-auth
  namespace: default
type: Opaque
检查此示例

解决方案:

nginx.ingress.kubernetes.io/configuration-snippet: |
    more_set_input_headers "Authorization: Basic <based64 user:pass>";
nginx.ingres.kubernetes.io/configuration-snippet:|
更多设置输入标题“授权:基本”;

这添加了一个身份验证层,这与我试图实现的目标完全相反。好吧,也许我误解了……如果用户不是从您希望的密码来源输入密码?
nginx.ingress.kubernetes.io/configuration-snippet: |
    more_set_input_headers "Authorization: Basic <based64 user:pass>";