Harbor 是一款開源的 Container Registry 解決方案,支援代理映像檔倉庫功能,並結合映像檔案掃描工具於抓取後進行第三方函式庫的弱點掃描。這邊就先由安裝 harbor 開始介紹起,然後設定代理鏡像倉庫,最後再來測試第三方函式庫弱點掃描功能。
參考資料 : Harbor Installation and Configuration。安裝檔案位於官方 github 頁面,請下載 offline 檔案 goharbor/harbor v2.5.1。步驟如下 :
wget https://github.com/goharbor/harbor/releases/download/v2.7.0/harbor-offline-installer-v2.7.0.tgz ;
tar xvf harbor-offline-installer-v2.7.0.tgz ;
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt ;
cd harbor ;
cp harbor.yml.tmpl harbor.yml ;
# Configuration file of Harbor
# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: ithome
# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 80
# https related config
https:
# https port for harbor, default is 443
port: 443
# The path of cert and key files for nginx
certificate: /etc/ssl/certs/nginx-selfsigned.crt
private_key: /etc/ssl/private/nginx-selfsigned.key
./prepare --with-trivy
sudo find common/ -type f -exec chmod 0755 \{\} \;
#背景執行
docker compose up -d ;
連入 port 80,帳號 admin,預設密碼 Harbor12345。
先把語系切換成英文,待會比較好比對。
接著要新增一個遠端倉庫遠端連到 dockerhub,參考設定 Creating Replication Endpoints,步驟是先到從[Administrator]->[Registers]中新增一個[ENDPOINT],記得務必把 Provider 切換成你要的對象 (重要!!!!!!!!!)。Provider 選擇 [Docker Hub] -> 輸入自己的帳號、密碼 -> [Test Connection] -> OK。
接著設定一個本地倉庫使用這個遠端倉庫,步驟參考 How to use Harbor Registry to Eliminate Docker Hub Rate Limits、Configure Proxy Cache。步驟是 [Projects] -> [New PROJECT] -> Project Name 填入 [docker-hub] -> Access Level 針對 Public 打勾 -> [Proxy Cache] 選擇 [docker_hub],按下 [確定]。
透過 harbor 拉取鏡像倉庫
docker pull localhost/docker-hub/ubuntu ; #先試拉一個 image 看看
docker pull localhost/docker-hub/aeifkz/ithome_ctf:v1.0 ;
# 顯示抓取的鏡像檔案
docker images ;
# 等待harbor 進行掃描。
# 刪除鏡像檔案
docker rmi localhost/docker-hub/aeifkz/ithome_ctf:v1.0 ;
# 再次抓取會失敗
docker pull localhost/docker-hub/aeifkz/ithome_ctf:v1.0 ;