获取 Azure K8s 以信任自签名证书

问题描述 投票:0回答:1

我运行一个私有 aks,该集群运行的服务也连接到更广泛的公司网络中的其他服务。在我们公司,我们有一个内部自签名的根证书。而

example.company.internal
域下有一个我们需要访问的服务。
example.company.internal
的证书是由我们自签名的根证书签署的。

对于所有 Windows PC,这都没有问题,因为某些策略会将根证书添加到 Windows 受信任的证书存储中。

但是,从集群内部,如果我运行

curl https://example.company.internal/
我会得到以下输出

curl: (60) SSL certificate problem: self signed certificate in certificate chain
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

我到目前为止还找不到一种方法让整个集群信任这个自签名证书。 任何指导将不胜感激。

kubernetes azure-aks
1个回答
0
投票

要让 AKS 群集信任自签名证书,您需要将根证书添加到群集环境中的受信任存储中。这通常涉及在容器级别配置信任,因为 Kubernetes 本身不直接管理出站连接的 SSL/TLS 证书。

使用您的根证书创建 ConfigMap -

kubectl create configmap custom-root-ca --from-file=rootCA.pem -n your-namespace
enter image description here

这会将您的根证书作为 ConfigMap 存储在 Kubernetes 中,使其可以挂载到 Pod 中。

更新您的部署以使用受信任的证书。 部署示例-

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  namespace: default
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      initContainers:
      - name: add-ca-cert
        image: alpine
        command:
        - sh
        - -c
        - >
          if [ -f /etc/ssl/certs/ca-certificates.crt ]; then
            cat /etc/ssl/certs/custom-root-ca/rootCA.pem >> /etc/ssl/certs/ca-certificates.crt;
          elif [ -f /etc/ssl/cert.pem ]; then
            cat /etc/ssl/certs/custom-root-ca/rootCA.pem >> /etc/ssl/cert.pem;
          else
            echo "No known SSL directory found.";
            exit 1;
          fi
        volumeMounts:
        - name: custom-root-ca
          mountPath: /etc/ssl/certs/custom-root-ca
          readOnly: true
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
        volumeMounts:
        - name: custom-root-ca
          mountPath: /etc/ssl/certs/custom-root-ca
          readOnly: true
      volumes:
      - name: custom-root-ca
        configMap:
          name: custom-root-ca

同样适用

kubectl apply -f <filename.yaml>

enter image description here

enter image description here

然后执行到你的 pod 中

kubectl exec -it [your-pod-name] -- /bin/sh
检查是否附加了CA证书(根据您的系统选择正确的证书文件)
cat /etc/ssl/certs/ca-certificates.crt | grep "Issuer"

© www.soinside.com 2019 - 2024. All rights reserved.