Compare commits
107 Commits
Author | SHA1 | Date | |
---|---|---|---|
1498795de2 | |||
f00de363c7 | |||
7f58926aa2 | |||
98340d7602 | |||
9459804a1d | |||
b298eb16bc | |||
2c3284acd6 | |||
314eb15507 | |||
ee9f4531ad | |||
41f7fd22ad | |||
d08df0189b | |||
d96378a391 | |||
32029c98c8 | |||
3df53012b6 | |||
74c4ca94a7 | |||
b96a91e876 | |||
407506392f | |||
bf9f58f8e1 | |||
050d4a1f82 | |||
d6209eebc2 | |||
2d16231c3c | |||
15ac3c89b0 | |||
0181bb93d6 | |||
e557222753 | |||
3703d3afc3 | |||
d3d11b660a | |||
4868a35bd3 | |||
bce012b92a | |||
7007c49d34 | |||
c679404695 | |||
2508abd5ad | |||
149cd3a3a3 | |||
1f47f361eb | |||
d89cbe5ba3 | |||
02c3ee63a1 | |||
34d9601e6e | |||
5a1e642177 | |||
313d1e756c | |||
7a3cc674f0 | |||
08d8116e31 | |||
017580fdaa | |||
0edc11b585 | |||
155c4d4b90 | |||
56a8e735b6 | |||
9c8d195880 | |||
e6f7904344 | |||
6aca273d89 | |||
e3655b5115 | |||
1078267db5 | |||
27bb8c7149 | |||
868da2ddac | |||
7399ff7bbd | |||
e0f7856e6f | |||
a52a9cdc8d | |||
d1ae4dd305 | |||
e361e757da | |||
ca78b46723 | |||
2e2c66b978 | |||
5e4bad7bc4 | |||
debf45ae46 | |||
e53492850f | |||
978e072d29 | |||
5021bad597 | |||
bcb55f6255 | |||
c3024ce335 | |||
2f9947c8e4 | |||
35c5d7bf70 | |||
bf34f341fc | |||
a42a42885e | |||
47cc0e3ae6 | |||
06c005a449 | |||
190ab9ae51 | |||
f208847f54 | |||
f431d179aa | |||
fd4a5dc38e | |||
e6e2221d8b | |||
3c64367583 | |||
5e514721ff | |||
88c76c787e | |||
3d2d839d0b | |||
8d8f19d951 | |||
96ffed0984 | |||
43ae3eb61d | |||
6b23cf8d88 | |||
e9d1022eb4 | |||
42d95bd77a | |||
e959dca048 | |||
862aa19017 | |||
5eb8c4b054 | |||
1940434447 | |||
4cd6f89a5a | |||
7f2ae880d5 | |||
06aee5bc37 | |||
1cb38ce146 | |||
3eeee022fd | |||
1e2418ae37 | |||
97f231b4e7 | |||
bf50da4ee2 | |||
f6b177df4e | |||
b8de403958 | |||
31a8584685 | |||
384beb888a | |||
52725702e2 | |||
8cd45f1139 | |||
73c206d14a | |||
bfb896f716 | |||
f2148d99ae |
21
.travis.yml
Normal file
21
.travis.yml
Normal file
@ -0,0 +1,21 @@
|
||||
# Disallowing packages: openvpn
|
||||
# If you require these packages, please review the package approval process at: https://github.com/travis-ci/apt-package-whitelist#package-approval-process
|
||||
#addons:
|
||||
# apt:
|
||||
# sources:
|
||||
# - ubuntu-toolchain-r-test
|
||||
# packages:
|
||||
# - openvpn
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
before_install:
|
||||
- docker --version
|
||||
- docker build -t kylemanna/openvpn .
|
||||
- docker inspect kylemanna/openvpn
|
||||
- docker run kylemanna/openvpn openvpn --version || true # why does it returns 1?
|
||||
- docker run kylemanna/openvpn openssl version
|
||||
|
||||
script:
|
||||
- pushd tests && for i in *.sh; do "./$i"; done && popd
|
@ -6,11 +6,11 @@ FROM debian:jessie
|
||||
MAINTAINER Kyle Manna <kyle@kylemanna.com>
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y openvpn iptables git-core && \
|
||||
apt-get install -y openvpn iptables curl && \
|
||||
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
|
||||
# Update checkout to use tags when v3.0 is finally released
|
||||
RUN git clone --depth 1 --branch v3.0.0-rc2 https://github.com/OpenVPN/easy-rsa.git /usr/local/share/easy-rsa && \
|
||||
RUN mkdir -p /usr/local/share/easy-rsa && \
|
||||
curl -L https://github.com/OpenVPN/easy-rsa/archive/v3.0.0.tar.gz | tar xzf - --strip=1 -C /usr/local/share/easy-rsa easy-rsa-3.0.0/easyrsa3 && \
|
||||
ln -s /usr/local/share/easy-rsa/easyrsa3/easyrsa /usr/local/bin
|
||||
|
||||
# Needed by scripts
|
||||
@ -21,7 +21,7 @@ ENV EASYRSA_VARS_FILE $OPENVPN/vars
|
||||
|
||||
VOLUME ["/etc/openvpn"]
|
||||
|
||||
# Internally uses port 1194, remap using docker
|
||||
# Internally uses port 1194/udp, remap using `docker run -p 443:1194/tcp`
|
||||
EXPOSE 1194/udp
|
||||
|
||||
WORKDIR /etc/openvpn
|
||||
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Kyle Manna
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
54
README.md
54
README.md
@ -1,8 +1,20 @@
|
||||
# OpenVPN for Docker
|
||||
|
||||
[](https://travis-ci.org/kylemanna/docker-openvpn)
|
||||
|
||||
OpenVPN server in a Docker container complete with an EasyRSA PKI CA.
|
||||
|
||||
Extensively tested on [Digital Ocean](https://www.digitalocean.com/?refcode=d19f7fe88c94).
|
||||
Extensively tested on [Digital Ocean $5/mo node](http://bit.ly/1C7cKr3) and has
|
||||
a corresponding [Digital Ocean Community Tutorial](http://bit.ly/1AGUZkq).
|
||||
|
||||
#### Upstream Links
|
||||
|
||||
* Docker Registry @ [kylemanna/openvpn](https://registry.hub.docker.com/u/kylemanna/openvpn)
|
||||
* GitHub @ [kylemanna/docker-openvpn](https://github.com/kylemanna/docker-openvpn)
|
||||
|
||||
#### Example Service
|
||||
|
||||
* [backroad.io](http://beta.backroad.io?utm_source=kylemanna/openvpn&utm_medium=readme&utm_campaign=20150621) - powered by *kylemanna/openvpn*
|
||||
|
||||
## Quick Start
|
||||
|
||||
@ -10,9 +22,9 @@ Extensively tested on [Digital Ocean](https://www.digitalocean.com/?refcode=d19f
|
||||
|
||||
docker run --name $OVPN_DATA -v /etc/openvpn busybox
|
||||
|
||||
* Initalize the `$OVPN_DATA` container that will hold the configuration files and certificates
|
||||
* Initialize the `$OVPN_DATA` container that will hold the configuration files and certificates
|
||||
|
||||
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM:1194
|
||||
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM
|
||||
docker run --volumes-from $OVPN_DATA --rm -it kylemanna/openvpn ovpn_initpki
|
||||
|
||||
* Start OpenVPN server process
|
||||
@ -21,7 +33,7 @@ Extensively tested on [Digital Ocean](https://www.digitalocean.com/?refcode=d19f
|
||||
|
||||
docker run --volumes-from $OVPN_DATA -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
|
||||
|
||||
- On Docker older than 1.2 version
|
||||
- On Docker older than version 1.2
|
||||
|
||||
docker run --volumes-from $OVPN_DATA -d -p 1194:1194/udp --privileged kylemanna/openvpn
|
||||
|
||||
@ -33,6 +45,9 @@ Extensively tested on [Digital Ocean](https://www.digitalocean.com/?refcode=d19f
|
||||
|
||||
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
|
||||
|
||||
* Create an environment variable with the name DEBUG and value of 1 to enable debug output (using "docker -e").
|
||||
|
||||
docker run --volumes-from $OVPN_DATA -d -p 1194:1194/udp --privileged -e DEBUG=1 kylemanna/openvpn
|
||||
|
||||
## How Does It Work?
|
||||
|
||||
@ -96,18 +111,45 @@ packets, etc).
|
||||
simplicity. It's highly recommended to secure the CA key with some
|
||||
passphrase to protect against a filesystem compromise. A more secure system
|
||||
would put the EasyRSA PKI CA on an offline system (can use the same Docker
|
||||
image to accomplish this).
|
||||
image and the script [`ovpn_copy_server_files`](/docs/paranoid.md) to accomplish this).
|
||||
* It would be impossible for an adversary to sign bad or forged certificates
|
||||
without first cracking the key's passphase should the adversary have root
|
||||
access to the filesystem.
|
||||
* The EasyRSA `build-client-full` command will generate and leave keys on the
|
||||
server, again possible to compromise and steal the keys. The keys generated
|
||||
need to signed by the CA which the user hopefully configured with a passphrase
|
||||
need to be signed by the CA which the user hopefully configured with a passphrase
|
||||
as described above.
|
||||
* Assuming the rest of the Docker container's filesystem is secure, TLS + PKI
|
||||
security should prevent any malicious host from using the VPN.
|
||||
|
||||
|
||||
## Benefits of Running Inside a Docker Container
|
||||
|
||||
### The Entire Daemon and Dependencies are in the Docker Image
|
||||
|
||||
This means that it will function correctly (after Docker itself is setup) on
|
||||
all distributions Linux distributions such as: Ubuntu, Arch, Debian, Fedora,
|
||||
etc. Furthermore, an old stable server can run a bleeding edge OpenVPN server
|
||||
without having to install/muck with library dependencies (i.e. run latest
|
||||
OpenVPN with latest OpenSSL on Ubuntu 12.04 LTS).
|
||||
|
||||
### It Doesn't Stomp All Over the Server's Filesystem
|
||||
|
||||
Everything for the Docker container is contained in two images: the ephemeral
|
||||
run time image (kylemanna/openvpn) and the data image (using busybox as a
|
||||
base). To remove it, remove the two Docker images and corresponding containers
|
||||
and it's all gone. This also makes it easier to run multiple servers since
|
||||
each lives in the bubble of the container (of course multiple IPs or separate
|
||||
ports are needed to communicate with the world).
|
||||
|
||||
### Some (arguable) Security Benefits
|
||||
|
||||
At the simplest level compromising the container may prevent additional
|
||||
compromise of the server. There are many arguments surrounding this, but the
|
||||
take away is that it certainly makes it more difficult to break out of the
|
||||
container. People are actively working on Linux containers to make this more
|
||||
of a guarantee in the future.
|
||||
|
||||
## Differences from jpetazzo/dockvpn
|
||||
|
||||
* No longer uses serveconfig to distribute the configuration via https
|
||||
|
@ -4,7 +4,11 @@
|
||||
# Import/export EasyRSA default settings
|
||||
#
|
||||
|
||||
set -ex
|
||||
if [ "$DEBUG" == "1" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "No command provided"
|
||||
|
41
bin/ovpn_copy_server_files
Executable file
41
bin/ovpn_copy_server_files
Executable file
@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
## @licence MIT <http://opensource.org/licenses/MIT>
|
||||
## @author Copyright (C) 2015 Robin Schneider <ypid@riseup.net>
|
||||
|
||||
set -e
|
||||
|
||||
if [ -z "$OPENVPN" ]; then
|
||||
export OPENVPN="$PWD"
|
||||
fi
|
||||
if ! source "$OPENVPN/ovpn_env.sh"; then
|
||||
echo "Could not source $OPENVPN/ovpn_env.sh."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARGET="$OPENVPN/server"
|
||||
if [ -n "$1" ]; then
|
||||
TARGET="$1"
|
||||
fi
|
||||
mkdir -p "${TARGET}"
|
||||
|
||||
## Ensure that no other keys then the one for the server is present.
|
||||
rm -rf "$TARGET/pki/private" "$TARGET/pki/issued"
|
||||
|
||||
FILES=(
|
||||
"openvpn.conf"
|
||||
"ovpn_env.sh"
|
||||
"pki/private/${OVPN_CN}.key"
|
||||
"pki/issued/${OVPN_CN}.crt"
|
||||
"pki/dh.pem"
|
||||
"pki/ta.key"
|
||||
"pki/ca.crt"
|
||||
)
|
||||
|
||||
# rsync isn't available to keep size down
|
||||
# cp --parents isn't in busybox version
|
||||
# hack the directory structure with tar
|
||||
tar cf - -C "${OPENVPN}" "${FILES[@]}" | tar xvf - -C "${TARGET}"
|
||||
|
||||
mkdir -p "$TARGET/ccd"
|
||||
|
||||
echo "Created the openvpn configuration for the server: $TARGET"
|
@ -41,24 +41,53 @@ usage() {
|
||||
echo "optional arguments:"
|
||||
echo " -d Disable NAT routing and default route"
|
||||
echo " -c Enable client-to-client option"
|
||||
echo " -D Disable built in external dns (google dns)"
|
||||
echo " -N Configure NAT to access external server network"
|
||||
echo " -m Set client MTU"
|
||||
echo " -t Use TAP device (instead of TUN device)"
|
||||
echo " -T Encrypt packets with the given cipher algorithm instead of the default one (tls-cipher)."
|
||||
echo " -C A list of allowable TLS ciphers delimited by a colon (cipher)."
|
||||
echo " -a Authenticate packets with HMAC using the given message digest algorithm (auth)."
|
||||
}
|
||||
|
||||
set -ex
|
||||
if [ "$DEBUG" == "1" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
OVPN_ENV=$OPENVPN/ovpn_env.sh
|
||||
OVPN_SERVER=192.168.255.0/24
|
||||
OVPN_DEFROUTE=1
|
||||
OVPN_NAT=0
|
||||
OVPN_DNS=1
|
||||
OVPN_DEVICE="tun"
|
||||
OVPN_DEVICEN=0
|
||||
OVPN_ROUTES=()
|
||||
TMP_ROUTES=()
|
||||
OVPN_PUSH=()
|
||||
TMP_PUSH=()
|
||||
OVPN_TLS_CIPHER=''
|
||||
OVPN_CIPHER=''
|
||||
OVPN_AUTH=''
|
||||
|
||||
# Import defaults if present
|
||||
[ -r "$OVPN_ENV" ] && source "$OVPN_ENV"
|
||||
|
||||
# Parse arguments
|
||||
while getopts ":r:s:du:cp:" opt; do
|
||||
while getopts ":a:C:T:r:s:du:cp:DNm:t" opt; do
|
||||
case $opt in
|
||||
a)
|
||||
OVPN_AUTH="$OPTARG"
|
||||
;;
|
||||
C)
|
||||
OVPN_CIPHER="$OPTARG"
|
||||
;;
|
||||
T)
|
||||
OVPN_TLS_CIPHER="$OPTARG"
|
||||
;;
|
||||
r)
|
||||
OVPN_ROUTES+=("$OPTARG")
|
||||
TMP_ROUTES+=("$OPTARG")
|
||||
;;
|
||||
s)
|
||||
OVPN_SERVER=$OPTARG
|
||||
@ -73,7 +102,19 @@ while getopts ":r:s:du:cp:" opt; do
|
||||
OVPN_CLIENT_TO_CLIENT=1
|
||||
;;
|
||||
p)
|
||||
OVPN_PUSH+=("$OPTARG")
|
||||
TMP_PUSH+=("$OPTARG")
|
||||
;;
|
||||
D)
|
||||
OVPN_DNS=0
|
||||
;;
|
||||
N)
|
||||
OVPN_NAT=1
|
||||
;;
|
||||
m)
|
||||
OVPN_MTU=$OPTARG
|
||||
;;
|
||||
t)
|
||||
OVPN_DEVICE="tap"
|
||||
;;
|
||||
\?)
|
||||
set +x
|
||||
@ -90,6 +131,11 @@ while getopts ":r:s:du:cp:" opt; do
|
||||
esac
|
||||
done
|
||||
|
||||
# if new routes were not defined with -r, use default
|
||||
[ ${#TMP_ROUTES[@]} -gt 0 ] && OVPN_ROUTES=("${TMP_ROUTES[@]}")
|
||||
|
||||
# if new push directives were not defined with -p, use default
|
||||
[ ${#TMP_PUSH[@]} -gt 0 ] && OVPN_PUSH=("${TMP_PUSH[@]}")
|
||||
|
||||
# Server name is in the form "udp://vpn.example.com:1194"
|
||||
if [[ "$OVPN_SERVER_URL" =~ ^((udp|tcp)://)?([0-9a-zA-Z\.\-]+)(:([0-9]+))?$ ]]; then
|
||||
@ -110,7 +156,8 @@ fi
|
||||
|
||||
export OVPN_SERVER OVPN_ROUTES OVPN_DEFROUTE
|
||||
export OVPN_SERVER_URL OVPN_ENV OVPN_PROTO OVPN_CN OVPN_PORT
|
||||
export OVPN_CLIENT_TO_CLIENT OVPN_PUSH
|
||||
export OVPN_CLIENT_TO_CLIENT OVPN_PUSH OVPN_NAT OVPN_DNS OVPN_MTU OVPN_DEVICE
|
||||
export OVPN_TLS_CIPHER OVPN_CIPHER OVPN_AUTH
|
||||
|
||||
# Preserve config
|
||||
if [ -f "$OVPN_ENV" ]; then
|
||||
@ -130,7 +177,6 @@ fi
|
||||
cat > "$conf" <<EOF
|
||||
server $(getroute $OVPN_SERVER)
|
||||
verb 3
|
||||
#duplicate-cn
|
||||
key $EASYRSA_PKI/private/${OVPN_CN}.key
|
||||
ca $EASYRSA_PKI/ca.crt
|
||||
cert $EASYRSA_PKI/issued/${OVPN_CN}.crt
|
||||
@ -140,20 +186,24 @@ key-direction 0
|
||||
keepalive 10 60
|
||||
persist-key
|
||||
persist-tun
|
||||
push "dhcp-option DNS 8.8.4.4"
|
||||
push "dhcp-option DNS 8.8.8.8"
|
||||
|
||||
proto $OVPN_PROTO
|
||||
# Rely on Docker to do port mapping, internally always 1194
|
||||
port 1194
|
||||
dev tun0
|
||||
dev $OVPN_DEVICE$OVPN_DEVICEN
|
||||
status /tmp/openvpn-status.log
|
||||
|
||||
client-config-dir $OPENVPN/ccd
|
||||
user nobody
|
||||
group nogroup
|
||||
EOF
|
||||
|
||||
[ -n "$OVPN_CLIENT_TO_CLIENT" ] && echo "client-to-client" >> "$conf"
|
||||
[ -n "$OVPN_TLS_CIPHER" ] && echo "tls-cipher $OVPN_TLS_CIPHER" >> "$conf"
|
||||
[ -n "$OVPN_CIPHER" ] && echo "cipher $OVPN_CIPHER" >> "$conf"
|
||||
[ -n "$OVPN_AUTH" ] && echo "auth $OVPN_AUTH" >> "$conf"
|
||||
|
||||
[ -n "$OVPN_CLIENT_TO_CLIENT" ] && echo "client-to-client" >> "$conf"
|
||||
[ "$OVPN_DNS" == "1" ] && echo push "dhcp-option DNS 8.8.4.4" >> "$conf"
|
||||
[ "$OVPN_DNS" == "1" ] && echo push "dhcp-option DNS 8.8.8.8" >> "$conf"
|
||||
# Append Routes
|
||||
for i in "${OVPN_ROUTES[@]}"; do
|
||||
# If user passed "0" skip this, assume no extra routes
|
||||
@ -166,8 +216,16 @@ for i in "${OVPN_PUSH[@]}"; do
|
||||
echo push \"$i\" >> "$conf"
|
||||
done
|
||||
|
||||
# Clean-up duplicate configs (always return success)
|
||||
diff -q "$bak_env" "$OVPN_ENV" 2> /dev/null && rm "$bak_env" || true
|
||||
diff -q "$bak" "$conf" 2> /dev/null && rm "$bak" || true
|
||||
set +e
|
||||
|
||||
# Clean-up duplicate configs
|
||||
if diff -q "$bak_env" "$OVPN_ENV" 2>/dev/null; then
|
||||
echo "Removing duplicate back-up: $bak_env"
|
||||
rm -fv "$bak_env"
|
||||
fi
|
||||
if diff -q "$bak" "$conf" 2>/dev/null; then
|
||||
echo "Removing duplicate back-up: $bak"
|
||||
rm -fv "$bak"
|
||||
fi
|
||||
|
||||
echo "Successfully generated config"
|
||||
|
@ -4,44 +4,108 @@
|
||||
# Get an OpenVPN client configuration file
|
||||
#
|
||||
|
||||
set -ex
|
||||
if [ "$DEBUG" == "1" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
source "$OPENVPN/ovpn_env.sh"
|
||||
cn=$1
|
||||
set -e
|
||||
|
||||
if [ -z "$OPENVPN" ]; then
|
||||
export OPENVPN="$PWD"
|
||||
fi
|
||||
if ! source "$OPENVPN/ovpn_env.sh"; then
|
||||
echo "Could not source $OPENVPN/ovpn_env.sh."
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$EASYRSA_PKI" ]; then
|
||||
export EASYRSA_PKI="$OPENVPN/pki"
|
||||
fi
|
||||
|
||||
cn="$1"
|
||||
parm="$2"
|
||||
|
||||
if [ ! -f "$EASYRSA_PKI/private/${cn}.key" ]; then
|
||||
echo "Unable to find ${cn}, please try again or generate the key first"
|
||||
echo "Unable to find \"${cn}\", please try again or generate the key first" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
get_client_config() {
|
||||
mode="$1"
|
||||
echo "
|
||||
client
|
||||
nobind
|
||||
dev tun
|
||||
dev $OVPN_DEVICE
|
||||
remote-cert-tls server
|
||||
|
||||
remote $OVPN_CN $OVPN_PORT $OVPN_PROTO
|
||||
"
|
||||
if [ "$mode" == "combined" ]; then
|
||||
echo "
|
||||
<key>
|
||||
$(cat $EASYRSA_PKI/private/${cn}.key)
|
||||
</key>
|
||||
<cert>
|
||||
$(cat $EASYRSA_PKI/issued/${cn}.crt)
|
||||
$(openssl x509 -in $EASYRSA_PKI/issued/${cn}.crt)
|
||||
</cert>
|
||||
<ca>
|
||||
$(cat $EASYRSA_PKI/ca.crt)
|
||||
</ca>
|
||||
<dh>
|
||||
$(cat $EASYRSA_PKI/dh.pem)
|
||||
</dh>
|
||||
<tls-auth>
|
||||
$(cat $EASYRSA_PKI/ta.key)
|
||||
</tls-auth>
|
||||
key-direction 1
|
||||
"
|
||||
elif [ "$mode" == "separated" ]; then
|
||||
echo "
|
||||
key ${cn}.key
|
||||
ca ca.crt
|
||||
cert ${cn}.crt
|
||||
tls-auth ta.key 1
|
||||
$OVPN_ADDITIONAL_CLIENT_CONFIG
|
||||
"
|
||||
fi
|
||||
|
||||
<connection>
|
||||
remote $OVPN_CN $OVPN_PORT $OVPN_PROTO
|
||||
</connection>
|
||||
EOF
|
||||
if [ "$OVPN_DEFROUTE" != "0" ];then
|
||||
echo "redirect-gateway def1"
|
||||
fi
|
||||
|
||||
if [ "$OVPN_DEFROUTE" != "0" ];then
|
||||
echo "redirect-gateway def1"
|
||||
fi
|
||||
if [ -n "$OVPN_MTU" ]; then
|
||||
echo "tun-mtu $OVPN_MTU"
|
||||
fi
|
||||
|
||||
if [ -n "$OVPN_TLS_CIPHER" ]; then
|
||||
echo "tls-cipher $OVPN_TLS_CIPHER"
|
||||
fi
|
||||
|
||||
if [ -n "$OVPN_CIPHER" ]; then
|
||||
echo "cipher $OVPN_CIPHER"
|
||||
fi
|
||||
|
||||
if [ -n "$OVPN_AUTH" ]; then
|
||||
echo "auth $OVPN_AUTH"
|
||||
fi
|
||||
}
|
||||
|
||||
dir="$OPENVPN/clients/$cn"
|
||||
case "$parm" in
|
||||
"separated")
|
||||
mkdir -p "$dir"
|
||||
get_client_config "$parm" > "$dir/${cn}.ovpn"
|
||||
cp "$EASYRSA_PKI/private/${cn}.key" "$dir/${cn}.key"
|
||||
cp "$EASYRSA_PKI/ca.crt" "$dir/ca.crt"
|
||||
cp "$EASYRSA_PKI/issued/${cn}.crt" "$dir/${cn}.crt"
|
||||
cp "$EASYRSA_PKI/ta.key" "$dir/ta.key"
|
||||
;;
|
||||
"" | "combined")
|
||||
get_client_config "combined"
|
||||
;;
|
||||
"combined-save")
|
||||
get_client_config "combined" > "$dir/${cn}-combined.ovpn"
|
||||
;;
|
||||
*)
|
||||
echo "This script can produce the client configuration in to formats:" >&2
|
||||
echo " 1. combined (default): All needed configuration and cryptographic material is in one file (Use \"combined-save\" to write the configuration file in the same path as the separated parameter does)." >&2
|
||||
echo " 2. separated: Separated files." >&2
|
||||
echo "Please specific one of those options as second parameter." >&2
|
||||
;;
|
||||
esac
|
||||
|
25
bin/ovpn_getclient_all
Executable file
25
bin/ovpn_getclient_all
Executable file
@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
## @licence MIT <http://opensource.org/licenses/MIT>
|
||||
## @author Copyright (C) 2015 Robin Schneider <ypid@riseup.net>
|
||||
|
||||
if [ -z "$OPENVPN" ]; then
|
||||
export OPENVPN="$PWD"
|
||||
fi
|
||||
if ! source "$OPENVPN/ovpn_env.sh"; then
|
||||
echo "Could not source $OPENVPN/ovpn_env.sh."
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$EASYRSA_PKI" ]; then
|
||||
export EASYRSA_PKI="$OPENVPN/pki"
|
||||
fi
|
||||
|
||||
pushd "$EASYRSA_PKI"
|
||||
for name in issued/*.crt; do
|
||||
name=${name%.crt}
|
||||
name=${name#issued/}
|
||||
if [ "$name" != "$OVPN_CN" ]; then
|
||||
ovpn_getclient "$name" separated
|
||||
ovpn_getclient "$name" combined-save
|
||||
fi
|
||||
done
|
||||
popd
|
@ -4,7 +4,11 @@
|
||||
# Initialize the EasyRSA PKI
|
||||
#
|
||||
|
||||
set -ex
|
||||
if [ "$DEBUG" == "1" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
source "$OPENVPN/ovpn_env.sh"
|
||||
|
||||
|
52
bin/ovpn_run
52
bin/ovpn_run
@ -4,7 +4,14 @@
|
||||
# Run the OpenVPN server normally
|
||||
#
|
||||
|
||||
set -ex
|
||||
if [ "$DEBUG" == "1" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
# Build runtime arguments array based on environment
|
||||
ARGS=("--config" "$OPENVPN/openvpn.conf")
|
||||
|
||||
source "$OPENVPN/ovpn_env.sh"
|
||||
|
||||
@ -13,22 +20,47 @@ if [ ! -c /dev/net/tun ]; then
|
||||
mknod /dev/net/tun c 10 200
|
||||
fi
|
||||
|
||||
if [ ! -d "$OPENVPN/ccd" ]; then
|
||||
mkdir -p /etc/openvpn/ccd
|
||||
if [ -d "$OPENVPN/ccd" ]; then
|
||||
ARGS+=("--client-config-dir" "$OPENVPN/ccd")
|
||||
fi
|
||||
|
||||
# When using --net=host, use this to specify nat device.
|
||||
[ -z "$OVPN_NATDEVICE" ] && OVPN_NATDEVICE=eth0
|
||||
|
||||
# Setup NAT forwarding if requested
|
||||
if [ "$OVPN_DEFROUTE" != "0" ];then
|
||||
iptables -t nat -C POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE || {
|
||||
iptables -t nat -A POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE
|
||||
if [ "$OVPN_DEFROUTE" != "0" ] || [ "$OVPN_NAT" == "1" ] ; then
|
||||
iptables -t nat -C POSTROUTING -s $OVPN_SERVER -o $OVPN_NATDEVICE -j MASQUERADE || {
|
||||
iptables -t nat -A POSTROUTING -s $OVPN_SERVER -o $OVPN_NATDEVICE -j MASQUERADE
|
||||
}
|
||||
for i in "${OVPN_ROUTES[@]}"; do
|
||||
iptables -t nat -C POSTROUTING -s "$i" -o eth0 -j MASQUERADE || {
|
||||
iptables -t nat -A POSTROUTING -s "$i" -o eth0 -j MASQUERADE
|
||||
iptables -t nat -C POSTROUTING -s "$i" -o $OVPN_NATDEVICE -j MASQUERADE || {
|
||||
iptables -t nat -A POSTROUTING -s "$i" -o $OVPN_NATDEVICE -j MASQUERADE
|
||||
}
|
||||
done
|
||||
fi
|
||||
|
||||
conf="$OPENVPN/openvpn.conf"
|
||||
# Use a hacky hardlink as the CRL Needs to be readable by the user/group
|
||||
# OpenVPN is running as. Only pass arguments to OpenVPN if it's found.
|
||||
if [ -r "$EASYRSA_PKI/crl.pem" ]; then
|
||||
if [ ! -r "$OPENVPN/crl.pem" ]; then
|
||||
ln "$EASYRSA_PKI/crl.pem" "$OPENVPN/crl.pem"
|
||||
chmod 644 "$OPENVPN/crl.pem"
|
||||
fi
|
||||
ARGS+=("--crl-verify" "$OPENVPN/crl.pem")
|
||||
fi
|
||||
|
||||
openvpn --config "$conf"
|
||||
ip -6 route show default 2>/dev/null
|
||||
if [ $? = 0 ]; then
|
||||
echo "Enabling IPv6 Forwarding"
|
||||
# If this fails, ensure the docker container is run with --privileged
|
||||
# Could be side stepped with `ip netns` madness to drop privileged flag
|
||||
|
||||
sysctl net.ipv6.conf.default.forwarding=1 || echo "Failed to enable IPv6 Forwarding default"
|
||||
sysctl net.ipv6.conf.all.forwarding=1 || echo "Failed to enable IPv6 Forwarding"
|
||||
fi
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
exec openvpn "$@"
|
||||
else
|
||||
exec openvpn ${ARGS[@]}
|
||||
fi
|
||||
|
@ -3,7 +3,10 @@
|
||||
#
|
||||
# Get OpenVPN server status
|
||||
#
|
||||
if [ "$DEBUG" == "1" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
set -ex
|
||||
set -e
|
||||
|
||||
tail -F /tmp/openvpn-status.log
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Advanced Configurations
|
||||
|
||||
The ovpn_genconfig script is intended for simple configurations that apply to the majority of the users. If your use case isn't general, it likely won't be supported. This document aims to explain how to work around that.
|
||||
The [`ovpn_genconfig`](/bin/ovpn_genconfig) script is intended for simple configurations that apply to the majority of the users. If your use case isn't general, it likely won't be supported. This document aims to explain how to work around that.
|
||||
|
||||
## Create host volume mounts rather than data volumes
|
||||
|
||||
@ -18,4 +18,3 @@ The ovpn_genconfig script is intended for simple configurations that apply to th
|
||||
* Start the server with:
|
||||
|
||||
docker run -v $PWD:/etc/openvpn -d -p 1194:1194/udp --privileged kylemanna/openvpn
|
||||
|
||||
|
@ -2,17 +2,19 @@
|
||||
|
||||
## Security
|
||||
|
||||
The resulting archive from this back-up contains all credential to impersonate the server at a minimum. If the client private keys are generated using the EasyRSA utility then it also contains the client certificates that could be used to impersonate said clients. Most importantly, if the certificate authority key is in this archive (as it is given the quick start directions), then a adversary could generate certificates at will.
|
||||
The resulting archive from this backup contains all credential to impersonate the server at a minimum. If the client's private keys are generated using the EasyRSA utility then it also contains the client certificates that could be used to impersonate said clients. Most importantly, if the certificate authority key is in this archive (as it is given the quick start directions), then a adversary could generate certificates at will.
|
||||
|
||||
I'd recommend encrypting the archive with something strong (e.g. gpg or openssl + AES). For the paranoid keep backup offline. For the truly paranoid users, never keep any keys (i.e. client and certificate authority) in the docker container to begin with :).
|
||||
I'd recommend encrypting the archive with something strong (e.g. gpg or openssl + AES). For the paranoid keep backup offline. For the [truly paranoid users](/docs/paranoid.md), never keep any keys (i.e. client and certificate authority) in the docker container to begin with :).
|
||||
|
||||
|
||||
TL;DR Protect the resulting archive file, by ensure there is very limited access to it.
|
||||
**TL;DR Protect the resulting archive file. Ensure there is very limited access to it.**
|
||||
|
||||
## Backup to Archive
|
||||
|
||||
docker run --volumes-from $OVPN_DATA --rm busybox tar -cvf - -C /etc openvpn | xz > openvpn-backup.tar.xz
|
||||
|
||||
## Retore to New Image
|
||||
## Restore to New Container
|
||||
|
||||
Assumes an existing container named `$OVPN_DATA` to extract the data over the top.
|
||||
|
||||
xzcat openvpn-backup.tar.xz | docker run --name $OVPN_DATA -v /etc/openvpn -i busybox tar -xvf - -C /etc
|
||||
|
36
docs/clients.md
Normal file
36
docs/clients.md
Normal file
@ -0,0 +1,36 @@
|
||||
# Advanced Client Management
|
||||
|
||||
## Client Configuration Mode
|
||||
|
||||
The [`ovpn_getclient`](/bin/ovpn_getclient) can produce two different versions of the configuration.
|
||||
|
||||
1. combined (default): All needed configuration and cryptographic material is in one file (Use "combined-save" to write the configuration file in the same path as the separated parameter does).
|
||||
2. separated: Separated files.
|
||||
|
||||
Note that some client software might be picky about which configuration format it accepts.
|
||||
|
||||
## Batch Mode
|
||||
|
||||
If you have more than a few clients, you will want to generate and update your client configuration in batch. For this task the script [`ovpn_getclient_all`](/bin/ovpn_getclient_all) was written, which writes out the configuration for each client to a separate directory called `clients/$cn`.
|
||||
|
||||
Execute the following to generate the configuration for all clients:
|
||||
|
||||
docker run --rm -it --volumes-from $OVPN_DATA --volume /tmp/openvpn_clients:/etc/openvpn/clients kylemanna/openvpn ovpn_getclient_all
|
||||
|
||||
After doing so, you will find the following files in each of the `$cn` directories:
|
||||
|
||||
ca.crt
|
||||
$cn-combined.ovpn # Combined configuration file format. If your client recognices this file then only this file is needed.
|
||||
$cn.ovpn # Separated configuration. This configuration file requires the other files ca.crt dh.pem $cn.crt $cn.key ta.key
|
||||
$cn.crt
|
||||
$cn.key
|
||||
ta.key
|
||||
|
||||
## Revoking Client Certificates
|
||||
|
||||
Revoke `client1`'s certificate and generate the certificate revocation list (CRL):
|
||||
|
||||
docker run --rm -it --volumes-from $OVPN_DATA kylemanna/openvpn easyrsa revoke client1
|
||||
docker run --rm -it --volumes-from $OVPN_DATA kylemanna/openvpn easyrsa gen-crl
|
||||
|
||||
The OpenVPN server will read this change every time a client connects (no need to restart server) and deny clients access using revoked certificates.
|
52
docs/docker.md
Normal file
52
docs/docker.md
Normal file
@ -0,0 +1,52 @@
|
||||
# Install Latest Docker Service
|
||||
|
||||
Docker included with some distributions lags far behind upstream. This guide aims to provide a quick and reliable way to install or update it.
|
||||
|
||||
It is recommended to use platforms that support systemd as future versions of this docker image may require systemd to help with some tasks:
|
||||
|
||||
* Fedora
|
||||
* Debian 8.1+
|
||||
|
||||
## Debian / Ubuntu
|
||||
|
||||
### Step 1 — Set Up Docker
|
||||
|
||||
Docker is moving fast and Debian / Ubuntu's long term support (LTS) policy doesn't keep up. To work around this we'll install a PPA that will get us the latest version of Docker. For Debian Jessie users, just install docker.io from jessie-backports.
|
||||
|
||||
Ensure dependencies are installed:
|
||||
|
||||
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
|
||||
|
||||
Add the upstream Docker repository package signing key. The apt-key command uses elevated privileges via sudo, so a password prompt for the user's password may appear:
|
||||
|
||||
curl -L https://get.docker.com/gpg | sudo apt-key add -
|
||||
|
||||
Add the upstream Docker repository to the system list:
|
||||
|
||||
echo deb https://get.docker.io/ubuntu docker main | sudo tee /etc/apt/sources.list.d/docker.list
|
||||
|
||||
Update the package list and install the Docker package:
|
||||
|
||||
sudo apt-get update && sudo apt-get install -y lxc-docker
|
||||
|
||||
Add your user to the `docker` group to enable communication with the Docker daemon as a normal user, where `$USER` is your username. Exit and log in again for the new group to take effect:
|
||||
|
||||
sudo usermod -aG docker $USER
|
||||
|
||||
After **re-logging in** verify the group membership using the id command. The expected response should include docker like the following example:
|
||||
|
||||
uid=1001(test0) gid=1001(test0) groups=1001(test0),27(sudo),999(docker)
|
||||
|
||||
### Step 2 — Test Docker
|
||||
|
||||
Run a Debian jessie docker container:
|
||||
|
||||
docker run --rm -it debian:jessie bash -l
|
||||
|
||||
Once inside the container you'll see the `root@<container id>:/#` prompt signifying that the current shell is in a Docker container. To confirm that it's different from the host, check the version of Debian running in the container:
|
||||
|
||||
cat /etc/issue.net
|
||||
|
||||
Expected result:
|
||||
|
||||
Debian GNU/Linux 8
|
14
docs/faqs.md
Normal file
14
docs/faqs.md
Normal file
@ -0,0 +1,14 @@
|
||||
# Frequently Asked Questions
|
||||
|
||||
## How do I edit `openvpn.conf`?
|
||||
|
||||
Use a Docker image with a text editor pre-installed (i.e. Ubuntu) and connect the volume container:
|
||||
|
||||
docker run --volumes-from $OVPN_DATA --rm -it ubuntu vi /etc/openvpn/openvpn.conf
|
||||
|
||||
|
||||
## Why not keep everything in one image?
|
||||
|
||||
The run-time image (`kylemanna/openvpn`) is intended to be an ephemeral image. Nothing should be saved in it so that it can be re-downloaded and re-run when updates are pushed (i.e. newer version of OpenVPN or even Debian). The data container contains all this data and is attached at run time providing a safe home.
|
||||
|
||||
If it was all in one container, an upgrade would require a few steps to extract all the data, perform some upgrade import, and re-run. This technique is also prone to people losing their EasyRSA PKI when they forget where it was. With everything in the data container upgrading is as simple as re-running `docker pull kylemanna/openvpn` and then `docker run ... kylemanna/openvpn`.
|
94
docs/ipv6.md
Normal file
94
docs/ipv6.md
Normal file
@ -0,0 +1,94 @@
|
||||
# IPv6 Support
|
||||
|
||||
This is a work in progress, more polish to follow.
|
||||
|
||||
## Tunnel IPv6 Address To OpenVPN Clients
|
||||
|
||||
This feature is advanced and recommended only for those who already have a functioning IPv4 tunnel and know how IPv6 works.
|
||||
|
||||
Systemd is used to setup a static route and Debian 8.1 or later is recommended as the host distribution. Others probably work, but haven't been tested.
|
||||
|
||||
|
||||
### Step 1 — Setup IPv6 on the Host Machine
|
||||
|
||||
The tutorial uses a free tunnel from [tunnelbroker.net](https://tunnelbroker.net/) to get a /64 and /48 prefix allocated to me. The tunnel endpoint is less then 3 ms away from Digital Ocean's San Francisco datacenter.
|
||||
|
||||
Place the following in `/etc/network/interfaces`. Replace `PUBLIC_IP` with your host's public IPv4 address and replace 2001:db8::2 and 2001:db8::1 with the corresponding tunnel endpoints:
|
||||
|
||||
auto he-ipv6
|
||||
iface he-ipv6 inet6 v4tunnel
|
||||
address 2001:db8::2
|
||||
netmask 64
|
||||
endpoint 72.52.104.74
|
||||
local PUBLIC_IP
|
||||
ttl 255
|
||||
gateway 2001:db8::1
|
||||
|
||||
Bring the interface up:
|
||||
|
||||
ifup he-ipv6
|
||||
|
||||
Test that IPv6 works on the host:
|
||||
|
||||
ping6 google.com
|
||||
|
||||
If this doesn't work, figure it out. It may be necessary to add an firewall rule to allow IP protocol 41 through the firewall.
|
||||
|
||||
|
||||
### Step 2 — Update Docker's Init To Enable IPv6 Support
|
||||
|
||||
Add the `--ipv6` to the Docker daemon invocation.
|
||||
|
||||
On **Ubuntu** and old versions of Debian Append the `--ipv6` argument to the `DOCKER_OPTS` variable in:
|
||||
|
||||
/etc/default/docker
|
||||
|
||||
On modern **systemd** distributions copy the service file and modify it and reload the service:
|
||||
|
||||
sed -e 's:^\(ExecStart.*\):\1 --ipv6:' /lib/systemd/system/docker.service | tee /etc/systemd/system/docker.service
|
||||
systemctl restart docker.service
|
||||
|
||||
|
||||
### Step 3 — Setup the systemd Unit File
|
||||
|
||||
Copy the systemd init file from the docker-openvpn /init directory of the repository and install into `/etc/systemd/system/docker-openvpn.service`
|
||||
|
||||
curl -o /etc/systemd/system/docker-openvpn@.service 'https://raw.githubusercontent.com/kylemanna/docker-openvpn/dev/init/docker-openvpn%40.service'
|
||||
|
||||
Edit the file, replace `IP6_PREFIX` value with the value of your /64 prefix.
|
||||
|
||||
vi /etc/systemd/system/docker-openvpn@.service
|
||||
|
||||
Finally, reload systemd so the changes take affect:
|
||||
|
||||
systemctl daemon-reload
|
||||
|
||||
### Step 4 — Start OpenVPN
|
||||
|
||||
Ensure that OpenVPN has been initialized and configured as described in the top level `README.md`.
|
||||
|
||||
Start the systemd service file specifying the volume container suffix as the instance. For example, `INSTANCE=test0` has a docker volume container named `ovpn-data-test0` and service will create `ovpn-test0` container:
|
||||
|
||||
systemctl start docker-openvpn@test0
|
||||
|
||||
Verify logs if needed:
|
||||
|
||||
systemctl status docker-openvpn@test0
|
||||
docker logs ovpn-test0
|
||||
|
||||
### Step 4 — Modify Client Config for IPv6 Default Route
|
||||
|
||||
Append the default route for the public Internet:
|
||||
|
||||
echo "route-ipv6 2000::/3" >> clientname.ovpn
|
||||
|
||||
### Step 5 — Start up Client
|
||||
|
||||
If all went according to plan, then `ping6 2600::` and `ping6 google.com` should work.
|
||||
|
||||
Fire up a web browser and attempt to navigate to [https://ipv6.google.com](https://ipv6.google.com).
|
||||
|
||||
|
||||
## Connect to the OpenVPN Server Over IPv6
|
||||
|
||||
Not implemented, yet.
|
32
docs/paranoid.md
Normal file
32
docs/paranoid.md
Normal file
@ -0,0 +1,32 @@
|
||||
# Advanced security
|
||||
|
||||
## Keep the CA root key save
|
||||
As mentioned in the [backup section](/docs/backup.md), there are good reasons to not generate the CA and/or leave it on the server. This document describes how you can generate the CA and all your certificates on a secure machine and then copy only the needed files (which never includes the CA root key obviously ;) ) to the server(s) and clients.
|
||||
|
||||
Execute the following commands. Note that you might want to change the volume `$PWD` or use a data docker container for this.
|
||||
|
||||
docker run --net=none --rm -t -i -v $PWD:/etc/openvpn kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM
|
||||
docker run --net=none --rm -t -i -v $PWD:/etc/openvpn kylemanna/openvpn ovpn_initpki
|
||||
docker run --net=none --rm -t -i -v $PWD:/etc/openvpn kylemanna/openvpn ovpn_copy_server_files
|
||||
|
||||
The [`ovpn_copy_server_files`](/bin/ovpn_copy_server_files) script puts all the needed configuration in a subdirectory which defaults to `$OPENVPN/server`. All you need to do now is to copy this directory to the server and you are good to go.
|
||||
|
||||
## Crypto Hardening
|
||||
|
||||
If you want to select the cyphers used by OpenVPN the following parameters of the `ovpn_genconfig` might interest you:
|
||||
|
||||
-T Encrypt packets with the given cipher algorithm instead of the default one (tls-cipher).
|
||||
-C A list of allowable TLS ciphers delimited by a colon (cipher).
|
||||
-a Authenticate packets with HMAC using the given message digest algorithm (auth).
|
||||
|
||||
|
||||
The following options have been tested successfully:
|
||||
|
||||
docker run --volumes-from $OVPN_DATA --net=none --rm kylemanna/openvpn ovpn_genconfig -C 'AES-256-CBC' -a 'SHA384'
|
||||
|
||||
Changing the `tls-cipher` option seems to be more complicated because some clients (namely NetworkManager in Debian Jessie) seem to have trouble with this. Running `openvpn` manually also did not solve the issue:
|
||||
|
||||
TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
|
||||
TLS Error: TLS handshake failed
|
||||
|
||||
Have a look at the [Applied-Crypto-Hardening](https://github.com/BetterCrypto/Applied-Crypto-Hardening/tree/master/src/configuration/VPNs/OpenVPN) project for more examples.
|
@ -1,6 +1,6 @@
|
||||
# Static IP Addresses
|
||||
|
||||
The docker image is setup for static client configuration on the 192.168.254.0/24 subnet. To use it follow the Quick Start section below. Note that the IP addresses octects need to be picked special, see [OpenVPN Documentation](https://openvpn.net/index.php/open-source/documentation/howto.html#policy) for more details.
|
||||
The docker image is setup for static client configuration on the 192.168.254.0/24 subnet. To use it follow the Quick Start section below. Note that the IP addresses octets need to be picked special, see [OpenVPN Documentation](https://openvpn.net/index.php/open-source/documentation/howto.html#policy) for more details.
|
||||
|
||||
## Quick Start
|
||||
|
||||
|
44
init/docker-openvpn@.service
Normal file
44
init/docker-openvpn@.service
Normal file
@ -0,0 +1,44 @@
|
||||
[Unit]
|
||||
Description=OpenVPN Docker Container
|
||||
Documentation=https://github.com/kylemanna/docker-openvpn
|
||||
After=network.target docker.socket
|
||||
Requires=docker.socket
|
||||
|
||||
[Service]
|
||||
RestartSec=10
|
||||
Restart=always
|
||||
|
||||
# Modify IP6_PREFIX to match network config
|
||||
#Environment="IP6_PREFIX=2001:db8::/64"
|
||||
#Environment="ARGS=--config openvpn.conf --server-ipv6 2001:db8::/64"
|
||||
Environment="NAME=ovpn-%i"
|
||||
Environment="DATA_VOL=ovpn-data-%i"
|
||||
Environment="IMG=kylemanna/openvpn:latest"
|
||||
Environment="PORT=1194:1194/udp"
|
||||
|
||||
# To override environment variables, use local configuration directory:
|
||||
# /etc/systemd/system/docker-openvpn@foo.d/local.conf
|
||||
# http://www.freedesktop.org/software/systemd/man/systemd.unit.html
|
||||
|
||||
# Clean-up bad state if still hanging around
|
||||
ExecStartPre=-/usr/bin/docker rm -f $NAME
|
||||
|
||||
# Attempt to pull new image for security updates
|
||||
ExecStartPre=-/usr/bin/docker pull $IMG
|
||||
|
||||
# IPv6: Ensure forwarding is enabled on host's networking stack (hacky)
|
||||
# Would be nice to use systemd-network on the host, but this doens't work
|
||||
# http://lists.freedesktop.org/archives/systemd-devel/2015-June/032762.html
|
||||
ExecStartPre=/bin/sh -c 'test -z "$IP6_PREFIX" && exit 0; sysctl net.ipv6.conf.all.forwarding=1'
|
||||
|
||||
# Main process
|
||||
ExecStart=/usr/bin/docker run --rm --privileged --volumes-from ${DATA_VOL}:ro --name ${NAME} -p ${PORT} ${IMG} ovpn_run $ARGS
|
||||
|
||||
# IPv6: Add static route for IPv6 after it starts up
|
||||
ExecStartPost=/bin/sh -c 'test -z "${IP6_PREFIX}" && exit 0; sleep 1; ip route replace ${IP6_PREFIX} via $(docker inspect -f "{{ .NetworkSettings.GlobalIPv6Address }}" $NAME ) dev docker0'
|
||||
|
||||
# IPv6: Clean-up
|
||||
ExecStopPost=/bin/sh -c 'test -z "$IP6_PREFIX" && exit 0; ip route del $IP6_PREFIX dev docker0'
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
8
init/upstart.init
Normal file
8
init/upstart.init
Normal file
@ -0,0 +1,8 @@
|
||||
# Copy to /etc/init/docker-openvpn.conf
|
||||
description "Docker container for OpenVPN server"
|
||||
start on filesystem and started docker
|
||||
stop on runlevel [!2345]
|
||||
respawn
|
||||
script
|
||||
exec docker run --volumes-from ovpn-data --rm -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
|
||||
end script
|
61
tests/basic.sh
Executable file
61
tests/basic.sh
Executable file
@ -0,0 +1,61 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
OVPN_DATA=basic-data
|
||||
CLIENT=travis-client
|
||||
IMG=kylemanna/openvpn
|
||||
|
||||
#
|
||||
# Create a docker container with the config data
|
||||
#
|
||||
docker run --name $OVPN_DATA -v /etc/openvpn busybox
|
||||
|
||||
ip addr ls
|
||||
SERV_IP=$(ip -4 -o addr show scope global | awk '{print $4}' | sed -e 's:/.*::' | head -n1)
|
||||
docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_genconfig -u udp://$SERV_IP
|
||||
|
||||
# nopass is insecure
|
||||
docker run --volumes-from $OVPN_DATA --rm -it -e "EASYRSA_BATCH=1" -e "EASYRSA_REQ_CN=Travis-CI Test CA" $IMG ovpn_initpki nopass
|
||||
|
||||
docker run --volumes-from $OVPN_DATA --rm -it $IMG easyrsa build-client-full $CLIENT nopass
|
||||
|
||||
docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_getclient $CLIENT | tee client/config.ovpn
|
||||
|
||||
#
|
||||
# Fire up the server
|
||||
#
|
||||
sudo iptables -N DOCKER
|
||||
sudo iptables -I FORWARD -j DOCKER
|
||||
# run in shell bg to get logs
|
||||
docker run --name "ovpn-test" --volumes-from $OVPN_DATA --rm -p 1194:1194/udp --privileged $IMG &
|
||||
|
||||
#for i in $(seq 10); do
|
||||
# SERV_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}')
|
||||
# test -n "$SERV_IP" && break
|
||||
#done
|
||||
#sed -ie s:SERV_IP:$SERV_IP:g client/config.ovpn
|
||||
|
||||
#
|
||||
# Fire up a client in a container since openvpn is disallowed by Travis-CI, don't NAT
|
||||
# the host as it confuses itself:
|
||||
# "Incoming packet rejected from [AF_INET]172.17.42.1:1194[2], expected peer address: [AF_INET]10.240.118.86:1194"
|
||||
#
|
||||
docker run --rm --net=host --privileged --volume $PWD/client:/client $IMG /client/wait-for-connect.sh
|
||||
|
||||
#
|
||||
# Client either connected or timed out, kill server
|
||||
#
|
||||
kill %1
|
||||
|
||||
#
|
||||
# Celebrate
|
||||
#
|
||||
cat <<EOF
|
||||
___________
|
||||
< it worked >
|
||||
-----------
|
||||
\ ^__^
|
||||
\ (oo)\_______
|
||||
(__)\ )\/\\
|
||||
||----w |
|
||||
|| ||
|
||||
EOF
|
35
tests/client/wait-for-connect.sh
Executable file
35
tests/client/wait-for-connect.sh
Executable file
@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
OPENVPN_CONFIG=${1:-/client/config.ovpn}
|
||||
|
||||
# Run in background, rely on bash for job management
|
||||
openvpn --config "$OPENVPN_CONFIG" --management 127.0.0.1 9999 &
|
||||
|
||||
# Spin waiting for interface to exist signifying connection
|
||||
timeout=10
|
||||
for i in $(seq $timeout); do
|
||||
|
||||
# Break when connected
|
||||
#echo state | busybox nc 127.0.0.1 9999 | grep -q "CONNECTED,SUCCESS" && break;
|
||||
|
||||
# Bash magic for tcp sockets
|
||||
if exec 3<>/dev/tcp/127.0.0.1/9999; then
|
||||
# Consume all header input
|
||||
while read -t 0.1 <&3; do true; done
|
||||
echo "state" >&3
|
||||
read -t 1 <&3
|
||||
echo -n $REPLY | grep -q "CONNECTED,SUCCESS" && break || true
|
||||
exec 3>&-
|
||||
fi
|
||||
|
||||
# Else sleep
|
||||
sleep 1
|
||||
done
|
||||
|
||||
if [ $i -ge $timeout ]; then
|
||||
echo "Error starting OpenVPN, i=$i, exiting."
|
||||
exit 2;
|
||||
fi
|
||||
|
||||
# The show is over.
|
||||
kill %1
|
22
tests/paranoid.sh
Executable file
22
tests/paranoid.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
IMG=${IMG:-kylemanna/openvpn}
|
||||
|
||||
temp=$(mktemp -d)
|
||||
|
||||
pushd $temp
|
||||
|
||||
SERV_IP=$(ip -4 -o addr show scope global | awk '{print $4}' | sed -e 's:/.*::' | head -n1)
|
||||
|
||||
docker run --net=none --rm -t -i -v $PWD:/etc/openvpn $IMG ovpn_genconfig -u udp://$SERV_IP
|
||||
|
||||
docker run --net=none --rm -t -i -v $PWD:/etc/openvpn -e "EASYRSA_BATCH=1" -e "EASYRSA_REQ_CN=Travis-CI Test CA" kylemanna/openvpn ovpn_initpki nopass
|
||||
|
||||
docker run --net=none --rm -t -i -v $PWD:/etc/openvpn $IMG ovpn_copy_server_files
|
||||
|
||||
popd
|
||||
# Can't delete the temp directory as docker creates some files as root.
|
||||
# Just let it die with the test instance.
|
||||
rm -rf $temp || true
|
Reference in New Issue
Block a user