Fred808 commited on
Commit
72a4e50
·
verified ·
1 Parent(s): f1eaa00

Upload 15 files

Browse files
Files changed (15) hide show
  1. .dockerignore +3 -0
  2. .editorconfig +17 -0
  3. Dockerfile +76 -0
  4. ipsec.conf +69 -0
  5. kill_supervisor.py +28 -0
  6. options.xl2tpd +14 -0
  7. run.sh +82 -0
  8. strongswan.conf +17 -0
  9. supervisord.conf +26 -0
  10. vpn_adduser +20 -0
  11. vpn_apply +11 -0
  12. vpn_deluser +14 -0
  13. vpn_setpsk +15 -0
  14. vpn_unsetpsk +4 -0
  15. xl2tpd.conf +17 -0
.dockerignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .*
2
+ LICENSE
3
+ README.md
.editorconfig ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ end_of_line = lf
7
+ indent_size = 2
8
+ indent_style = tab
9
+ max_line_length = 80
10
+ trim_trailing_whitespace = true
11
+
12
+ [*.md]
13
+ max_line_length = 0
14
+ trim_trailing_whitespace = false
15
+
16
+ [COMMIT_EDITMSG]
17
+ max_line_length = 0
Dockerfile ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM buildpack-deps:jessie
2
+
3
+ WORKDIR /app
4
+
5
+
6
+ RUN mkdir -p /conf
7
+
8
+ RUN apt-get update && apt-get install -y \
9
+ libgmp-dev \
10
+ iptables \
11
+ xl2tpd \
12
+ module-init-tools \
13
+ supervisor
14
+
15
+ ENV STRONGSWAN_VERSION 5.5.0
16
+ ENV GPG_KEY 948F158A4E76A27BF3D07532DF42C170B34DBA77
17
+
18
+ RUN mkdir -p /usr/src/strongswan \
19
+ && cd /usr/src \
20
+ && curl -SOL "https://download.strongswan.org/strongswan-$STRONGSWAN_VERSION.tar.gz.sig" \
21
+ && curl -SOL "https://download.strongswan.org/strongswan-$STRONGSWAN_VERSION.tar.gz" \
22
+ && export GNUPGHOME="$(mktemp -d)" \
23
+ && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
24
+ && gpg --batch --verify strongswan-$STRONGSWAN_VERSION.tar.gz.sig strongswan-$STRONGSWAN_VERSION.tar.gz \
25
+ && tar -zxf strongswan-$STRONGSWAN_VERSION.tar.gz -C /usr/src/strongswan --strip-components 1 \
26
+ && cd /usr/src/strongswan \
27
+ && ./configure --prefix=/usr --sysconfdir=/etc \
28
+ --enable-eap-radius \
29
+ --enable-eap-mschapv2 \
30
+ --enable-eap-identity \
31
+ --enable-eap-md5 \
32
+ --enable-eap-tls \
33
+ --enable-eap-ttls \
34
+ --enable-eap-peap \
35
+ --enable-eap-tnc \
36
+ --enable-eap-dynamic \
37
+ --enable-xauth-eap \
38
+ --enable-openssl \
39
+ && make -j \
40
+ && make install \
41
+ && rm -rf "/usr/src/strongswan*"
42
+
43
+ # Strongswan Configuration
44
+ ADD ipsec.conf /etc/ipsec.conf
45
+ ADD strongswan.conf /etc/strongswan.conf
46
+
47
+ # XL2TPD Configuration
48
+ ADD xl2tpd.conf /etc/xl2tpd/xl2tpd.conf
49
+ ADD options.xl2tpd /etc/ppp/options.xl2tpd
50
+
51
+ # Supervisor config
52
+ ADD supervisord.conf supervisord.conf
53
+ ADD kill_supervisor.py /usr/bin/kill_supervisor.py
54
+
55
+ ADD run.sh /run.sh
56
+ ADD vpn_adduser /usr/local/bin/vpn_adduser
57
+ ADD vpn_deluser /usr/local/bin/vpn_deluser
58
+ ADD vpn_setpsk /usr/local/bin/vpn_setpsk
59
+ ADD vpn_unsetpsk /usr/local/bin/vpn_unsetpsk
60
+ ADD vpn_apply /usr/local/bin/vpn_apply
61
+
62
+ # The password is later on replaced with a random string
63
+ ENV VPN_USER user
64
+ ENV VPN_PASSWORD password
65
+ ENV VPN_PSK password
66
+
67
+ RUN useradd -m -u 1000 user
68
+ USER user
69
+ ENV PATH="/home/user/.local/bin:$PATH"
70
+
71
+ RUN chmod -R 777 /app
72
+ VOLUME ["/etc/ipsec.d"]
73
+
74
+ EXPOSE 4500/udp 500/udp 1701/udp
75
+
76
+ CMD ["/run.sh"]
ipsec.conf ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ipsec.conf - strongSwan IPsec configuration file
2
+
3
+ config setup
4
+ uniqueids=no
5
+ charondebug="cfg 2, dmn 2, ike 2, net 0"
6
+
7
+ conn %default
8
+ dpdaction=clear
9
+ dpddelay=300s
10
+ rekey=no
11
+ left=%defaultroute
12
+ leftfirewall=yes
13
+ right=%any
14
+ ikelifetime=60m
15
+ keylife=20m
16
+ rekeymargin=3m
17
+ keyingtries=1
18
+ auto=add
19
+
20
+ #######################################
21
+ # L2TP Connections
22
+ #######################################
23
+
24
+ conn L2TP-IKEv1-PSK
25
+ type=transport
26
+ keyexchange=ikev1
27
+ authby=secret
28
+ leftprotoport=udp/l2tp
29
+ left=%any
30
+ right=%any
31
+ rekey=no
32
+ forceencaps=yes
33
+
34
+ #######################################
35
+ # Default non L2TP Connections
36
+ #######################################
37
+
38
+ conn Non-L2TP
39
+ leftsubnet=0.0.0.0/0
40
+ rightsubnet=10.0.0.0/24
41
+ rightsourceip=10.0.0.0/24
42
+
43
+ #######################################
44
+ # EAP Connections
45
+ #######################################
46
+
47
+ # This detects a supported EAP method
48
+ conn IKEv2-EAP
49
+ also=Non-L2TP
50
+ keyexchange=ikev2
51
+ eap_identity=%any
52
+ rightauth=eap-dynamic
53
+
54
+ #######################################
55
+ # PSK Connections
56
+ #######################################
57
+
58
+ conn IKEv2-PSK
59
+ also=Non-L2TP
60
+ keyexchange=ikev2
61
+ authby=secret
62
+
63
+ # Cisco IPSec
64
+ conn IKEv1-PSK-XAuth
65
+ also=Non-L2TP
66
+ keyexchange=ikev1
67
+ leftauth=psk
68
+ rightauth=psk
69
+ rightauth2=xauth
kill_supervisor.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ import sys
3
+ import os
4
+ import signal
5
+
6
+ def write_stdout(s):
7
+ sys.stdout.write(s)
8
+ sys.stdout.flush()
9
+
10
+ def write_stderr(s):
11
+ sys.stderr.write(s)
12
+ sys.stderr.flush()
13
+
14
+ def main():
15
+ while 1:
16
+ write_stdout('READY\n')
17
+ line = sys.stdin.readline()
18
+ write_stdout('This line kills supervisor: ' + line);
19
+ try:
20
+ pidfile = open('/var/run/supervisord.pid','r')
21
+ pid = int(pidfile.readline());
22
+ os.kill(pid, signal.SIGQUIT)
23
+ except Exception as e:
24
+ write_stdout('Could not kill supervisor: ' + e.strerror + '\n')
25
+ write_stdout('RESULT 2\nOK')
26
+
27
+ if __name__ == '__main__':
28
+ main()
options.xl2tpd ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ipcp-accept-local
2
+ ipcp-accept-remote
3
+ ms-dns 8.8.8.8
4
+ ms-dns 8.8.4.4
5
+ noccp
6
+ auth
7
+ crtscts
8
+ idle 1800
9
+ mtu 1280
10
+ mru 1280
11
+ lock
12
+ lcp-echo-failure 10
13
+ lcp-echo-interval 60
14
+ connect-delay 5000
run.sh ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ sysctl -w net.ipv4.conf.all.rp_filter=2
4
+
5
+ iptables --table nat --append POSTROUTING --jump MASQUERADE
6
+ echo 1 > /proc/sys/net/ipv4/ip_forward
7
+ for each in /proc/sys/net/ipv4/conf/*
8
+ do
9
+ echo 0 > $each/accept_redirects
10
+ echo 0 > $each/send_redirects
11
+ done
12
+
13
+ if [ "$VPN_PASSWORD" = "password" ] || [ "$VPN_PASSWORD" = "" ]; then
14
+ # Generate a random password
15
+ P1=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3`
16
+ P2=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3`
17
+ P3=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3`
18
+ VPN_PASSWORD="$P1$P2$P3"
19
+ echo "No VPN_PASSWORD set! Generated a random password: $VPN_PASSWORD"
20
+ fi
21
+
22
+ if [ "$VPN_PSK" = "password" ] || [ "$VPN_PSK" = "" ]; then
23
+ # Generate a random password
24
+ P1=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3`
25
+ P2=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3`
26
+ P3=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3`
27
+ VPN_PSK="$P1$P2$P3"
28
+ echo "No VPN_PSK set! Generated a random PSK key: $VPN_PSK"
29
+ fi
30
+
31
+ if [ "$VPN_PASSWORD" = "$VPN_PSK" ]; then
32
+ echo "It is not recommended to use the same secret as password and PSK key!"
33
+ fi
34
+
35
+ cat > /etc/ppp/l2tp-secrets <<EOF
36
+ # This file holds secrets for L2TP authentication.
37
+ # Username Server Secret Hosts
38
+
39
+ "$VPN_USER" "*" "$VPN_PASSWORD" "*"
40
+ EOF
41
+
42
+ cat > /etc/ipsec.secrets <<EOF
43
+ # This file holds shared secrets or RSA private keys for authentication.
44
+ # RSA private key for this host, authenticating it to any other host
45
+ # which knows the public part. Suitable public keys, for ipsec.conf, DNS,
46
+ # or configuration of other implementations, can be extracted conveniently
47
+ # with "ipsec showhostkey".
48
+
49
+ : PSK "$VPN_PSK"
50
+
51
+ $VPN_USER : EAP "$VPN_PASSWORD"
52
+ $VPN_USER : XAUTH "$VPN_PASSWORD"
53
+ EOF
54
+
55
+ if [ -f "/etc/ipsec.d/l2tp-secrets" ]; then
56
+ echo "Overwriting standard /etc/ppp/l2tp-secrets with /etc/ipsec.d/l2tp-secrets"
57
+ cp -f /etc/ipsec.d/l2tp-secrets /etc/ppp/l2tp-secrets
58
+ fi
59
+
60
+ if [ -f "/etc/ipsec.d/ipsec.secrets" ]; then
61
+ echo "Overwriting standard /etc/ipsec.secrets with /etc/ipsec.d/ipsec.secrets"
62
+ cp -f /etc/ipsec.d/ipsec.secrets /etc/ipsec.secrets
63
+ fi
64
+
65
+ if [ -f "/etc/ipsec.d/ipsec.conf" ]; then
66
+ echo "Overwriting standard /etc/ipsec.conf with /etc/ipsec.d/ipsec.conf"
67
+ cp -f /etc/ipsec.d/ipsec.conf /etc/ipsec.conf
68
+ fi
69
+
70
+ if [ -f "/etc/ipsec.d/strongswan.conf" ]; then
71
+ echo "Overwriting standard /etc/strongswan.conf with /etc/ipsec.d/strongswan.conf"
72
+ cp -f /etc/ipsec.d/strongswan.conf /etc/strongswan.conf
73
+ fi
74
+
75
+ if [ -f "/etc/ipsec.d/xl2tpd.conf" ]; then
76
+ echo "Overwriting standard /etc/xl2tpd/xl2tpd.conf with /etc/ipsec.d/xl2tpd.conf"
77
+ cp -f /etc/ipsec.d/xl2tpd.conf /etc/xl2tpd/xl2tpd.conf
78
+ fi
79
+
80
+ mkdir -p /var/run/xl2tpd
81
+
82
+ exec /usr/bin/supervisord -c /supervisord.conf
strongswan.conf ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /etc/strongswan.conf - strongSwan configuration file
2
+ # strongswan.conf - strongSwan configuration file
3
+ #
4
+ # Refer to the strongswan.conf(5) manpage for details
5
+
6
+ charon {
7
+ load_modular = yes
8
+ send_vendor_id = yes
9
+ plugins {
10
+ include strongswan.d/charon/*.conf
11
+ attr {
12
+ dns = 8.8.8.8, 8.8.4.4
13
+ }
14
+ }
15
+ }
16
+
17
+ include strongswan.d/*.conf
supervisord.conf ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [supervisord]
2
+ nodaemon=true
3
+
4
+ [program:xl2tpd]
5
+ command=/usr/sbin/xl2tpd -c /etc/xl2tpd/xl2tpd.conf -D
6
+ redirect_stderr=true
7
+ numprocs=1
8
+ stdout_logfile=/dev/fd/1
9
+ stdout_logfile_maxbytes=0
10
+
11
+ [program:ipsec]
12
+ command=ipsec start --nofork
13
+ redirect_stderr=true
14
+ numprocs=1
15
+ stdout_logfile=/dev/fd/1
16
+ stdout_logfile_maxbytes=0
17
+
18
+ [eventlistener:ipsec_exit]
19
+ command=/usr/bin/kill_supervisor.py
20
+ process_name=ipsec
21
+ events=PROCESS_STATE_FATAL
22
+
23
+ [eventlistener:xl2tpd_exit]
24
+ command=/usr/bin/kill_supervisor.py
25
+ process_name=xl2tpd
26
+ events=PROCESS_STATE_FATAL
vpn_adduser ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ vpn_user=$1
4
+ vpn_password=$2
5
+
6
+ if [ -z ${vpn_user} ] || [ -z ${vpn_password} ]; then
7
+ echo "Usage: $0 user password"
8
+ exit 1
9
+ fi
10
+
11
+ vpn_deluser ${vpn_user}
12
+
13
+ cat >> /etc/ipsec.d/l2tp-secrets <<EOF
14
+ "${vpn_user}" "*" "${vpn_password}" "*"
15
+ EOF
16
+
17
+ cat >> /etc/ipsec.d/ipsec.secrets <<EOF
18
+ ${vpn_user} : EAP "${vpn_password}"
19
+ ${vpn_user} : XAUTH "${vpn_password}"
20
+ EOF
vpn_apply ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ if [ -f "/etc/ipsec.d/l2tp-secrets" ]; then
4
+ cp -f /etc/ipsec.d/l2tp-secrets /etc/ppp/l2tp-secrets
5
+ fi
6
+
7
+ if [ -f "/etc/ipsec.d/ipsec.secrets" ]; then
8
+ cp -f /etc/ipsec.d/ipsec.secrets /etc/ipsec.secrets
9
+ fi
10
+
11
+ ipsec rereadsecrets
vpn_deluser ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ vpn_user=$1
4
+
5
+ if [ -z ${vpn_user} ]; then
6
+ echo "Usage: $0 user"
7
+ exit 1
8
+ fi
9
+
10
+ touch /etc/ipsec.d/ipsec.secrets
11
+ touch /etc/ipsec.d/l2tp-secrets
12
+
13
+ sed -i "/${vpn_user} :/d" /etc/ipsec.d/ipsec.secrets
14
+ sed -i "/\"${vpn_user}\" \"*\"/d" /etc/ipsec.d/l2tp-secrets
vpn_setpsk ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ psk=$1
4
+
5
+ if [ -z ${psk} ]; then
6
+ echo "Usage: $0 psk"
7
+ exit 1
8
+ fi
9
+
10
+ vpn_unsetpsk
11
+
12
+ touch /etc/ipsec.d/ipsec.secrets
13
+ cat >> /etc/ipsec.d/ipsec.secrets <<EOF
14
+ : PSK "${psk}"
15
+ EOF
vpn_unsetpsk ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ touch /etc/ipsec.d/ipsec.secrets
4
+ sed '/: PSK/d' /etc/ipsec.d/ipsec.secrets
xl2tpd.conf ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [global]
2
+ port = 1701
3
+ auth file = /etc/ppp/l2tp-secrets
4
+ debug avp = yes
5
+ debug network = yes
6
+ debug state = yes
7
+ debug tunnel = yes
8
+ [lns default]
9
+ ip range = 10.1.0.2-10.1.0.254
10
+ local ip = 10.1.0.1
11
+ require chap = yes
12
+ refuse pap = yes
13
+ require authentication = yes
14
+ name = l2tpd
15
+ ;ppp debug = yes
16
+ pppoptfile = /etc/ppp/options.xl2tpd
17
+ length bit = yes