Rancher创建用户报错 x509: certificate has expired or is not yet valid

报错信息:

Internal error occurred: failed calling webhook "rancherauth.cattle.io": Post https://rancher-webhook.cattle-system.svc:443/v1/webhook/validation?timeout=10s: x509: certificate has expired or is not yet valid

排查思路: 

1、根据报错信息可以看出是证书过期了

    可用信息  cattle-system.svc ,去该名称空间下找到过期的证书

 

 

 

 

2、接下来需要准备签发证书所需文件

     打开cattle-webhook-ca  查看编辑YAML(找到自己对应签发的CA文件)

 

 

 将两个秘钥分别用base64进行解密(直接网上搜索)

 解密文件分别保存为  ca.crt   ca.key  (创建单独目录存放,后面签发证书需要这两个文件)

 打开cattle-webhook-tls

 将里面的tls证书进行解密,保存文件tls.crt

 

 

 同时需要查看旧的证书细节:

 openssl x509 -in tls.crt -noout -text

 

 

 

  DNS 这块在Chrome55下正常生成证书测试没问题的,但是Chrome61下测试提示Subject Alternative Name missing错误:

  The certificate for this site does not contain a Subject Alternative Name extension containing a domain name or IP address.

  所以我们需要生成v3证书,准备openssl.cnf文件(和上面测CA文件放在一起)内容如下:

[v3_req]
subjectAltName = @alt_names

[alt_names]
DNS.1 = rancher.webhook                     # 填写tls.crt详情里面的 DNS 地址
DNS.2 = rancher-webhook.cattle-system.svc   # 填写tls.crt详情里面的 DNS 地址

 3、签发证书

# 生成服务端私钥
openssl genrsa -out new.key 2048

 

# 生成证书请求文件
openssl req -new -key new.key -out new.csr

 

 

# 生成最终证书文件,-day指定证书有效期 3650 是十年
openssl x509 -req -days 3650 -sha256 -CA ca.crt -CAkey ca.key -CAcreateserial -extfile openssl.cnf -extensions v3_req -in new.csr -out new.crt

 

 

 

得到 new.key  new.crt两个文件,将两个证书导入到 cattle-webhook-tls 最后点击保存

 

 

 

 最后我们可以通过API查看,看到我们现在证书有效期

 

 

 

posted @ 2021-11-19 10:51  Traktorea  阅读(1771)  评论(0编辑  收藏  举报