Caddy file-server: 401 Unauthorized

1. Caddy version (caddy version):

$ docker images caddy
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
caddy        latest    06e3eab0f95d   4 weeks ago   39.2MB
$ docker run --rm -it --name caddy-test caddy:latest /bin/sh
/srv # caddy version
v2.2.1 h1:Q62GWHMtztnvyRU+KPOpw6fNfeCD3SkwH7SfT1Tgt2c=

2. How I run Caddy:

a. System environment:

  • Debian bullseye/sid

  • docker:

$ docker --version
Docker version 20.10.1+dfsg1, build 831ebea

b. Command:

docker run -d --restart unless-stopped \
        -p 80:80 -p 443:443 \
        -v /var/lib/yocto:/srv \
        --name yocto-file-srv caddy:latest \
        caddy file-server --browse --listen :80

Note: 443 is not used so, file server runs locally with http instead of https.

c. Service/unit/compose file:

Check above command.

d. My complete Caddyfile or JSON config:

Not used.

3. The problem I’m having:

Server returns HTTP/1.1 401 Unauthorized but no login should be required as it is not configured. Also, in a second attempt, the server returns HTTP/1.1 200 OK which is what is expected in the fist try.

Full client response:

--2021-01-18 20:54:43--  http://yocto.qtec.com/gallium/sstate-cache/96/df/sstate%3Atzdata%3A%3A2020d%3Ar0%3A%3A3%3A96dfdcc39a165f356cadb82ece570b4eca3fe1ff447aa682176dbe6245f4f4b9_populate_lic.tgz.siginfo                                                                                                                  
Resolving yocto.qtec.com (yocto.qtec.com)... 192.168.2.103
Connecting to yocto.qtec.com (yocto.qtec.com)|192.168.2.103|:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 401 Unauthorized
  Date: Mon, 18 Jan 2021 20:54:58 GMT
  Server: Apache/2.4.38 (Debian)
  WWW-Authenticate: Basic realm="Qtecnology"
  Content-Length: 461
  Keep-Alive: timeout=5, max=100
  Connection: Keep-Alive
  Content-Type: text/html; charset=iso-8859-1

Username/Password Authentication Failed.

Note: yocto.qtec.com points to my local server where the caddy file server (port 80) is running.

Client fetch command:

export PSEUDO_DISABLED=1; unset _PYTHON_SYSCONFIGDATA_NAME; export SSH_AUTH_SOCK="/ssh-agent"; export PATH="/workdir/build/tmp/sysroots-uninative/x86_64-linux/usr/bin:/workdir/repo/poky/scripts:/workdir/build/tmp/work/all-poky-linux/tzdata/2020d-r0/recipe-sysroot-native/usr/bin/allarch-poky-linux:/workdir/build/tmp/work/all-poky-linux/tzdata/2020d-r0/recipe-sysroot/usr/bin/crossscripts:/workdir/build/tmp/work/all-poky-linux/tzdata/2020d-r0/recipe-sysroot-native/usr/sbin:/workdir/build/tmp/work/all-poky-linux/tzdata/2020d-r0/recipe-sysroot-native/usr/bin:/workdir/build/tmp/work/all-poky-linux/tzdata/2020d-r0/recipe-sysroot-native/sbin:/workdir/build/tmp/work/all-poky-linux/tzdata/2020d-r0/recipe-sysroot-native/bin:/workdir/repo/poky/bitbake/bin:/workdir/build/tmp/hosttools"; export HOME="/home/pokyuser"; /usr/bin/env wget -t 2 -T 30 --passive-ftp --no-check-certificate --server-response -O /workdir/build/sstate-cache/96/df/sstate:tzdata::2020d:r0::3:96dfdcc39a165f356cadb82ece570b4eca3fe1ff447aa682176dbe6245f4f4b9_populate_lic.tgz.siginfo -P /workdir/build/sstate-cache 'http://yocto.qtec.com/gallium/sstate-cache/96/df/sstate%3Atzdata%3A%3A2020d%3Ar0%3A%3A3%3A96dfdcc39a165f356cadb82ece570b4eca3fe1ff447aa682176dbe6245f4f4b9_populate_lic.tgz.siginfo' --progress=dot -v

Re-executing the fetch (wget) command succeeds:

--2021-01-18 21:25:24--  http://yocto.qtec.com/gallium/sstate-cache/96/df/sstate%3Atzdata%3A%3A2020d%3Ar0%3A%3A3%3A96dfdcc39a165f356cadb82ece570b4eca3fe1ff447aa682176dbe6245f4f4b9_populate_lic.tgz.siginfo                                                                                                                  
Resolving yocto.qtec.com (yocto.qtec.com)... 192.168.2.107
Connecting to yocto.qtec.com (yocto.qtec.com)|192.168.2.107|:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 200 OK
  Accept-Ranges: bytes
  Content-Length: 34658
  Etag: "qn4zv6qqq"
  Last-Modified: Mon, 18 Jan 2021 15:47:30 GMT
  Server: Caddy
  Date: Mon, 18 Jan 2021 21:25:24 GMT
