代码之家  ›  专栏  ›  技术社区  ›  Mugen

在使用负载均衡器服务的k8s上部署nginx服务器时,不提示客户端证书

  •  0
  • Mugen  · 技术社区  · 7 年前

    我的web服务器后端强制执行客户端证书。在我将部署转移到Kubernetes集群之前,这非常有效。我的猜测是转发规则没有将证书请求从服务器传递到浏览器。

    uwsgi-nginx-flask-docker container .

    server {
        listen 8000 ssl;
        location / {
            try_files $uri @app;
        }
        location @app {
            include uwsgi_params; uwsgi_param SSL_CLIENT_S_DN $ssl_client_s_dn;
    
            uwsgi_pass unix:///tmp/uwsgi.sock;
            uwsgi_read_timeout 300;
    
            ssl_certificate     /app/cert.pem;
            ssl_certificate_key /app/key.pem;
            ssl_password_file   /app/password.pass;
    
            ssl_client_certificate  /app/client-ca.crt;
            ssl_verify_client off;
            ssl_verify_depth 2;
        }
        location /static {
            alias /app/static;
        }
    }
    

    在本地容器上部署此服务器时 SSL_CLIENT_S_DN 在里面 flask.request.environ

    在我的Kubernetes集群上,变量只是空的,浏览器上没有弹出证书请求。

    apiVersion: v1
    kind: Service
    metadata:
      name: my-server
    spec:
      selector:
        app: my-server
      type: LoadBalancer
      loadBalancerIP: XX.XX.XXX.XXX
      ports:
    
      - protocol: TCP
        port: 8000
        targetPort: 8000
    
    ---
    
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: my-server
      labels:
        app: my-server
    spec:
      replicas: 1
      strategy:
        type: RollingUpdate
      selector:
        matchLabels:
          app: my-server
      template:
        metadata:
          labels:
            app: my-server
        spec:
          restartPolicy: Always
          hostname: my-server
          containers:
    
          - name: my-server
            image: asia.gcr.io/my-project/my-server:latest
            imagePullPolicy: Always
            ports:
            - name: LISTEN_PORT
              value: "8000 ssl"
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Crou    7 年前

    Kubernetes支架 multiple means of authentication 它们是: X509 , Static Token File Bootstrap Tokens Static Password File , Service Account Tokens 和 OpenID Connect Tokens

    Here Frederic Branczyk 谁解释如何设置X509客户端证书。

    他创造了一个 ClusterRole

    apiVersion: rbac.authorization.k8s.io/v1beta1
    kind: ClusterRole
    metadata:
      name: read-only-user
    rules:
    - apiGroups:
      - ""
      resources:
      - pods
      - namespaces
      verbs:
      - get
      - list
      - watch
    

    然后在中授予用户这些权限 ClusterRoleBinding

    apiVersion: rbac.authorization.k8s.io/v1beta1
    kind: ClusterRoleBinding
    metadata:
      name: read-only-users
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: read-only-user
    subjects:
    - apiGroup: rbac.authorization.k8s.io
      kind: User
      name: brancz
    

    以上 群集角色绑定 为名为brancz的用户提供 群集角色 称为只读用户

    您还可以看看他用来生成客户机证书的自动化脚本,用集群的CA对它们进行签名,并生成 kubeconfig

    我希望这对你有帮助。

        2
  •  0
  •   JohnDavid    7 年前

    我猜是错误的复制粘贴,请检查以确保您的客户证书的签名者位于约crt链,如果不是它的nginx将无声地失败。

    推荐文章