Caddy2 + webdav plugin

1. Caddy version (caddy version):

v2.2.0-rc.1.0.20200915183741-309c1fec622c h1:uqTphfl/ofkjPHmpoc31bVBxQ7GecYOTI6gXkQI+8eI=

2. How I run Caddy:

a. System environment:

linux/amd64 (ArchLinux)

$ uname -a
Linux theodore 5.8.8-arch1-1 #1 SMP PREEMPT Wed, 09 Sep 2020 18:59:45 +0000 x86_64 GNU/Linux
$ systemctl --version
systemd 246 (246.4-1-arch)
+PAM +AUDIT -SELINUX -IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +ZSTD +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid

b. Command:

xcaddy build master --with github.com/mholt/caddy-webdav
sudo setcap cap_net_bind_service=+ep caddy
./caddy run --config /etc/caddy/Caddyfile

c. Service/unit/compose file:

(not applicable)

d. My complete Caddyfile or JSON config:

$ cat /etc/caddy/Caddyfile
{
	order webdav last
}

localhost {
        rewrite /dav /dav/
        webdav /dav/* {
                root /srv/http/dav/
                prefix /dav
        }

        root * /srv/http
        file_server

}

3. The problem I’m having:

PROPFIND /dav returns a 404 (see 4. below for full output of curl)

The server contents are:

/srv/http $ ls -R
.:
dav  index.html

./dav:
test.txt

/srv/http $ cat dav/test.txt
"Hello world! I'm a textfile in dav."

4. Error messages and/or full log output:

Caddy messages

$ ./caddy run --config /etc/caddy/Caddyfile
2020/09/16 18:31:46.101	INFO	using provided configuration	{"config_file": "/etc/caddy/Caddyfile", "config_adapter": ""}
2020/09/16 18:31:46.102	INFO	admin	admin endpoint started	{"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["localhost:2019", "[::1]:2019", "127.0.0.1:2019"]}
2020/09/16 18:31:46.102	INFO	http	server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS	{"server_name": "srv0", "https_port": 443}
2020/09/16 18:31:46.102	INFO	http	enabling automatic HTTP->HTTPS redirects	{"server_name": "srv0"}
2020/09/16 18:31:46.102	INFO	tls.cache.maintenance	started background certificate maintenance	{"cache": "0xc00042d260"}
2020/09/16 18:31:46.108	INFO	tls	setting internal issuer for automation policy that has only internal subjects but no issuer configured	{"subjects": ["localhost"]}
2020/09/16 18:31:46.109	INFO	http	enabling automatic TLS certificate management	{"domains": ["localhost"]}
2020/09/16 18:31:46.109	WARN	tls	stapling OCSP	{"error": "no OCSP stapling for [localhost]: no OCSP server specified in certificate"}
2020/09/16 18:31:46.109	INFO	tls	cleaned up storage units
2020/09/16 18:31:46.142	INFO	pki.ca.local	root certificate is already trusted by system	{"path": "storage:pki/authorities/local/root.crt"}
2020/09/16 18:31:46.142	INFO	autosaved config	{"file": "/home/fabian/.config/caddy/autosave.json"}
2020/09/16 18:31:46.142	INFO	serving initial configuration

Curl output:

$ curl -v -H "Depth: 1" -X PROPFIND https://localhost/dav
*   Trying ::1:443...
* Connected to localhost (::1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: [NONE]
*  start date: Sep 16 18:24:52 2020 GMT
*  expire date: Sep 17 06:24:52 2020 GMT
*  subjectAltName: host "localhost" matched cert's "localhost"
*  issuer: CN=Caddy Local Authority - ECC Intermediate
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x55dd0ac2c9f0)
> PROPFIND /dav HTTP/2
> Host: localhost
> user-agent: curl/7.72.0
> accept: */*
> depth: 1
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* Connection state changed (MAX_CONCURRENT_STREAMS == 250)!
< HTTP/2 404
< server: Caddy
< content-length: 0
< date: Wed, 16 Sep 2020 18:34:26 GMT
<
* Connection #0 to host localhost left intact

localhost:2019/config:

{"apps":{"http":{"servers":{"srv0":{"listen":[":443"],"routes":[{"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"vars","root":"/srv/http"}]},{"group":"group0","handle":[{"handler":"rewrite","uri":"/dav/"}],"match":[{"path":["/dav"]}]},{"handle":[{"handler":"file_server","hide":["/etc/caddy/Caddyfile"]}]},{"handle":[{"handler":"webdav","prefix":"/dav","root":"/srv/http/dav/"}],"match":[{"path":["/dav/*"]}]}]}],"match":[{"host":["localhost"]}],"terminal":true}]}}}}}

5. What I already tried:

I successfully tried moving the endpoint one level up, i.e. serving the dav directly at / works, with the following config.

localhost {
        webdav * {
                root /srv/http/dav/
        }
}

I failed to use a route {...} to express my intent to have everything in /dav/ served as WebDAV in Caddyfile.

6. Links to relevant resources:

(none)

This is the problem. If you set it to last, then that’s after file_server, so file_server is sorted to be handled before webdav. Instead, use order webdav before file_server and it should do what you expect.

Alternatively, you can use route like this:

localhost {
	root * /srv/http

	route {
		rewrite /dav /dav/
		webdav /dav/* {
			prefix /dav
		}
		file_server
	}
}
1 Like

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