Docker-registry v2使用tls和nginx身份验证错误后的基本身份验证

时间:2016-09-22 10:36:52

标签: nginx ubuntu-14.04 docker-compose bcrypt docker-registry

简短:我无法使用my.domain.ch名称从外部(运行MAC的本地计算机)登录我的docker-registry(在服务器中心托管在ubuntu-vm(14.04LTS)上)。

可以从运行注册表的ubuntu-machine(vm-2)成功登录'docker login http://localhost:5000'

这是我的设置:

vm-1:Ubuntu 14.04上的nginx / 1.10.1作为反向代理(此处未安装docker):

upstream registry {
    server vm-2:5000 fail_timeout=5s;
}

server {
 listen 80;
 server_name my.domain.ch; # server_name ;
 return 301 https://$host$request_uri;
}

server {
 listen 443 ssl;
 server_name my.domain.ch; # server_name ;

 charset utf-8;
 keepalive_timeout 5;
 add_header Docker-Distribution-Api-Version registry/2.0 always;
 ssl_certificate         /etc/nginx/ssl/cert.pem;
 ssl_certificate_key     /etc/nginx/ssl/key.pem;

 ssl_ecdh_curve          secp521r1;

 ssl_protocols           TLSv1.1 TLSv1.2;
 ssl_prefer_server_ciphers       on;
 ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCMSHA384:ECDHE-ECDSA-AES256-SHA384:EC$

 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
 proxy_set_header Host $http_host;
 proxy_set_header X-Original-URI $request_uri;
 proxy_set_header Docker-Distribution-Api-Version registry/2.0;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_read_timeout 900;

 location / {
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/htpasswd;
    proxy_pass https://registry;
 }
}

vm-2 docker-registry在Ubuntu 14.04上充当注册机构主机。

Docker version 1.12.1, build 23cf638

docker-compose version 1.7.0, build 0d7bf73

docker-registry version 2.5.1

这些是

  • / opt / docker-registry / auth(htaccess)
  • / opt / docker-registry / certs(密钥和证书)
  • / opt / docker-registry / data(empty)
  • /opt/docker-registry/docker-compose.yml

docker-compose.yml看起来像这样:

registry:
  restart: always
  image: registry:2
  ports:
   - 5000:5000
 environment:
    REGISTRY_HTTP_TLS_CERTIFICATE: /certs/cert.pem
    REGISTRY_HTTP_TLS_KEY: /certs/key.pem
    REGISTRY_AUTH: "htpasswd"
    REGISTRY_AUTH_HTPASSWD_REALM: basic-realm
    REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
    REGISTRY_LOG_LEVEL: "debug"
 volumes:
   - /opt/docker_registry/data:/var/lib/registry
   - /opt/docker_registry/certs:/certs
   - /opt/docker_registry/auth:/auth

从我的MAC我尝试

docker login https://my.domain.ch
Username: MyUserName
Password:
Error response from daemon: login attempt to https://my.domain.ch/v2/ failed with status: 401 Unauthorized

我的研究告诉我:

David Daeschler写道,docker只支持使用bcrypt的基本身份验证。 (我试过用apache-md5,md5和crypt都没用)。所以我按照建议使用bcrypt作为我的htacces。

我的docker-registry日志:

registry_1  | time="2016-09-22T10:01:00.809076941Z" level=debug msg="authorizing request" go.version=go1.6.3 http.request.host=mydomain.ch http.request.id=f1b0ccda-2d03-4480-aaf8-b7248acaed5f http.request.method=GET http.request.remoteaddr=xxx.xxx.xxx.127 http.request.uri="/v2/" http.request.useragent="docker/1.12.1 go/go1.6.3 git-commit/23cf638 kernel/4.4.20-moby os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.1 \\(darwin\\))" instance.id=59b4a38a-307e-446d-9f8a-3618c35bb6bb service=registry version=v2.5.1

registry_1  | time="2016-09-22T10:01:00.811894104Z" level=error msg="error authenticating user \"MyUserName\": authentication failure" go.version=go1.6.3 http.request.host=my.domain.ch http.request.id=f1b0ccda-2d03-4480-aaf8-b7248acaed5f http.request.method=GET http.request.remoteaddr=xxx.xxx.xxx.127 http.request.uri="/v2/" http.request.useragent="docker/1.12.1 go/go1.6.3 git-commit/23cf638 kernel/4.4.20-moby os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.1 \\(darwin\\))" instance.id=59b4a38a-307e-446d-9f8a-3618c35bb6bb service=registry version=v2.5.1

registry_1  | time="2016-09-22T10:01:00.812631504Z" level=warning msg="error authorizing context: basic authentication challenge for realm \"basic-realm\": authentication failure" go.version=go1.6.3 http.request.host=my.domain.ch http.request.id=f1b0ccda-2d03-4480-aaf8-b7248acaed5f http.request.method=GET http.request.remoteaddr=83.xxx.xxx.127 http.request.uri="/v2/" http.request.useragent="docker/1.12.1 go/go1.6.3 git-commit/23cf638 kernel/4.4.20-moby os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.1 \\(darwin\\))" instance.id=59b4a38a-307e-446d-9f8a-3618c35bb6bb service=registry version=v2.5.1

registry_1  | xxx.xxx.xxx.11 - - [22/Sep/2016:10:01:00 +0000] "GET /v2/ HTTP/1.0" 401 87 "" "docker/1.12.1 go/go1.6.3 git-commit/23cf638 kernel/4.4.20-moby os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.1 \\(darwin\\))"

nginx-log:

2016/09/22 09:14:34 [crit] 13318#0: *8 crypt_r() failed (22: Invalid argument), client: xxx.xxx.xxx.127, server: my.domain.ch, request: "GET /v2/ HTTP/1.1", host: "my.domain.ch"

此错误的原因由此答案from a Docker.com guy涵盖。 (简而言之:向下搜索显示这取决于debian附带的gcc版本。)

我从日志中得到的信息&错误是:

  • 已正确转发请求
  • 端口已打开并接受请求
  • TLS工作&证书是正确的 - 它使用api的v2
  • 必须与htaccess
  • 有关
  • 一定是nginx的问题。因此,本地工作

如何让nginx了解bcrypt? 或者是其他地方的错误?

感谢您的帮助 SWiggels

修改

来自docker.com的人

Found this

I'm not sure if this will help, but we've become tired of dealing with nginx's edge cases for new users, so registry 2.1 will come with htpasswd based basic auth support.

使用docker-registry v2.5.1时,基本身份验证应该可以正常工作。

我在 vm-1 上安装了sudo apt-get install apache2-utils。我以为它可能带来bcrypt。它没用。

明确安装bcrypt(sudo apt-get install bcrypt)后,我得到bcrypt is already the newest version.

按照建议here添加sudo apt-get install libgmp3-dev也无效。

正如所描述的here auth_basic(通常是nginx?或基本身份验证?)不支持bcrypt。但是对于htaccess密码,docker-registry允许的唯一加密是bcrypt。

看到read here nginx无法处理bcrypt密码哈希值。

在nginx 1.10.1后面有一个docker-registry v2.5.1是不可能的吗?

1 个答案:

答案 0 :(得分:0)

我仍然没有暗示如何解决我的问题。因此我得到了一个解决方法:我配置防火墙将端口直接转发到运行注册表的机器。所以我可以使用域名从外部连接到我的注册表。

如果有人知道如何使用nginx运行它,我会很感激答案。