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&amp;client_id=docker&amp;offline_token=true&amp;service=harbor-registry HTTP/1.1" 301 # 這裡被 nginx 導回 https
- TLSv1.2 harbor-hostname "GET /service/token?account=a0000778&amp;client_id=docker&amp;offline_token=true&amp;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

,

Related posts

apt 套件優先、禁用設定 (Pin)

設定檔位於 /etc/apt/preferences.d/

以下示範

Package: *
Pin: release a=stable,n=bionic
Pin-Priority: -1

表示:

Package: * 表示所有套件,也可以指定套件名稱或 glob 表示法Pin: release a=stable,n=bionic 表示僅限釋出在 stable...

容器內升級 Debian 11 後 SSH 登入變慢

於記錄 /var/log/auth.log 裡找到類似以下記錄的場合:

Failed to activate service 'org.freedesktop.login1': timed out (service_start_timeout=25000ms)

是因為 systemd-logind 無法啟動所致,可以將該服務從驗證流程中移除來解決

systemctl mask systemd-logind
pam-auth-update...

systemd-resolved 導致 docker 無法取得 DNS

解法

cd /etc
sed 's/#DNSStubListener=yes/DNSStubListener=no/' ./systemd/resolved.conf
systemctl restart systemd-resolved
rm resolv.conf
ln -s ../run/systemd/resolve/resolv.conf resolv.conf

原因分析

systemd-resolved 將 /etc/resolv.conf 改為本機地址 127.0.0.53,通過本機...

Leave a Comment

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *