san ssl 证书docker 私有仓库搭建
san ssl 证书docker 私有仓库搭建问题分析实现问题Get “https://kanq.test/v2/”: x509: certificate relies on legacy Common Name field, use SANs or temporarily enable Common Name matching with GODEBUG=x509ignoreCN=0分析由于doc
问题
Get “https://kanq.test/v2/”: x509: certificate relies on legacy Common Name field, use SANs or temporarily enable Common Name matching with GODEBUG=x509ignoreCN=0
分析
由于docker 版本20.10.8 版本编译使用的go 版本过高(>1.15.1)。是因为 go 1.15 版本开始废弃 CommonName
需要使用SAN证书
实现
cp /etc/pki/tls/openssl.cnf /tmp/docker/
修改 操作目录的openssl.cnf
vi /tmp/docker/openssl.cnf
修改如下 (去掉144 行的# 添加 145 146 行 146 可以写多个域名 )
144 req_extensions = v3_req # The extensions to add to a certificate request
145 [ alt_names ]
146 DNS.1 = kanq.test
生成默认 ca
openssl genrsa -out ca.key 2048
openssl req -x509 -new -nodes -key ca.key -subj “/CN=example.ca.com” -days 5000 -out ca.crt
生成证书请求
openssl req -new -sha256
-key ca.key
-subj “/C=CN/ST=Beijing/L=Beijing/O=UnitedStack/OU=Devops/CN=kang.test”
-reqexts SAN
-config <(cat ./openssl.cnf
<(printf “[SAN]\nsubjectAltName=DNS:kang.test”))
-out kanq.csr
生成证书
openssl x509 -req -days 365000
-in kanq.csr -CA ca.crt -CAkey ca.key -CAcreateserial
-extfile <(printf “subjectAltName=DNS:kanq.test”)
-out kanq.crt
启动 私有仓库
docker run
> --restart=always \
> --name registry \
> -v /tmp/docker/certs:/certs \
> -e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
> -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/kanq.crt \
> -e REGISTRY_HTTP_TLS_KEY=/certs/ca.key\
> -p 443:443 \
> -v /opt/registry:/var/lib/registry \
> registry:latest
配置域名解析
echo “x.x.x.x kanq.test” >>/etc/hosts
配置本地免密码登录
mkdir -p /etc/docker/certs.d/kanq.test/
cp /tmp/docker/kanq.crt /etc/docker/certs.d/kanq.test/
更多推荐
所有评论(0)