Plugging in CA certificate and key

这个task展示运维如何把现有的证书和密钥插入到Istio CA中。

默认情况下,Istio CA生成自签名CA证书和密钥,并使用它们签署工作负载证书。Istio CA也可以使用运维指定证书和私钥签署工作负载证书。这个task演示了一个插入证书和密钥到Istio CA中的例子。

Before you begin

  • 安装Istio。注意在 installation steps 中的第5步开启身份认证。

Plugging in the existing certificate and key

假设我们想要Istio CA使用已有的证书ca-cert.pem 和密钥 ca-key.pem。此外,证书 ca-cert.pem 是由根证书root-cert.pem 签署的,我们希望使用 root-cert.pem 作为Istio 工作负载的根证书。

在这个例子中,因为Istio CA证书 (ca-cert.pem)没有设置为工作负载根证书(root-cert.pem),工作负载不能直接从根证书确认工作负载的证书。工作负载需要一个 cert-chain.pem 文件指定信任链,它应该包括工作负载和根CA间的所有中间CAs的证书。在这个例子中,它只包含CA证书,因此 cert-chain.pemca-cert.pem 相同。注意如果你的 ca-cert.pemroot-cert.pem相同,你可以使用空的 cert-chain.pem 文件。

下载示例文件:

rm /tmp/ca-cert.pem /tmp/ca-key.pem /tmp/root-cert.pem /tmp/cert-chain.pem
wget -P /tmp https://raw.githubusercontent.com/istio/istio/master/security/samples/plugin_ca_certs/ca-cert.pem
wget -P /tmp https://raw.githubusercontent.com/istio/istio/master/security/samples/plugin_ca_certs/ca-key.pem
wget -P /tmp https://raw.githubusercontent.com/istio/istio/master/security/samples/plugin_ca_certs/root-cert.pem
wget -P /tmp https://raw.githubusercontent.com/istio/istio/master/security/samples/plugin_ca_certs/cert-chain.pem

下面步骤能够在Istio CA中插入证书和密钥:

1.创建一个密码 cacert ,它包括所有输入文件 ca-cert.pem, ca-key.pem, root-cert.pem and cert-chain.pem:

kubectl create secret generic cacerts -n istio-system --from-file=/tmp/ca-cert.pem --from-file=/tmp/ca-key.pem \
--from-file=/tmp/root-cert.pem --from-file=/tmp/cert-chain.pem

2.重新部署Istio CA,它从密码安装文件读取证书和密钥:

kubectl apply -f install/kubernetes/istio-ca-plugin-certs.yaml

3.确认工作负载立即获取新的证书,删除Istio CA(named as istio.*)生成的密码。在这个例子中是 istio.default。Istio CA将会为工作负载颁发新证书

kubectl delete secret istio.default

注意,如果你使用不同的证书/密钥文件或者密码名,你需要改变 istio-ca-plugin-certs.yaml 文件中的对应参数。

Verifying the new certificates

这小节中,我们核实被传播的新的工作负载证书和根证书。这需要你在机器上安装 openssl

1.部署bookinfo
2.检索挂载的证书
获取pods:

kubectl get pods

打印:

NAME                                        READY     STATUS    RESTARTS   AGE
details-v1-1520924117-48z17                 2/2       Running   0          6m
productpage-v1-560495357-jk1lz              2/2       Running   0          6m
ratings-v1-734492171-rnr5l                  2/2       Running   0          6m
reviews-v1-874083890-f0qf0                  2/2       Running   0          6m
reviews-v2-1343845940-b34q5                 2/2       Running   0          6m
reviews-v3-1813607990-8ch52                 2/2       Running   0          6m

接下来,我们以pod ratings-v1-734492171-rnr5l 为例,并核实其挂载的证书。运行如下命令检索在proxy上挂载的证书:

kubectl exec -it ratings-v1-734492171-rnr5l -c istio-proxy -- /bin/cat /etc/certs/root-cert.pem > /tmp/pod-root-cert.pem

文件 /tmp/pod-root-cert.pem 应该由运维在根证书中指定。

kubectl exec -it ratings-v1-734492171-rnr5l -c istio-proxy -- /bin/cat /etc/certs/cert-chain.pem > /tmp/pod-cert-chain.pem

文件/tmp/pod-cert-chain.pem 中应该包含工作负载证书及CA证书。

