簡體   English   中英

登錄haproxy后面的私有docker注冊表v2

[英]Logging in to private docker registry v2 behind haproxy

我正在嘗試使用HAProxy建立一個新的Docker Registry(v2)。 對於Docker注冊表我使用docker hub中的映像並使用docker run -d -p 5000:5000 -v /path/to/registry:/tmp/registry registry:2.0.1 這是我的HAProxy配置的一個子集:

global
    chroot /var/lib/haproxy
    user haproxy
    group haproxy
    daemon
    tune.ssl.default-dh-param 2048

userlist auth_list
    group docker_registry users root
    user root password ***PASSWORD***

backend docker-registry
    server 127.0.0.1:5000_localhost 127.0.0.1:5000 cookie 127.0.0.1:5000_localhost 

frontend shared-frontend
    mode http
    bind *:80
    bind *:443 ssl crt *** CERT FILES ***
    option accept-invalid-http-request

    acl domain_d.mydomain.com hdr(host) -i d.mydomain.com
    acl auth_docker_registry_root http_auth(auth_list) root
    redirect scheme https if !{ ssl_fc } domain_d.mydomain.com
    http-request auth realm Registry if !auth_docker_registry_root { ssl_fc } domain_d.mydomain.com
    use_backend docker-registry if domain_d.mydomain.com

需要注意的重要事項是我使用HAProxy進行SSL終止和HTTP身份驗證而不是注冊表。

我嘗試登錄到新注冊表時出現問題。 如果我運行docker login https://d.mydomain.com/v2/然后輸入用戶root和密碼我收到以下錯誤消息:

Docker客戶端:

FATA[0009] Error response from daemon: invalid registry endpoint https://d.mydomain.com/v2/: https://d.mydomain.com/v2/ does not appear to be a v2 registry endpoint. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry d.mydomain.com` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/d.mydomain.com/ca.crt

Docker守護程序:

ERRO[0057] Handler for POST /auth returned error: invalid registry endpoint https://d.mydomain.com/v2/: https://d.mydomain.com/v2/ does not appear to be a v2 registry endpoint. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry d.mydomain.com` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/d.mydomain.com/ca.crt
ERRO[0057] HTTP Error: statusCode=500 invalid registry endpoint https://d.mydomain.com/v2/: https://d.mydomain.com/v2/ does not appear to be a v2 registry endpoint. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry d.mydomain.com` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/d.mydomain.com/ca.crt

所以我嘗試將--insecure-registry d.mydomain.com添加到:

  • /etc/default/docker DOCKER_OPTS= -H unix:///var/run/docker.sock --insecure-registry d.mydomain.com with DOCKER_OPTS= -H unix:///var/run/docker.sock --insecure-registry d.mydomain.com
  • 使用docker -d --insecure-registry d.mydomain.com手動啟動docker -d --insecure-registry d.mydomain.com

這些,或我在網上找到的任何其他工作都沒有。 每次重新啟動docker並嘗試再次登錄后,都會給出相同的錯誤消息。

我嘗試過的其他一些事情:

  • 在瀏覽器中轉到d.mydomain.com會產生404
  • 在瀏覽器中訪問d.mydomain.com/v2/導致: {}
  • 在login命令中用所有這些替換https://d.mydomain.com/v2/但沒有成功
    • http://d.mydomain.com/v2/
    • d.mydomain.com/v2/
    • http://d.mydomain.com/
    • d.mydomain.com/

使用HAProxy執行SSL終止和HTTP身份驗證的此設置過去使用了注冊表的第一個版本和舊版本的docker。 所以Docker注冊表v2中的任何內容都有變化嗎? 這仍然有用嗎? 如果它沒有改變,為什么--insecure-registry標志不再做任何事情了?

另外,我一直在努力讓這個工作一段時間,所以我可能忘記了我嘗試過的所有事情。 如果有可能有用的東西,請告訴我,我會嘗試一下。

謝謝JamesStewy


編輯

此編輯已移至下面的答案

我有它的工作。 所以這是我的新配置:

haproxy.cfg

global
    chroot /var/lib/haproxy
    user haproxy
    group haproxy
    daemon
    tune.ssl.default-dh-param 2048

userlist auth_list
    group docker_registry users root
    user root password ***PASSWORD***

backend docker-registry
    server 127.0.0.1:5000_localhost 127.0.0.1:5000 cookie 127.0.0.1:5000_localhost 

backend docker-registry-auth
    errorfile 503 /path/to/registry_auth.http

frontend shared-frontend
    mode http
    bind *:80
    bind *:443 ssl crt *** CERT FILES ***
    option accept-invalid-http-request

    acl domain_d.mydomain.com hdr(host) -i d.mydomain.com
    redirect scheme https if !{ ssl_fc } domain_d.mydomain.com
    acl auth_docker_registry_root http_auth(auth_list) root
    use_backend docker-registry-auth if !auth_docker_registry_root { ssl_fc } domain_d.mydomain.com
    rsprep ^Location:\ http://(.*) Location:\ https://\1
    use_backend docker-registry if domain_d.mydomain.com

registry_auth.http

HTTP/1.0 401 Unauthorized
Cache-Control: no-cache
Connection: close
Content-Type: text/html
Docker-Distribution-Api-Version: registry/2.0
WWW-Authenticate: Basic realm="Registry"

<html><body><h1>401 Unauthorized</h1>
You need a valid user and password to access this content.
</body></html>

http-request auth行的差異已被use_backend docker-registry-auth取代。 后端docker-registry-auth沒有服務器,它總是會產生503錯誤。 但503錯誤文件已更改為registry_auth.http registry_auth.http ,錯誤代碼被重寫為401 ,標題WWW-Authenticate設置為Basic realm="Registry" ,提供了基本的HAProxy 401錯誤頁面,最重要的是,頭文件Docker-Distribution-Api-Version是設置為registry/2.0

因此,除了現在設置了自定義標頭Docker-Distribution-Api-Version之外,這種hacky解決方法與舊的http-request auth行完全相同。 這允許此設置通過測試,該測試從https://github.com/docker/docker/blob/v1.7.0/registry/endpoint.go的 line 236開始。

所以現在當我運行docker login d.mydomain.com ,登錄成功,我的憑據被添加到.docker/config.json

第二個問題是即使登錄也無法推送到新的存儲庫。這是通過在frontend添加rsprep行來解決的。 這一行的作用是修改Location標頭(如果存在)以將所有http://https://

我還找到了這些文檔供將來參考。

作為對前一個答案的一個小澄清:我不得不改變這一行:

WWW-Authenticate: Basic realm="Registry"

對此:

WWW-Authenticate: Basic realm="Registry realm"

一切順利......

順便說一句,散列傳遞可以使用mkpasswd(whois deb包的一部分)來完成

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM