From 01d80d8ec5bf2e1ca74392ff2cb8bf408a9b86c3 Mon Sep 17 00:00:00 2001 From: "Damien Sironi (The WiW)" Date: Sun, 1 Dec 2024 17:47:49 +0100 Subject: [PATCH] New configuration parameters management using docker environment variables --- Dockerfile | 1 + README.md | 18 ++++++++++++++++++ start_vsftpd.sh | 2 ++ update_conf.sh | 14 ++++++++++++++ 4 files changed, 35 insertions(+) create mode 100755 update_conf.sh diff --git a/Dockerfile b/Dockerfile index 22d55e0..ffd2c69 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,7 @@ COPY --from=pidproxy /usr/bin/pidproxy /usr/bin/pidproxy RUN apk --no-cache add vsftpd tini COPY start_vsftpd.sh /bin/start_vsftpd.sh +COPY update_conf.sh /bin/update_conf.sh COPY vsftpd.conf /etc/vsftpd/vsftpd.conf EXPOSE 21 21000-21010 diff --git a/README.md b/README.md index ea307fd..734886b 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Environment variables: - `ADDRESS` - external address to which clients can connect for passive ports (optional, should resolve to ftp server ip address) - `MIN_PORT` - minimum port number to be used for passive connections (optional, default `21000`) - `MAX_PORT` - maximum port number to be used for passive connections (optional, default `21010`) +- `CONF_` - custom parameter in configuration file, may be UPPER or lower case ## USERS examples @@ -29,6 +30,17 @@ Environment variables: - `user|password||10000` - `user|password||10000|82` : add to an existing group (www-data) +## CONF examples + +- `CONF_FTPD_BANNER`: `My ftps server` +- `CONF_CHROOT_LOCAL_USER`: `YES` +- `CONF_chroot_list_enable`: `YES` +- `CONF_allow_writeable_chroot`: `YES` +- `CONF_chroot_list_file`: `/etc/vsftpd.chroot_list` +- `CONF_max_login_fails`: `3` +- `CONF_max_per_ip`: `3` +- `CONF_max_clients`: `10` + ## FTPS (File Transfer Protocol + SSL) Example Issue free Let's Encrypt certificate and use it with `alpine-ftp-server`. @@ -61,6 +73,7 @@ docker run -d \ - Do not forget to renew certificate in 3 month with `certbot renew` command. ## Via docker-compose + ``` alpine-ftp-server: image: delfer/alpine-ftp-server @@ -68,6 +81,11 @@ alpine-ftp-server: - "21:21" - 21000-21010:21000-21010 environment: + - CONF_FTPD_BANNER="My ftps server" + - CONF_CHROOT_LOCAL_USER=YES + - CONF_chroot_list_enable=YES + - CONF_allow_writeable_chroot=YES + - CONF_chroot_list_file=/etc/vsftpd.chroot_list - USERS="one|1234" - ADDRESS=ftp.site.domain volumes: diff --git a/start_vsftpd.sh b/start_vsftpd.sh index d3338af..5f1f470 100755 --- a/start_vsftpd.sh +++ b/start_vsftpd.sh @@ -76,6 +76,8 @@ fi if [ ! -z "$1" ]; then exec "$@" else + #Update configuration file + /bin/update_conf.sh vsftpd -opasv_min_port=$MIN_PORT -opasv_max_port=$MAX_PORT $ADDR_OPT $TLS_OPT /etc/vsftpd/vsftpd.conf [ -d /var/run/vsftpd ] || mkdir /var/run/vsftpd pgrep vsftpd | tail -n 1 > /var/run/vsftpd/vsftpd.pid diff --git a/update_conf.sh b/update_conf.sh new file mode 100755 index 0000000..82d23ab --- /dev/null +++ b/update_conf.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +readonly CONF_FILE_PATH="/etc/vsftpd/vsftpd.conf" + +env | grep -E '^CONF_' | grep -Ev '^CONF_FILE_PATH=' | while IFS== read parm value ; do + parm="${parm#CONF_*}" ; + parm=`echo "${parm}" | tr 'A-Z' 'a-z'` + echo "Setting parm ${parm} to ${value}" + if ( grep -qE "^#?${parm}=" ${CONF_FILE_PATH} ) ; then + sed -i "s;^#\?${parm}=.*;${parm}=${value};" "${CONF_FILE_PATH}" + else + sed -i "$ a\\#\n# Parameter based on environment variable\n${parm}=${value}" "${CONF_FILE_PATH}" + fi +done