3.核实根证书是否和运维指定的相同:

openssl x509 -in /tmp/root-cert.pem -text -noout > /tmp/root-cert.crt.txt
openssl x509 -in /tmp/pod-root-cert.pem -text -noout > /tmp/pod-root-cert.crt.txt
diff /tmp/root-cert.crt.txt /tmp/pod-root-cert.crt.txt

4.核实CA证书是否和运维指定的相同:

tail /tmp/pod-cert-chain.pem -n 22 > /tmp/pod-cert-chain-ca.pem
openssl x509 -in /tmp/ca-cert.pem -text -noout > /tmp/ca-cert.crt.txt
openssl x509 -in /tmp/pod-cert-chain-ca.pem -text -noout > /tmp/pod-cert-chain-ca.crt.txt
diff /tmp/ca-cert.crt.txt /tmp/pod-cert-chain-ca.crt.txt

预期输出结果为空。

5.从根证书到工作负载证书核实证书链:

head /tmp/pod-cert-chain.pem -n 18 > /tmp/pod-cert-chain-workload.pem
openssl verify -CAfile <(cat /tmp/ca-cert.pem /tmp/root-cert.pem) /tmp/pod-cert-chain-workload.pem

预期结果:

/tmp/pod-cert-chain-workload.pem: OK

Cleanup

  • 移除密码 cacerts:
kubectl delete secret cacerts -n istio-system
  • 移除Istio组件:
kubectl delete -f install/kubernetes/istio-auth.yaml
1. To calculate the covariance matrix, we first need to calculate the mean values for x and y: mean_x = (2+5+6+8)/4 = 5.25 mean_y = (3+5+6+9)/4 = 5.75 Then, we calculate the deviations from the mean for each point: A: (2-5.25, 3-5.75) = (-3.25, -2.75) B: (5-5.25, 5-5.75) = (-0.25, -0.75) C: (6-5.25, 6-5.75) = (0.75, 0.25) D: (8-5.25, 9-5.75) = (2.75, 3.25) Using these deviations, we can calculate the covariance matrix: | var(x) cov(x,y) | Cov = | cov(x,y) var(y) | where var(x) = sum((xi - mean_x)^2)/n var(y) = sum((yi - mean_y)^2)/n cov(x,y) = sum((xi - mean_x)*(yi - mean_y))/n Plugging in the values, we get: var(x) = (3.25^2 + 0.25^2 + 0.75^2 + 2.75^2)/4 = 4.1875 var(y) = (2.75^2 + 0.75^2 + 0.25^2 + 3.25^2)/4 = 4.1875 cov(x,y) = (-3.25*-2.75 + -0.25*-0.75 + 0.75*0.25 + 2.75*3.25)/4 = 3.9375 So the covariance matrix is: | 4.1875 3.9375 | Cov = | 3.9375 4.1875 | 2. To calculate the eigenvalues and eigenvectors of the covariance matrix, we first need to solve for the characteristic equation: | 4.1875-lambda 3.9375 | | x | | 0 | | 3.9375 4.1875-lambda | * | y | = | 0 | Expanding the determinant, we get: (4.1875-lambda)^2 - 3.9375^2 = 0 Solving for lambda, we get lambda1 = 8.375 and lambda2 = 0 For lambda1 = 8.375, we need to solve for the eigenvector: (4.1875-8.375)x + 3.9375y = 0 3.9375x + (4.1875-8.375)y = 0 Simplifying, we get: -4.188x + 3.938y = 0 3.938x - 4.188y = 0 This system has infinitely many solutions, but we can choose any non-zero vector that satisfies it. One such solution is (1, 1), so the corresponding eigenvector is: v1 = (1, 1) For lambda2 = 0, we similarly get: (4.1875-0)x + 3.9375y = 0 3.9375x + (4.1875-0)y = 0 Simplifying, we get: 4.188x + 3.938y = 0 3.938x + 4.188y = 0 This system has a unique solution (x=0, y=0), which means that there is only one linearly independent eigenvector for lambda2. We can choose any non-zero vector that is orthogonal to v1, such as (-1, 1), so the corresponding eigenvector is: v2 = (-1, 1) Therefore, the eigenvalues and eigenvectors of the covariance matrix are: lambda1 = 8.375, v1 = (1, 1) lambda2 = 0, v2 = (-1, 1)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值