Length: 34658 (34K)
Saving to: ‘/workdir/build/sstate-cache/96/df/sstate:tzdata::2020d:r0::3:96dfdcc39a165f356cadb82ece570b4eca3fe1ff447aa682176dbe6245f4f4b9_populate_lic.tgz.siginfo’                                                                                                                                                           

     0K .......... .......... .......... ...                  100% 81.8M=0s

2021-01-18 21:25:24 (81.8 MB/s) - ‘/workdir/build/sstate-cache/96/df/sstate:tzdata::2020d:r0::3:96dfdcc39a165f356cadb82ece570b4eca3fe1ff447aa682176dbe6245f4f4b9_populate_lic.tgz.siginfo’ saved [34658/34658] 

Full log (for the case: libunwind):

DEBUG: Executing python function do_populate_lic_setscene                                                                                                                                                                                                                                                                      
DEBUG: Searching for a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz in paths:                                                                                                                                                                           
    /workdir/build/sstate-cache                                                                                                                                                                                                                                                                                                
DEBUG: Defaulting to /workdir/build/sstate-cache/a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz for a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz                               
DEBUG: Testing URL file://a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz;downloadfilename=a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz                                         
DEBUG: For url ['file', '', 'a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz', '', '', OrderedDict([('downloadfilename', 'a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz')])] comp
aring ['file', '', '.*', '', '', OrderedDict()] to ['http', 'yocto.qtec.com', '/gallium/sstate-cache/PATH', '', '', OrderedDict()]                                                                                                                                                                                             
DEBUG: For url file://a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz;downloadfilename=a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz returning http://yocto.qtec.com/gallium/ssta
te-cache/a1/f1/sstate%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz;downloadfilename=a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz                                            
DEBUG: Trying PREMIRRORS                                                                                                                                                                                                                                                                                                       
DEBUG: For url ['file', '', 'a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz', '', '', OrderedDict([('downloadfilename', 'a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz')])] comp
aring ['file', '', '.*', '', '', OrderedDict()] to ['http', 'yocto.qtec.com', '/gallium/sstate-cache/PATH', '', '', OrderedDict()]                                                                                                                                                                                             
DEBUG: For url file://a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz;downloadfilename=a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz returning http://yocto.qtec.com/gallium/ssta
te-cache/a1/f1/sstate%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz;downloadfilename=a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz                                            
DEBUG: Fetching http://yocto.qtec.com/gallium/sstate-cache/a1/f1/sstate%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz;downloadfilename=a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_l
ic.tgz using command '/usr/bin/env wget -t 2 -T 30 --passive-ftp --no-check-certificate -O /workdir/build/sstate-cache/a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz -P /workdir/build/sstate-cache 'http://yocto.qtec.com/gallium/sstate-cache/a1/f1/s
state%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz''                                                                                                                                                                                                 
DEBUG: Fetcher accessed the network with the command /usr/bin/env wget -t 2 -T 30 --passive-ftp --no-check-certificate -O /workdir/build/sstate-cache/a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz -P /workdir/build/sstate-cache 'http://yocto.qtec.c
om/gallium/sstate-cache/a1/f1/sstate%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz'                                                                                                                                                                   
DEBUG: Running export PSEUDO_DISABLED=1; unset _PYTHON_SYSCONFIGDATA_NAME; export SSH_AUTH_SOCK="/ssh-agent"; export PATH="/workdir/build/tmp/sysroots-uninative/x86_64-linux/usr/bin:/workdir/repo/poky/scripts:/workdir/build/tmp/work/bobcat-poky-linux/libunwind/1.3.1-r0/recipe-sysroot-native/usr/bin/x86_64-poky-linux:/
workdir/build/tmp/work/bobcat-poky-linux/libunwind/1.3.1-r0/recipe-sysroot/usr/bin/crossscripts:/workdir/build/tmp/work/bobcat-poky-linux/libunwind/1.3.1-r0/recipe-sysroot-native/usr/sbin:/workdir/build/tmp/work/bobcat-poky-linux/libunwind/1.3.1-r0/recipe-sysroot-native/usr/bin:/workdir/build/tmp/work/bobcat-poky-linu
x/libunwind/1.3.1-r0/recipe-sysroot-native/sbin:/workdir/build/tmp/work/bobcat-poky-linux/libunwind/1.3.1-r0/recipe-sysroot-native/bin:/workdir/repo/poky/bitbake/bin:/workdir/build/tmp/hosttools"; export HOME="/home/pokyuser"; /usr/bin/env wget -t 2 -T 30 --passive-ftp --no-check-certificate -O /workdir/build/sstate-c
ache/a1/f1/sstate:libunwind::1.3.1:r0::3:a1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz -P /workdir/build/sstate-cache 'http://yocto.qtec.com/gallium/sstate-cache/a1/f1/sstate%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz' --progress=dot -v
--2021-01-18 19:43:36--  http://yocto.qtec.com/gallium/sstate-cache/a1/f1/sstate%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz                                                                                                                       
Resolving yocto.qtec.com (yocto.qtec.com)... 192.168.2.103
Connecting to yocto.qtec.com (yocto.qtec.com)|192.168.2.103|:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized

