Harbor配置https认证

                                Harbor配置https认证
由于Harbor不附带任何证书,它默认使用HTTP来提供注册表请求。但是,强烈建议为任何生产环境启用安全性。
因为测试使用,使用自签名证书:

1、创建CA证书

首先创建个目录存放

mkdir /root/ca -p
cd /root/ca
以下命令创建CA证书
openssl req  -newkey rsa:4096 -nodes -sha256 -keyout ca.key -x509 -days 365 -out ca.crt

其中:(req:申请证书签署请求;-newkey 新密钥 ;-x509:可以用来显示证书的内容,转换其格式,给CSR签名等X.509证书的管理工作,这里用来自签名。)
一路回车出现Common Name 输入IP或域名
Common Name (eg, your name or your server's hostname) []:47.52.25.8

2、生成证书签名请求

openssl req  -newkey rsa:4096 -nodes -sha256 -keyout 47.52.25.80.key -out 47.52.25.80.csr
一路回车出现Common Name 输入IP或域名
Common Name (eg, your name or your server's hostname) []:47.52.25.8

3、生成证书

备注:若需要添加多个地址(允许链接的ip等)

echo subjectAltName = IP:47.52.25.8 > extfile.cnf
openssl x509 -req -days 365 -in 47.52.25.80.csr -CA ca.crt -CAkey ca.key -CAcreateserial -extfile extfile.cnf -out 47.52.25.80.crt

4、配置harbor.cfg

  #set hostname
  hostname = xxxx     #域名或ip
  #set ui_url_protocol
  uiurlprotocol = https    #这里改为https****
  ......
  #The path of cert and key files for nginx, they are applied only the protocol is set to https
  ssl_cert = /cert/47.52.25.8.crt     #crt位置
  ssl_cert_key = /cert/47.52.25.8.key  #key的位置

5、配置启动harbor

    # docker-compose down
    # ./prepare
    #  docker-compose up –d

6、测试

1、访问,https://配置的ip或域名(若nginx的443配置了其他端口需要加上对应端口号)
2、# docker login xxxx

若报错x509: certificate signed by unknown authority:

需要把之前制作的ca证书添加到信任(因为是自签名证书):

# mkdir –p /etc/docker/certs.d/47.52.25.8
# cp ca.crt /etc/docker/certs.d/47.52.25.8/ca.crt
# systemc   restart docker.service

注意:
每一个客户端都需要复制上面的ca.crt到Docker相应目录,然后重启Docker。

再次测试docker login xxxx,成功登陆~
浏览器需要添加“访问例外”,根据提示进行操作。

猜你喜欢

转载自www.cnblogs.com/Dev0ps/p/10566398.html
今日推荐