Skip to content

Commit 0bb2fb2

Browse files
Initial commit
1 parent 577226e commit 0bb2fb2

File tree

8 files changed

+139
-1
lines changed

8 files changed

+139
-1
lines changed

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# https://github.com/docker-library/php/tree/master/8.1/bullseye/apache
2+
FROM php:8.1.1-apache-bullseye
3+
4+
ENTRYPOINT ["/usr/local/bin/tini", "--", "/docker-entrypoint.sh"]
5+
6+
EXPOSE 36622/tcp
7+
EXPOSE 80/tcp
8+
9+
# Override stopsignal https://github.com/docker-library/php/blob/master/8.1/bullseye/apache/Dockerfile#L280
10+
# SIGWINCH is Graceful Stop https://httpd.apache.org/docs/2.2/stopping.html#gracefulstop but tini would not catch it
11+
STOPSIGNAL SIGTERM
12+
13+
# Install openssh-server for sftp
14+
RUN apt-get update && \
15+
apt-get -y install openssh-server && \
16+
rm -rf /var/lib/apt/lists/* && \
17+
mkdir -p /var/run/sshd && \
18+
rm -f /etc/ssh/ssh_host_*key*
19+
20+
# Add sshd config file
21+
COPY sshd_config /etc/ssh/sshd_config
22+
23+
# Prepare dir for user keys
24+
RUN mkdir /var/www/.ssh && chown -R www-data:www-data /var/www/.ssh
25+
26+
# Install init system see https://github.com/krallin/tini
27+
COPY --from=krallin/ubuntu-tini:trusty /usr/local/bin/tini /usr/local/bin/tini
28+
29+
# Add custom entrypoint
30+
COPY docker-entrypoint.sh /docker-entrypoint.sh

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Mario Vejlupek
3+
Copyright (c) 2022 milionplus
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

docker-compose.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
services:
2+
3+
generate-ssh-keys:
4+
image: php-apache-sftp
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
entrypoint: /prepare-test.sh
9+
volumes:
10+
- ./test/prepare-test.sh:/prepare-test.sh
11+
- ssh:/var/www/.ssh
12+
13+
php-apache-sftp:
14+
image: php-apache-sftp
15+
depends_on:
16+
generate-ssh-keys:
17+
condition: service_completed_successfully
18+
build:
19+
context: .
20+
dockerfile: Dockerfile
21+
ports:
22+
- "8080:80"
23+
- "36622:36622"
24+
volumes:
25+
- ssh:/var/www/.ssh
26+
healthcheck:
27+
test: ["CMD", "echo", ">", "/dev/tcp/127.0.0.1/36622", "&&", "echo", ">", "/dev/tcp/127.0.0.1/80"]
28+
interval: 5s
29+
timeout: 3s
30+
retries: 20
31+
32+
sftp-test:
33+
image: php-apache-sftp
34+
build:
35+
context: .
36+
dockerfile: Dockerfile
37+
depends_on:
38+
php-apache-sftp:
39+
condition: service_healthy
40+
entrypoint: /test.sh php-apache-sftp
41+
working_dir: /
42+
volumes:
43+
- ./test/index.php:/index.php
44+
- ./test/test.sh:/test.sh
45+
- ssh:/var/www/.ssh
46+
47+
volumes:
48+
ssh:

docker-entrypoint.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#/bin/bash
2+
3+
if [ ! -f /etc/ssh/ssh_host_ed25519_key ]; then
4+
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
5+
fi
6+
if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
7+
ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N ''
8+
fi
9+
10+
# Restrict access from other users
11+
chmod 600 /etc/ssh/ssh_host_ed25519_key
12+
chmod 600 /etc/ssh/ssh_host_rsa_key
13+
chown www-data:www-data /var/www/.ssh/authorized_keys
14+
15+
/usr/sbin/sshd -D -e &
16+
17+
/usr/local/bin/docker-php-entrypoint apache2-foreground &
18+
19+
tail -f /var/log/apache2/*

sshd_config

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Secure defaults
2+
# See: https://stribika.github.io/2015/01/04/secure-secure-shell.html
3+
Port 36622
4+
Protocol 2
5+
HostKey /etc/ssh/ssh_host_ed25519_key
6+
HostKey /etc/ssh/ssh_host_rsa_key
7+
8+
# Faster connection
9+
# See: https://github.com/atmoz/sftp/issues/11
10+
UseDNS no
11+
12+
# Limited access
13+
PermitRootLogin no
14+
X11Forwarding no
15+
AllowTcpForwarding no
16+
17+
# Force sftp and chroot jail
18+
Subsystem sftp internal-sftp
19+
ForceCommand internal-sftp
20+
ChrootDirectory %h
21+
22+
# Enable this for more logs
23+
#LogLevel VERBOSE

test/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?
2+
phpinfo(INFO_MODULES);
3+
?>

test/prepare-test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
ssh-keygen -t ed25519 -C "[email protected]" -f /var/www/.ssh/id_ed25519 -P ""
4+
cp /var/www/.ssh/id_ed25519.pub /var/www/.ssh/authorized_keys
5+
chown -R www-data:www-data /var/www/.ssh

test/test.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
TARGET_HOST=$1
4+
5+
sftp -i /var/www/.ssh/id_ed25519 -oStrictHostKeyChecking=no -P36622 www-data@${TARGET_HOST} <<EOF
6+
cd html
7+
put index.php
8+
quit
9+
EOF
10+
curl -f -I ${TARGET_HOST} && echo "\033[0;32mOK\033[0m" || echo "\033[0;31mFAIL\033[0m"

0 commit comments

Comments
 (0)