文章目錄
- 配置Harbor鏡像倉庫HTTPS Secure Registry
-
- 前言
- 生成證書
-
- 生成CA憑證
- 生成證書簽名請求(CSR)
- 生成Harbor證書(Harbor hostname為IP)
- CA憑證檔案清單
- 複制證書到指定位置
- 配置Harbor
- 通過浏覽器通路Harbor
- 配置Docker
- 參考文檔
-
配置Harbor鏡像倉庫HTTPS Secure Registry
前言
在之前的文章我們介紹了如何搭建Harbor鏡像倉庫 HTTP Insecure Registry,這篇文章我們再來介紹如何為Harbor鏡像倉庫配置HTTPS。
生成證書
生成CA憑證
openssl req \
-newkey rsa:4096 -nodes -sha256 -keyout ca.key \
-x509 -days 3650 -out ca.crt \
-subj "/C=CN/ST=Guangdong/L=Guangzhou/O=example/OU=example/CN=example"
subj參數說明如下:
字段 | 字段含義 | 示例 |
---|---|---|
/C= | Country 國家 | CN |
/ST= | State or Province 省 | Guangdong |
/L= | Location or City 城市 | Guangzhou |
/O= | Organization 組織或企業 | |
/OU= | Organization Unit 部門 | |
/CN= | Common Name 域名或IP |
生成證書簽名請求(CSR)
openssl req \
-newkey rsa:4096 -nodes -sha256 -keyout harbor.key \
-out harbor.csr \
-subj "/C=CN/ST=Guangdong/L=Guangzhou/O=example/OU=example/CN=example"
生成Harbor證書(Harbor hostname為IP)
建立一個配置檔案來指定IP位址:
vim extfile.cnf
subjectAltName = IP:192.168.37.170
生成Harbor證書:
openssl x509 -req -days 3650 \
-in harbor.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
-extfile extfile.cnf \
-out harbor.crt
CA憑證檔案清單
檔案名 | 說明 |
---|---|
ca.crt | CA憑證公鑰 |
ca.key | CA憑證密鑰(不能公布和洩露) |
harbor.crt | Harbor證書公鑰 |
harbor.key | Harbor證書密鑰(不能公布和洩露) |
複制證書到指定位置
sudo cp *.crt *.key /etc/ssl/certs
配置Harbor
編輯
harbor.cfg
檔案:
ui_url_protocol = https
ssl_cert = /etc/ssl/certs/harbor.crt
ssl_cert_key = /data/cert/harbor.key
重新配置Harbor:
docker-compose down -v
./prepare
docker-compose up -d
通過浏覽器通路Harbor
在浏覽器中打開https://<harbor_hostname>來通路Harbor。
在Firefox浏覽器中可以添加Security Exception來忽略HTTPS錯誤警告。
Chrome浏覽器可以嘗試通過導入CA憑證的方式來忽略HTTPS錯誤警告。
注意:Chrome浏覽器可能有導入CA憑證後仍然無法通路的問題。
配置Docker
如果之前在
/etc/docker/daemon.json
中定義了
insecure-registries
,則需要移除
insecure-registries
,并運作以下指令重新加載和重新開機Docker:
systemctl daemon-reload
systemctl restart docker
嘗試運作
docker login <harbor_hostname>
來通路Harbor,因為未配置證書會遇到"x509 certificate signed by unknown authority"的錯誤。
請參考下面的文章來配置Docker的證書:
- Harbor docker login x509 certificate signed by unknown authority
配置好後,嘗試
docker login
、
docker pull
和
docker push
指令是否工作正常。
除了在Harbor的機器上配置Docker外,其它機器的Docker想要通路Harbor也要參考上面的文章來配置證書。
參考文檔
- https://github.com/goharbor/harbor/blob/master/docs/configure_https.md
- https://blog.inkubate.io/how-to-use-harbor-private-registry-with-kubernetes/
- https://ivanzz1001.github.io/records/post/docker/2018/04/09/docker-harbor-https
- https://www.shellhacks.com/create-csr-openssl-without-prompt-non-interactive/