Username/Password Authentication Failed.

4. Error messages and/or full log output:

Server logs (access):

2021/01/18 19:43:36.705 INFO    http.log.access handled request {"request": {"remote_addr": "192.168.2.105:50666", "proto": "HTTP/1.1", "method": "HEAD", "host": "yocto.qtec.com", "uri": "/gallium/sstate-cache/a1/f1/sstate%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz", "headers": {"Accept-Encoding": ["identity"], "Accept": ["*/*"], "User-Agent": ["Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Ubuntu/9.10 (karmic) Firefox/3.6.12"], "Connection": ["close"]}}, "common_log": "192.168.2.105 - - [18/Jan/2021:19:43:36 +0000] \"HEAD /gallium/ss
tate-cache/a1/f1/sstate%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz HTTP/1.1\" 200 0", "duration": 0.000196521, "size": 0, "status": 200, "resp_headers": {"Content-Type": ["application/gzip"], "Last-Modified": ["Mon, 18 Jan 2021 15:47:50 GMT"],
 "Accept-Ranges": ["bytes"], "Content-Length": ["1074"], "Server": ["Caddy"], "Etag": ["\"qn4zvqtu\""]}}         
2021/01/18 19:43:47.194 INFO    http.log.access handled request {"request": {"remote_addr": "192.168.2.105:51230", "proto": "HTTP/1.1", "method": "HEAD", "host": "yocto.qtec.com", "uri": "/gallium/sstate-cache/a1/f1/sstate%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz.siginfo", "headers": {"Connection": ["close"], "Accept-Encoding": ["identity"], "Accept": ["*/*"], "User-Agent": ["Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Ubuntu/9.10 (karmic) Firefox/3.6.12"]}}, "common_log": "192.168.2.105 - - [18/Jan/2021:19:43:47 +0000] \"HEAD /ga
llium/sstate-cache/a1/f1/sstate%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz.siginfo HTTP/1.1\" 200 0", "duration": 0.000212345, "size": 0, "status": 200, "resp_headers": {"Server": ["Caddy"], "Etag": ["\"qn4zvqre7\""], "Content-Type": [], "Last
-Modified": ["Mon, 18 Jan 2021 15:47:50 GMT"], "Accept-Ranges": ["bytes"], "Content-Length": ["35503"]}}    
2021/01/18 19:43:47.214 INFO    http.log.access handled request {"request": {"remote_addr": "192.168.2.105:51232", "proto": "HTTP/1.1", "method": "GET", "host": "yocto.qtec.com", "uri": "/gallium/sstate-cache/a1/f1/sstate%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a
017a_populate_lic.tgz.siginfo", "headers": {"Connection": ["Keep-Alive"], "User-Agent": ["Wget/1.20.1 (linux-gnu)"], "Accept": ["*/*"], "Accept-Encoding": ["identity"]}}, "common_log": "192.168.2.105 - - [18/Jan/2021:19:43:47 +0000] \"GET /gallium/sstate-cache/a1/f1/sstate%3Alibunwind%3A%3A1.3.1%3Ar0%3A%3A3%3Aa1f181ae0a3ac5a891aa88845e7417441c76f8fa488f3281a9484c2fc41a017a_populate_lic.tgz.siginfo HTTP/1.1\" 200 35503", "duration": 0.000363413, "size": 35503, "status": 200, "resp_headers": {"Server": ["Caddy"], "Etag": ["\"qn4zvqre7\""], "Content-Type": [], "Last-Modified": ["Mon, 18 Jan 2021 15:47:50 GMT"], "Accept-Ranges": ["byt
es"], "Content-Length": ["35503"]}}

5. What I already tried:

I’ve tried to use --no-check-certificate (for wget) as my logs shows but it makes no difference.

6. Links to relevant resources:

caddy file-server is used as http server for an sstate-cache directory with yocto project:

I think you’re hitting the wrong server. Caddy wouldn’t respond with Server: Apache!

Looks like your domain is resolving to two different IP addresses at the same time. Make sure that’s all properly configured!

1 Like

Awesome!

I didn’t realize but that’s true. Actually, the DNS resolved with the wrong ip (x.x.x.103) while when the client succeeds is then, the 107.

Thanks and sorry for the noise!

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.