Skip to content

Commit 5f68159

Browse files
authored
Merge pull request #1 from kylemanna/master
Bring fork up to date
2 parents d53043e + 1228577 commit 5f68159

File tree

15 files changed

+141
-183
lines changed

15 files changed

+141
-183
lines changed

Dockerfile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ LABEL maintainer="Kyle Manna <[email protected]>"
77

88
# Testing: pamtester
99
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories && \
10-
apk add --update openvpn iptables bash easy-rsa openvpn-auth-pam google-authenticator pamtester && \
10+
apk add --update openvpn iptables bash easy-rsa openvpn-auth-pam google-authenticator pamtester libqrencode && \
1111
ln -s /usr/share/easy-rsa/easyrsa /usr/local/bin && \
1212
rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /var/cache/distfiles/*
1313

1414
# Needed by scripts
15-
ENV OPENVPN /etc/openvpn
16-
ENV EASYRSA /usr/share/easy-rsa
17-
ENV EASYRSA_PKI $OPENVPN/pki
18-
ENV EASYRSA_VARS_FILE $OPENVPN/vars
19-
20-
# Prevents refused client connection because of an expired CRL
21-
ENV EASYRSA_CRL_DAYS 3650
15+
ENV OPENVPN=/etc/openvpn
16+
ENV EASYRSA=/usr/share/easy-rsa \
17+
EASYRSA_CRL_DAYS=3650 \
18+
EASYRSA_PKI=$OPENVPN/pki
2219

2320
VOLUME ["/etc/openvpn"]
2421

Dockerfile.aarch64

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ RUN echo "http://dl-4.alpinelinux.org/alpine/edge/community/" >> /etc/apk/reposi
1515
ENV OPENVPN /etc/openvpn
1616
ENV EASYRSA /usr/share/easy-rsa
1717
ENV EASYRSA_PKI $OPENVPN/pki
18-
ENV EASYRSA_VARS_FILE $OPENVPN/vars
1918

2019
# Prevents refused client connection because of an expired CRL
2120
ENV EASYRSA_CRL_DAYS 3650

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ a corresponding [Digital Ocean Community Tutorial](http://bit.ly/1AGUZkq).
3131
private key used by the newly generated certificate authority.
3232

3333
docker volume create --name $OVPN_DATA
34-
docker run -v $OVPN_DATA:/etc/openvpn --log-driver=none --rm kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM
35-
docker run -v $OVPN_DATA:/etc/openvpn --log-driver=none --rm -it kylemanna/openvpn ovpn_initpki
34+
docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM
35+
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
3636

3737
* Start OpenVPN server process
3838

3939
docker run -v $OVPN_DATA:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
4040

4141
* Generate a client certificate without a passphrase
4242

43-
docker run -v $OVPN_DATA:/etc/openvpn --log-driver=none --rm -it kylemanna/openvpn easyrsa build-client-full CLIENTNAME nopass
43+
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full CLIENTNAME nopass
4444

4545
* Retrieve the client configuration with embedded certificates
4646

47-
docker run -v $OVPN_DATA:/etc/openvpn --log-driver=none --rm kylemanna/openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
47+
docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
4848

4949
## Next Steps
5050

@@ -69,7 +69,7 @@ If you prefer to use `docker-compose` please refer to the [documentation](docs/d
6969

7070
* Create an environment variable with the name DEBUG and value of 1 to enable debug output (using "docker -e").
7171

72-
docker run -v $OVPN_DATA:/etc/openvpn -p 1194:1194/udp --privileged -e DEBUG=1 kylemanna/openvpn
72+
docker run -v $OVPN_DATA:/etc/openvpn -p 1194:1194/udp --cap-add=NET_ADMIN -e DEBUG=1 kylemanna/openvpn
7373

7474
* Test using a client that has openvpn installed correctly
7575

bin/easyrsa_vars

Lines changed: 0 additions & 39 deletions
This file was deleted.

bin/ovpn_otp_user

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ if [ "$2" == "interactive" ]; then
2828
# Always use time base OTP otherwise storage for counters must be configured somewhere in volume
2929
google-authenticator --time-based --force -l "${1}@${OVPN_CN}" -s /etc/openvpn/otp/${1}.google_authenticator
3030
else
31+
# Skip confirmation if not running in interctive mode. Essential for integration tests.
3132
google-authenticator --time-based --disallow-reuse --force --rate-limit=3 --rate-time=30 --window-size=3 \
32-
-l "${1}@${OVPN_CN}" -s /etc/openvpn/otp/${1}.google_authenticator
33-
fi
33+
-l "${1}@${OVPN_CN}" -s /etc/openvpn/otp/${1}.google_authenticator --no-confirm
34+
fi

bin/ovpn_revokeclient

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ if [ -z "$EASYRSA_PKI" ]; then
2222
fi
2323

2424
cn="$1"
25-
parm="$2"
2625

2726
if [ ! -f "$EASYRSA_PKI/private/${cn}.key" ]; then
2827
echo "Unable to find \"${cn}\", please try again or generate the key first" >&2
@@ -37,25 +36,4 @@ revoke_client_certificate(){
3736
chmod 644 "$OPENVPN/crl.pem"
3837
}
3938

40-
remove_files(){
41-
rm -v "$EASYRSA_PKI/issued/${1}.crt"
42-
rm -v "$EASYRSA_PKI/private/${1}.key"
43-
rm -v "$EASYRSA_PKI/reqs/${1}.req"
44-
}
45-
46-
case "$parm" in
47-
"remove")
48-
revoke_client_certificate "$cn"
49-
remove_files "$cn"
50-
;;
51-
"" | "keep")
52-
revoke_client_certificate "$cn"
53-
;;
54-
*)
55-
echo "When revoking a client certificate, this script let you choose if you want to remove the corresponding crt, key and req files." >&2
56-
echo "Pease note that the removal of those files is required if you want to generate a new client certificate using the revoked certificate's CN." >&2
57-
echo " 1. keep (default): Keep the files." >&2
58-
echo " 2. remove: Remove the files." >&2
59-
echo "Please specify one of those options as second parameter." >&2
60-
;;
61-
esac
39+
revoke_client_certificate "$cn"

bin/ovpn_run

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ function addArg {
3939
# this allows rules/routing to be altered by supplying this function
4040
# in an included file, such as ovpn_env.sh
4141
function setupIptablesAndRouting {
42-
iptables -t nat -C POSTROUTING -s $OVPN_SERVER -o $OVPN_NATDEVICE -j MASQUERADE || {
42+
iptables -t nat -C POSTROUTING -s $OVPN_SERVER -o $OVPN_NATDEVICE -j MASQUERADE 2>/dev/null || {
4343
iptables -t nat -A POSTROUTING -s $OVPN_SERVER -o $OVPN_NATDEVICE -j MASQUERADE
4444
}
4545
for i in "${OVPN_ROUTES[@]}"; do
46-
iptables -t nat -C POSTROUTING -s "$i" -o $OVPN_NATDEVICE -j MASQUERADE || {
46+
iptables -t nat -C POSTROUTING -s "$i" -o $OVPN_NATDEVICE -j MASQUERADE 2>/dev/null || {
4747
iptables -t nat -A POSTROUTING -s "$i" -o $OVPN_NATDEVICE -j MASQUERADE
4848
}
4949
done
@@ -87,13 +87,18 @@ fi
8787

8888
ip -6 route show default 2>/dev/null
8989
if [ $? = 0 ]; then
90-
echo "Enabling IPv6 Forwarding"
91-
# If this fails, ensure the docker container is run with --privileged
92-
# Could be side stepped with `ip netns` madness to drop privileged flag
90+
echo "Checking IPv6 Forwarding"
91+
if [ "$(</proc/sys/net/ipv6/conf/all/disable_ipv6)" != "0" ]; then
92+
echo "Sysctl error for disable_ipv6, please run docker with '--sysctl net.ipv6.conf.all.disable_ipv6=0'"
93+
fi
94+
95+
if [ "$(</proc/sys/net/ipv6/conf/default/forwarding)" != "1" ]; then
96+
echo "Sysctl error for default forwarding, please run docker with '--sysctl net.ipv6.conf.default.forwarding=1'"
97+
fi
9398

94-
sysctl -w net.ipv6.conf.all.disable_ipv6=0 || echo "Failed to enable IPv6 support"
95-
sysctl -w net.ipv6.conf.default.forwarding=1 || echo "Failed to enable IPv6 Forwarding default"
96-
sysctl -w net.ipv6.conf.all.forwarding=1 || echo "Failed to enable IPv6 Forwarding"
99+
if [ "$(</proc/sys/net/ipv6/conf/all/forwarding)" != "1" ]; then
100+
echo "Sysctl error for all forwarding, please run docker with '--sysctl net.ipv6.conf.all.forwarding=1'"
101+
fi
97102
fi
98103

99104
echo "Running 'openvpn ${ARGS[@]} ${USER_ARGS[@]}'"

docs/advanced.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ The [`ovpn_genconfig`](/bin/ovpn_genconfig) script is intended for simple config
1717

1818
* Start the server with:
1919

20-
docker run -v $PWD:/etc/openvpn -d -p 1194:1194/udp --privileged kylemanna/openvpn
20+
docker run -v $PWD:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn

docs/tcp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ specified protocol, adjust the mapping appropriately:
2121
## Running a Second Fallback TCP Container
2222
Instead of choosing between UDP and TCP, you can use both. A single instance of OpenVPN can only listen for a single protocol on a single port, but this image makes it easy to run two instances simultaneously. After building, configuring, and starting a standard container listening for UDP traffic on 1194, you can start a second container listening for tcp traffic on port 443:
2323

24-
docker run -v $OVPN_DATA:/etc/openvpn --rm -p 443:1194/tcp --privileged kylemanna/openvpn ovpn_run --proto tcp
24+
docker run -v $OVPN_DATA:/etc/openvpn --rm -p 443:1194/tcp --cap-add=NET_ADMIN kylemanna/openvpn ovpn_run --proto tcp
2525

2626
`ovpn_run` will load all the values from the default config file, and `--proto tcp` will override the protocol setting.
2727

test/client/wait-for-connect.sh

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,46 @@ set -e
55

66
OPENVPN_CONFIG=${1:-/client/config.ovpn}
77

8-
# Run in background, rely on bash for job management
8+
# For some reason privileged mode creates the char device and cap-add=NET_ADMIN doesn't
9+
mkdir -p /dev/net
10+
if [ ! -c /dev/net/tun ]; then
11+
mknod /dev/net/tun c 10 200
12+
fi
13+
14+
# Run in background using bash job management, setup trap to clean-up
15+
trap "{ jobs -p | xargs -r kill; wait; }" EXIT
916
openvpn --config "$OPENVPN_CONFIG" --management 127.0.0.1 9999 &
1017

1118
# Spin waiting for interface to exist signifying connection
1219
timeout=10
1320
for i in $(seq $timeout); do
21+
# Allow to start-up
22+
sleep 0.5
23+
24+
# Use bash magic to open tcp socket on fd 3 and break when successful
25+
exec 3<>/dev/tcp/127.0.0.1/9999 && break
26+
done
1427

15-
# Break when connected
16-
#echo state | busybox nc 127.0.0.1 9999 | grep -q "CONNECTED,SUCCESS" && break;
28+
if [ $i -ge $timeout ]; then
29+
echo "Error connecting to OpenVPN mgmt interface, i=$i, exiting."
30+
exit 2
31+
fi
1732

18-
# Bash magic for tcp sockets
19-
if exec 3<>/dev/tcp/127.0.0.1/9999; then
20-
# Consume all header input
21-
while read -t 0.1 <&3; do true; done
22-
echo "state" >&3
23-
read -t 1 <&3
24-
echo -n $REPLY | grep -q "CONNECTED,SUCCESS" && break || true
25-
exec 3>&-
26-
fi
33+
# Consume all header input and echo, look for errors here
34+
while read -t 0.1 <&3; do echo $REPLY; done
2735

28-
# Else sleep
36+
# Request state over mgmt interface
37+
timeout=10
38+
for i in $(seq $timeout); do
39+
echo "state" >&3
40+
state=$(head -n1 <&3)
41+
echo -n "$state" | grep -q 'CONNECTED,SUCCESS' && break
2942
sleep 1
3043
done
3144

3245
if [ $i -ge $timeout ]; then
33-
echo "Error starting OpenVPN, i=$i, exiting."
34-
exit 2;
46+
echo "Error connecting to OpenVPN, i=$i, exiting."
47+
exit 3
3548
fi
3649

37-
# The show is over.
38-
kill %1
50+
exec 3>&-

0 commit comments

Comments
 (0)