Skip to content

Commit 059deb2

Browse files
committed
initial
0 parents  commit 059deb2

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM alpine:3.8
2+
3+
ENV VPN_DEVICE="eth0"
4+
ENV VPN_NETWORK_IPV4="192.168.99.0/24"
5+
ENV VPN_NETWORK_IPV6="fd9d:bc11:4020::/48"
6+
ENV IKE_CIPHERS="aes128gcm16-prfsha512-ecp256!"
7+
ENV ESP_CIPHERS="aes128gcm16-ecp256!"
8+
ENV DUMMY_DEVICE="1.1.1.1/32"
9+
ENV VPN_DNS="1.1.1.1"
10+
11+
RUN apk add --no-cache iptables openssl strongswan util-linux \
12+
&& ln -sf /etc/ipsec.d/ipsec.conf /etc/ipsec.conf \
13+
&& ln -sf /etc/ipsec.d/ipsec.secrets /etc/ipsec.secrets
14+
15+
COPY initial-setup.sh /initial-setup.sh
16+
COPY docker-entrypoint.sh /docker-entrypoint.sh
17+
18+
VOLUME /etc/ipsec.d /etc/strongswan.d
19+
20+
EXPOSE 500/udp 4500/udp
21+
22+
ENTRYPOINT ["/docker-entrypoint.sh"]
23+

docker-entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh -e
2+
3+
./initial-setup.sh
4+
exec ipsec start --nofork "$@"
5+

initial-setup.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh -e
2+
3+
if [ -e /etc/ipsec.d/ipsec.conf ]; then
4+
echo "VPN has already been setup!"
5+
exit 0
6+
fi
7+
8+
echo "Initializing..."
9+
VPN_PASSWORD=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32 ; echo '')
10+
echo ${VPN_PASSWORD} > /etc/ipsec.d/client.password
11+
12+
touch /etc/ipsec.d/triplets.dat
13+
cat > /etc/ipsec.d/ipsec.conf <<_EOF_
14+
config setup
15+
uniqueids=never
16+
charondebug="ike 2, knl 2, cfg 2, net 2, esp 2, dmn 2, mgr 2"
17+
18+
conn %default
19+
fragmentation=yes
20+
rekey=no
21+
dpdaction=clear
22+
keyexchange=ikev2
23+
compress=yes
24+
dpddelay=21600s
25+
26+
ike=${IKE_CIPHERS}
27+
esp=${ESP_CIPHERS}
28+
29+
left=%any
30+
leftauth=pubkey
31+
leftid="${VPN_DOMAIN}"
32+
leftcert=fullchain.pem
33+
leftsendcert=always
34+
leftsubnet=0.0.0.0/0,::/0
35+
36+
right=%any
37+
rightauth=eap-mschapv2
38+
rightsourceip=${VPN_NETWORK_IPV4},${VPN_NETWORK_IPV6}
39+
rightsubnet=${DUMMY_DEVICE}
40+
rightdns=${VPN_DNS}
41+
eap_identity=%identity
42+
43+
conn ikev2-pubkey
44+
auto=add
45+
_EOF_
46+
47+
cat > /etc/ipsec.d/ipsec.secrets <<_EOF_
48+
: RSA "privkey.pem"
49+
vpn : EAP "${VPN_PASSWORD}"
50+
_EOF_

0 commit comments

Comments
 (0)