【问题标题】:How to create a Kubernetes client certificate signing request for Cockroachdb如何为 Cockroachdb 创建 Kubernetes 客户端证书签名请求
【发布时间】:2018-08-23 09:46:32
【问题描述】:

我正在使用的环境是一个运行 cockroach/gke 的安全集群。

我有一个批准的 default.client.root 证书,它允许我使用 root 访问数据库,但我不明白如何为其他用户生成新的证书请求。我一遍又一遍地阅读了 cockroachDB 文档,它解释了如何在可访问 ca.key 位置的独立配置中手动生成用户证书,但没有具体说明如何在 Kubernetes 的上下文中执行此操作。

我相信图像 cockroachdb/cockroach-k8s-request-cert:0.3 是起点,但我无法弄清楚如何使用它的模式。

任何指针将不胜感激。最终,我希望能够在使用 pg 客户端的同一个 Kubernetes 集群中使用来自 API 的证书。目前,它处于不安全模式,仅使用用户名和密码。

【问题讨论】:

    标签: kubernetes client-certificates cockroachdb


    【解决方案1】:

    request-cert 作业用作 pod 的初始化容器。它将使用 K8S CSR API 请求客户端或服务器证书(服务器证书由 CockroachDB 节点请求)。

    您可以在client-secure.yaml 中看到请求客户端证书然后由作业使用的示例。 init 容器在普通容器之前运行:

      initContainers:
      # The init-certs container sends a certificate signing request to the
      # kubernetes cluster.
      # You can see pending requests using: kubectl get csr
      # CSRs can be approved using:         kubectl certificate approve <csr name>
      #
      # In addition to the client certificate and key, the init-certs entrypoint will symlink
      # the cluster CA to the certs directory.
      - name: init-certs
        image: cockroachdb/cockroach-k8s-request-cert:0.3
        imagePullPolicy: IfNotPresent
        command:
        - "/bin/ash"
        - "-ecx"
        - "/request-cert -namespace=${POD_NAMESPACE} -certs-dir=/cockroach-certs -type=client -user=root -symlink-ca-from=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        volumeMounts:
        - name: client-certs
          mountPath: /cockroach-certs
    

    这会使用 K8S API 发送 CSR,等待批准,然后将所有生成的文件(客户端证书、客户端证书的密钥、CA 证书)放在 /cockroach-certs 中。如果证书已经作为 K8S 机密存在,它只会抓取它。

    您只需将--user=root 更改为您要使用的用户名,即可为任何用户申请证书。

    【讨论】:

    • 谢谢。我确实尝试过这个,但是遇到了除 root 以外的用户的错误。将尝试这个来检查错误。
    • 默认只有root用户存在。任何其他用户都需要通过 sql shell 创建。然后,您应该能够使用该用户及其客户端证书进行连接。
    • 感谢您的支持 - 它正在工作。我确实已经创建了用户。执行修改后的 client-secure.yaml 会导致我无法追踪的 pod init 错误,但它确实会触发我可以批准的 csr 请求。我上次在 init 错误时放弃了,没有检查 csr 请求是否确实已经发出。改天将不得不尝试找出 pod 初始化错误。
    猜你喜欢
    • 2017-11-02
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-02
    • 1970-01-01
    • 2018-09-21
    相关资源
    最近更新 更多