Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit 6d5b331

Browse files
committed
Add SFTP support
SFTP support should be shipped in a separate docker image. SFTP is served by openssh listening on port 22. SFTP is not properly configured to chroot users in their homedir. This allows an authenticated user to leak the list of your ftp users.
1 parent 27dc88e commit 6d5b331

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

Dockerfile

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,53 @@
11
FROM alpine:latest
2-
LABEL maintainer "[email protected]"
2+
LABEL maintainer "[email protected]"
3+
ARG VERSION_S3FS=v1.83
34

4-
# s3fs tag to checkout
5-
ARG S3FS_VERSION=v1.83
6-
7-
# Install s3fs binary
8-
RUN apk add --no-cache --virtual .fuse-builddeps \
5+
# Install s3fs-fuse and sftpserver
6+
RUN apk upgrade --no-cache \
7+
&& apk add --no-cache --virtual build-deps \
98
alpine-sdk \
109
automake \
1110
autoconf \
1211
curl-dev \
1312
fuse-dev \
13+
gnutls-dev \
1414
libxml2-dev \
15-
&& git clone https://github.com/s3fs-fuse/s3fs-fuse.git \
15+
libgcrypt-dev \
16+
&& git clone https://github.com/s3fs-fuse/s3fs-fuse \
1617
&& cd s3fs-fuse \
17-
&& git checkout tags/${S3FS_VERSION} -b ${S3FS_VERSION} \
18+
&& git checkout tags/${VERSION_S3FS} -b ${VERSION_S3FS} \
1819
&& ./autogen.sh \
19-
&& ./configure --prefix=/usr \
20-
&& make \
20+
&& ./configure --prefix=/usr --with-gnutls \
2121
&& make install \
2222
&& cd .. \
2323
&& rm -rf s3fs-fuse \
24-
&& apk del .fuse-builddeps
24+
&& apk del build-deps
2525

2626
# Install vsftpd and s3fs libraries
2727
RUN apk add --no-cache \
2828
fuse \
29+
gnutls \
2930
lftp \
3031
libcurl \
32+
libgcrypt \
3133
libstdc++ \
3234
libxml2 \
3335
logrotate \
36+
openssh \
3437
openssl \
3538
vsftpd
3639

3740
RUN sed -i 's|/var/log/messages|/var/log/*.log|' /etc/logrotate.conf
3841

42+
RUN ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N '' \
43+
&& ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N ''
44+
3945
COPY lftp-sync.sh /usr/local/bin/
4046
RUN chmod 755 /usr/local/bin/lftp-sync.sh
4147

4248
COPY docker-entrypoint.sh /
4349
ENTRYPOINT ["/docker-entrypoint.sh"]
50+
EXPOSE 21/tcp
51+
EXPOSE 22/tcp
52+
EXPOSE 65000/tcp
4453
VOLUME ["/var/log"]

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# docker-vsftpd-s3
22

3-
Alpine based Dockerfile running a vsftpd server providing FTP access to an Amazon S3 bucket.
3+
Alpine based Dockerfile running a vsftpd server providing secure FTP access to an Amazon S3 bucket.
44
This docker image can run in Amazon ECS.
55

66
## Usage
@@ -78,3 +78,9 @@ Start a docker from this image.
7878
$ docker run -it --device /dev/fuse --cap-add sys_admin --security-opt apparmor:unconfined -p 21:21 -p 65000:65000 -e AWS_ACCESS_KEY_ID=ABCDEFGHIJKLMNOPQRST -e AWS_SECRET_ACCESS_KEY=0123456789ABCDEF0123456789ABCDEF01234567 -e S3_BUCKET="my-s3-bucket" -e FTPD_USER="my_ftp_user" -e FTPD_PASS="my_ftp_password" vsftpd-s3
7979
```
8080

81+
## Security notes
82+
83+
Current docker image is shipped with FTPS and SFTP support, although SFTP support should be (and will be !) shipped in a separate docker image.
84+
SFTP is served by openssh listening on port 22. SFTP is not properly configured to chroot users in their homedir.
85+
This allows an authenticated user to leak the list of your ftp users.
86+

docker-entrypoint.sh

+15-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ echo "${FTPD_USERS}" |sed 's/ /\n/g' |while read line; do
9898
done
9999
done
100100

101+
# Enable SFTP
102+
echo "Protocol 2
103+
HostKey /etc/ssh/ssh_host_ed25519_key
104+
HostKey /etc/ssh/ssh_host_rsa_key
105+
UseDNS no
106+
PermitRootLogin no
107+
X11Forwarding no
108+
AllowTcpForwarding no
109+
Subsystem sftp internal-sftp
110+
ForceCommand internal-sftp -d %u
111+
ChrootDirectory /home
112+
" > /etc/ssh/sshd_config
113+
101114
# FTP sync client
102115
FTP_SYNC=${FTP_SYNC:-0}
103116
FTP_HOST=${FTP_HOST:-localhost}
@@ -116,6 +129,6 @@ DIR_LOCAL=${DIR_LOCAL:-/home/$FTPD_USER}
116129
# Launch crond
117130
crond -L /var/log/crond.log
118131

119-
# Launch vsftpd
120-
[ $# -eq 0 ] && /usr/sbin/vsftpd || exec "$@" &
132+
# Launch sshd && vsftpd
133+
[ $# -eq 0 ] && /usr/sbin/sshd -e && /usr/sbin/vsftpd || exec "$@" &
121134
PID=$! && wait

0 commit comments

Comments
 (0)