#431

htpasswd auth standalone (setup help needed)

Openvljukap98opened 1y ago

Login on my private registry/ui works, but push doesn't.

I have setup my docker-compose.yml as such:

services:
  registry-ui:
    image: joxit/docker-registry-ui:latest
    restart: always
    ports:
      - 3000:80
    environment:
      - SINGLE_REGISTRY=true
      - REGISTRY_TITLE=Ein docker registry
      - REGISTRY_URL=https://my.domain.com
      - DELETE_IMAGES=true
      - SHOW_CONTENT_DIGEST=true
      - NGINX_PROXY_PASS_URL=http://registry-server:5000
      - SHOW_CATALOG_NB_TAGS=true
      - CATALOG_MIN_BRANCHES=1
      - CATALOG_MAX_BRANCHES=1
      - TAGLIST_PAGE_SIZE=100
      - REGISTRY_SECURED=true
      - CATALOG_ELEMENTS_LIMIT=1000
      - HISTORY_CUSTOM_LABELS=mylabel
    container_name: registry-ui

  registry-server:
    image: registry:2.7
    restart: always
    environment:
      - REGISTRY_HTTP_HEADERS_X-Content-Type-Options=[nosniff]
      - REGISTRY_HTTP_HEADERS_Access-Control-Allow-Origin=['http://127.0.0.1,http://localhost,http://my.domain.com,https://my.domain.com']
      - REGISTRY_HTTP_HEADERS_Access-Control-Allow-Methods=['HEAD', 'GET', 'OPTIONS', 'DELETE']
      - REGISTRY_HTTP_HEADERS_Access-Control-Allow-Headers=['Authorization']
      - REGISTRY_HTTP_HEADERS_Access-Control-Expose-Headers=['Docker-Content-Digest']
      - REGISTRY_HTTP_HEADERS_Access-Control-Allow-Credentials=['true']
      - REGISTRY_AUTH_HTPASSWD_REALM=basic-realm
      - REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd
      - REGISTRY_STORAGE_DELETE_ENABLED=true
    volumes:
      - /mnt/storage/services-common/docker-registry/data:/var/lib/registry
      - /mnt/storage/services-common/docker-registry/auth:/auth
    container_name: registry-server

Added a user:

htpasswd -Bbn user password > auth/htpasswd

Set up a location for the ui service on my vps nginx:

location /registry/ {
        proxy_pass http://127.0.0.1:3000/;
	include proxy_params;
	proxy_set_header Authorization $http_authorization;
}

Can login succesfully with docker cli:

docker login my.domain.com
Username: user
Password: 

WARNING! Your credentials are stored unencrypted in '/home/myuser/.docker/config.json'.
Configure a credential helper to remove this warning. See
https://docs.docker.com/go/credential-store/

Login Succeeded

Can see the registy ui landing page after credentials input:

But when trying to finally push something, it starts pushing, but gives up in the middle of it and says: unauthorized: authentication required:

docker push my.domain.com/my-image:latest
The push refers to repository [my.domain.com/my-image]
f1c1971e5ab1: Pushing  3.072kB
dfe9f99cf5b8: Pushing   2.56kB
62ed05c6d8e8: Pushing  133.6kB/11.62MB
2eeba623172e: Pushing  133.1kB/11.62MB
a4f46948bea5: Pushing  10.24kB
e1d41bac7d04: Waiting 
11dc284d87fb: Waiting 
418dccb7d85a: Waiting 
unauthorized: authentication required

The volume mount for registry shows some files (if that info is helpful):

Now what else do I have to setup for this to work?

Additional note is that without the auth setup, login/push/pull works like expected without problems.

Activity

1
galagithub8mo ago

Going out on a whim here, but can you try with modifying allowed headers to this:

- REGISTRY_HTTP_HEADERS_Access-Control-Allow-Headers=['Authorization','Accept','Cache-Control']

That is, add Accept and Cache-Control to allowed headers, maybe it works, I don't know much about this subject.