docker login 無法登入經過 SSL 終結的 Harbor
原因分析
場景
- 外部 <-https-> Nginx <-http-> Harbor
- nginx 設定將 http 導向 https
- Harbor v2
分析
執行時 docker login 向 Harbor 發送 HTTP Request
# Request
GET https://harbor-hostname/v2/
# Response
401
Www-Authenticate: Bearer realm="http://harbor-hostname/service/token",service="harbor-registry"
realm 欄位將驗證請求導向 http,nginx 將連線導回 https,導回時丟失驗證資訊導致驗證失敗
- TLSv1.2 harbor-hostname "GET /v2/ HTTP/1.1" 401 # realm 導向 http
username - harbor-hostname "GET /service/token?account=a0000778&client_id=docker&offline_token=true&service=harbor-registry HTTP/1.1" 301 # 這裡被 nginx 導回 https
- TLSv1.2 harbor-hostname "GET /service/token?account=a0000778&client_id=docker&offline_token=true&service=harbor-registry HTTP/1.1" 401 # 丟失驗證資訊 (username),驗證失敗
解法
編輯 /horbor.yml ,解除設定項 external_url 的註解並填上對外 https 網址
# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
external_url: https://harbor-hostname/
未完成安裝 (即沒執行過 ./install.sh ) 的情況下繼續安裝即可,
否則在 Harbor 資料夾下依序執行以下指令
docker-compose down # 停止 harbor
./prepare # 重新生成容器設定檔
docker-compose up -d # 啟動 harbor
Leave a Comment