Skip to content

Commit a64ecb0

Browse files
committed
Add IPSec/L2TP support
1 parent 0869d3f commit a64ecb0

6 files changed

+95
-18
lines changed

Dockerfile

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ RUN mkdir -p /conf
44

55
RUN apt-get update && apt-get install -y \
66
libgmp-dev \
7-
iptables
7+
iptables \
8+
xl2tpd
89

910
ENV STRONGSWAN_VERSION 5.3.4
1011

@@ -13,7 +14,6 @@ RUN mkdir -p /usr/src/strongswan \
1314
| tar -zxC /usr/src/strongswan --strip-components 1 \
1415
&& cd /usr/src/strongswan \
1516
&& ./configure --prefix=/usr --sysconfdir=/etc \
16-
--enable-kernel-libipsec \
1717
--enable-eap-radius \
1818
--enable-eap-mschapv2 \
1919
--enable-eap-identity \
@@ -30,9 +30,14 @@ RUN mkdir -p /usr/src/strongswan \
3030
&& make install \
3131
&& rm -rf /usr/src/strongswan
3232

33-
# Configuration files
33+
# Strongswan Configuration
3434
ADD ipsec.conf /etc/ipsec.conf
3535
ADD strongswan.conf /etc/strongswan.conf
36+
37+
# XL2TPD Configuration
38+
ADD xl2tpd.conf /etc/xl2tpd/xl2tpd.conf
39+
ADD options.xl2tpd /etc/ppp/options.xl2tpd
40+
3641
ADD run.sh /run.sh
3742

3843
# The password is later on replaced with a random string
@@ -41,6 +46,7 @@ ENV VPN_PASSWORD password
4146
ENV VPN_PSK password
4247

4348
VOLUME ["/etc/ipsec.d"]
44-
EXPOSE 4500/udp 500/udp
49+
50+
EXPOSE 4500/udp 500/udp 1701/udp
4551

4652
CMD ["/run.sh"]

ipsec.conf

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,52 @@
11
# ipsec.conf - strongSwan IPsec configuration file
22

33
config setup
4-
uniqueids=never
4+
uniqueids=no
55
charondebug="cfg 2, dmn 2, ike 2, net 0"
66

77
conn %default
88
dpdaction=clear
99
dpddelay=300s
1010
rekey=no
1111
left=%defaultroute
12-
leftsubnet=0.0.0.0/0
1312
leftfirewall=yes
1413
right=%any
15-
rightsubnet=10.0.0.0/24
16-
rightsourceip=10.0.0.0/24
1714
ikelifetime=60m
1815
keylife=20m
1916
rekeymargin=3m
2017
keyingtries=1
2118
auto=add
2219

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+
2343
#######################################
2444
# EAP Connections
2545
#######################################
2646

2747
# This detects a supported EAP method
2848
conn IKEv2-EAP
49+
also=Non-L2TP
2950
keyexchange=ikev2
3051
eap_identity=%any
3152
rightauth=eap-dynamic
@@ -35,11 +56,13 @@ conn IKEv2-EAP
3556
#######################################
3657

3758
conn IKEv2-PSK
59+
also=Non-L2TP
3860
keyexchange=ikev2
3961
authby=secret
4062

4163
# Cisco IPSec
4264
conn IKEv1-PSK-XAuth
65+
also=Non-L2TP
4366
keyexchange=ikev1
4467
leftauth=psk
4568
rightauth=psk

options.xl2tpd

+14
Original file line numberDiff line numberDiff line change
@@ -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

+26-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ if [ "$VPN_PSK" = "password" ] || [ "$VPN_PSK" = "" ]; then
2828
echo "No VPN_PSK set! Generated a random PSK key: $VPN_PSK"
2929
fi
3030

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/chap-secrets <<EOF
36+
# This file holds secrets for L2TP authentication.
37+
# Username Server Secret Hosts
38+
39+
"$VPN_USER" "*" "$VPN_PASSWORD" "*"
40+
EOF
41+
3142
cat > /etc/ipsec.secrets <<EOF
3243
# This file holds shared secrets or RSA private keys for authentication.
3344
# RSA private key for this host, authenticating it to any other host
@@ -41,6 +52,11 @@ $VPN_USER : EAP "$VPN_PASSWORD"
4152
$VPN_USER : XAUTH "$VPN_PASSWORD"
4253
EOF
4354

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+
4460
if [ -f "/etc/ipsec.d/ipsec.secrets" ]; then
4561
echo "Overwriting standard /etc/ipsec.secrets with /etc/ipsec.d/ipsec.secrets"
4662
cp -f /etc/ipsec.d/ipsec.secrets /etc/ipsec.secrets
@@ -56,4 +72,13 @@ if [ -f "/conf/strongswan.conf" ]; then
5672
cp -f /conf/strongswan.conf /etc/strongswan.conf
5773
fi
5874

59-
ipsec start --nofork
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+
echo "Starting XL2TPD process..."
81+
mkdir -p /var/run/xl2tpd
82+
/usr/sbin/xl2tpd -c /etc/xl2tpd/xl2tpd.conf
83+
84+
ipsec start --nofork\

strongswan.conf

+1-9
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,12 @@
55

66
charon {
77
load_modular = yes
8+
send_vendor_id = yes
89
plugins {
910
include strongswan.d/charon/*.conf
1011
attr {
1112
dns = 8.8.8.8, 8.8.4.4
1213
}
13-
kernel-netlink {
14-
fwmark = !0x42
15-
}
16-
socket-default {
17-
fwmark = 0x42
18-
}
19-
kernel-libipsec {
20-
allow_peer_ts = yes
21-
}
2214
}
2315
}
2416

xl2tpd.conf

+17
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)