Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set configuration parameters by variables #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_<PARM>` - custom parameter in configuration file, <PARM> may be UPPER or lower case

## USERS examples

Expand All @@ -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`.
Expand Down Expand Up @@ -61,13 +73,19 @@ 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
ports:
- "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:
Expand Down
2 changes: 2 additions & 0 deletions start_vsftpd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions update_conf.sh
Original file line number Diff line number Diff line change
@@ -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