From c58a87c7d3a0999cba78857534fa330dd25d531b Mon Sep 17 00:00:00 2001 From: noodlefighter Date: Sat, 30 Jan 2021 23:56:27 +0800 Subject: [PATCH 1/3] Add environments PUID/PGID of `/var/lib/dav` folder. --- 2.4/Dockerfile | 6 ------ 2.4/docker-entrypoint.sh | 14 +++++++++++++- README.md | 5 +++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/2.4/Dockerfile b/2.4/Dockerfile index 6083e29..55bc0d5 100644 --- a/2.4/Dockerfile +++ b/2.4/Dockerfile @@ -13,7 +13,6 @@ RUN set -ex; \ # Create directories for Dav data and lock database. mkdir -p "/var/lib/dav/data"; \ touch "/var/lib/dav/DavLock"; \ - chown -R www-data:www-data "/var/lib/dav"; \ \ # Enable DAV modules. for i in dav dav_fs; do \ @@ -30,11 +29,6 @@ RUN set -ex; \ sed -i -e "/^#LoadModule ${i}_module.*/s/^#//" "conf/httpd.conf"; \ done; \ \ - # Run httpd as "www-data" (instead of "daemon"). - for i in User Group; do \ - sed -i -e "s|^$i .*|$i www-data|" "conf/httpd.conf"; \ - done; \ - \ # Include enabled configs and sites. printf '%s\n' "Include conf/conf-enabled/*.conf" \ >> "conf/httpd.conf"; \ diff --git a/2.4/docker-entrypoint.sh b/2.4/docker-entrypoint.sh index 3ee4575..b8ad3d7 100755 --- a/2.4/docker-entrypoint.sh +++ b/2.4/docker-entrypoint.sh @@ -10,9 +10,13 @@ set -e # PASSWORD # ANONYMOUS_METHODS # SSL_CERT +# PUID +# PGID # Just in case this environment variable has gone missing. HTTPD_PREFIX="${HTTPD_PREFIX:-/usr/local/apache2}" +PUID=${PUID:-1000} +PGID=${PGID:-1000} # Configure vhosts. if [ "x$SERVER_NAMES" != "x" ]; then @@ -98,9 +102,17 @@ if [ -e /privkey.pem ] && [ -e /cert.pem ]; then "$HTTPD_PREFIX/conf/sites-enabled" fi +# add PUID:PGID, ignore error +addgroup -g $PGID -S user-group 1>/dev/null || true +adduser -u $PUID -S user 1>/dev/null || true + +# Run httpd as PUID:PGID +sed -i -e "s|^User .*|User #$PUID|" "$HTTPD_PREFIX/conf/httpd.conf"; +sed -i -e "s|^Group .*|Group #$PGID|" "$HTTPD_PREFIX/conf/httpd.conf"; + # Create directories for Dav data and lock database. [ ! -d "/var/lib/dav/data" ] && mkdir -p "/var/lib/dav/data" [ ! -e "/var/lib/dav/DavLock" ] && touch "/var/lib/dav/DavLock" -chown -R www-data:www-data "/var/lib/dav" +chown -R $PUID:$PGID "/var/lib/dav" exec "$@" diff --git a/README.md b/README.md index f9b9e8e..89e86cc 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ services: AUTH_TYPE: Digest USERNAME: alice PASSWORD: secret1234 + PUID: 1000 + GUID: 1000 volumes: - /srv/dav:/var/lib/dav @@ -104,4 +106,7 @@ All environment variables are optional. You probably want to at least specify `U * **`PASSWORD`**: Authenticate with this password (and the username above). This is ignored if you bind mount your own authentication file to `/user.passwd`. * **`ANONYMOUS_METHODS`**: Comma-separated list of HTTP request methods (eg, `GET,POST,OPTIONS,PROPFIND`). Clients can use any method you specify here without authentication. Set to `ALL` to disable authentication. The default is to disallow any anonymous access. * **`SSL_CERT`**: Set to `selfsigned` to generate a self-signed certificate and enable Apache's SSL module. If you specify `SERVER_NAMES`, the first domain is set as the Common Name. +* **`PUID`**: file owner's UID of `/var/lib/dav` +* **`PGID`**: file owner's GID of `/var/lib/dav` + From 90b57d8ca4ac8389ec3db004c6ba5c5e6c260851 Mon Sep 17 00:00:00 2001 From: noodlefighter Date: Sat, 3 Apr 2021 23:53:35 +0800 Subject: [PATCH 2/3] do not change the owner of /var/lib/dav --- 2.4/docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.4/docker-entrypoint.sh b/2.4/docker-entrypoint.sh index b8ad3d7..d1788d5 100755 --- a/2.4/docker-entrypoint.sh +++ b/2.4/docker-entrypoint.sh @@ -113,6 +113,6 @@ sed -i -e "s|^Group .*|Group #$PGID|" "$HTTPD_PREFIX/conf/httpd.conf"; # Create directories for Dav data and lock database. [ ! -d "/var/lib/dav/data" ] && mkdir -p "/var/lib/dav/data" [ ! -e "/var/lib/dav/DavLock" ] && touch "/var/lib/dav/DavLock" -chown -R $PUID:$PGID "/var/lib/dav" +chown $PUID:$PGID "/var/lib/dav/DavLock" exec "$@" From be0c394ce45960980221f4e775afa0a1af80d1fd Mon Sep 17 00:00:00 2001 From: mgutt Date: Mon, 12 Jul 2021 14:09:25 +0200 Subject: [PATCH 3/3] Update docker-entrypoint.sh This allows the user to set the default umask / chmod of files, which are uploaded through an WebDAV client --- 2.4/docker-entrypoint.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/2.4/docker-entrypoint.sh b/2.4/docker-entrypoint.sh index d1788d5..6713f7a 100755 --- a/2.4/docker-entrypoint.sh +++ b/2.4/docker-entrypoint.sh @@ -12,6 +12,7 @@ set -e # SSL_CERT # PUID # PGID +# PUMASK # Just in case this environment variable has gone missing. HTTPD_PREFIX="${HTTPD_PREFIX:-/usr/local/apache2}" @@ -115,4 +116,9 @@ sed -i -e "s|^Group .*|Group #$PGID|" "$HTTPD_PREFIX/conf/httpd.conf"; [ ! -e "/var/lib/dav/DavLock" ] && touch "/var/lib/dav/DavLock" chown $PUID:$PGID "/var/lib/dav/DavLock" +# Set umask +if [ "x$PUMASK" != "x" ]; then + umask $PUMASK +fi + exec "$@"