Compare commits
183 Commits
Author | SHA1 | Date | |
---|---|---|---|
98f9681d3e | |||
74ba753f70 | |||
cd8fd6afaa | |||
9ea4815a74 | |||
74bfad0aac | |||
ed51116fb6 | |||
eb22992a2f | |||
286676879d | |||
42bf842202 | |||
bd51bb273e | |||
70b70e298d | |||
95c260a97a | |||
35c9103454 | |||
d481313311 | |||
9b824fb35a | |||
7a9abf4c14 | |||
44055aa687 | |||
8356a664d8 | |||
ba7b925a9f | |||
517ad6aeb2 | |||
9c6f3311a1 | |||
dc4656ef48 | |||
e8d93ea4fa | |||
10dd404159 | |||
607063b358 | |||
bb3d1add3c | |||
c24a22deea | |||
6084261943 | |||
5ca92a2c5e | |||
dd719c1f11 | |||
6fcebf9adb | |||
86d2a52f85 | |||
1623afe651 | |||
e7d0d4ea0e | |||
e50f4dcc23 | |||
96d17bb5a7 | |||
f2111006ad | |||
d520a58ec4 | |||
1c290e60db | |||
2fa3abe064 | |||
2650d4a286 | |||
2abbcf1999 | |||
818e8682d1 | |||
3edc12a6b7 | |||
ded4414ef4 | |||
f277449569 | |||
edfbffb85f | |||
98cf2128c7 | |||
c3d526fd67 | |||
1498795de2 | |||
f00de363c7 | |||
7f58926aa2 | |||
ba7860cced | |||
98340d7602 | |||
9459804a1d | |||
b298eb16bc | |||
2c3284acd6 | |||
23f66094ff | |||
3da0efa5bc | |||
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 | |||
473671a4d0 | |||
19f4c5cde4 | |||
17ef8cebfc | |||
f07e4ad531 | |||
656be240b6 | |||
b06631099f | |||
be22048a2b | |||
f05de3eb84 | |||
543292e124 | |||
8c7d020074 | |||
a69ca8d65e | |||
f1616f7196 | |||
d36bb7ecba | |||
76a230b3be | |||
5fd47763d7 | |||
37f86037d8 | |||
e9c5108a8f | |||
816eff9af6 | |||
c38b412dc6 | |||
b9cc5b347a | |||
20be0f90a5 | |||
0c873ab4cf | |||
f263eb9a61 | |||
d5979915cf |
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
|
35
CONTRIBUTING.md
Normal file
35
CONTRIBUTING.md
Normal file
@ -0,0 +1,35 @@
|
||||
# Contributing to docker-openvpn
|
||||
|
||||
Community contributions are welcome and help move the project along. Please review this document before sending any pull requests.
|
||||
|
||||
Thanks!
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
All bug fixes are welcome. Please try to add a test if the bug is something that should have been fixed already. Oops.
|
||||
|
||||
## Feature Additions
|
||||
|
||||
New features are welcome provided that the feature has a general audience and is reasonably simple. The goal of the repository is to support a wide audience and be simple enough.
|
||||
|
||||
Please add new documentation in the `docs` folder for any new features. Pull requests for missing documentation is welcome as well. Keep the `README.md` focused on the most popular use case, details belong in the docs directory.
|
||||
|
||||
If you have a special feature, you're likely to try but it will likely be rejected if not too many people seem interested.
|
||||
|
||||
## Tests
|
||||
|
||||
In an effort to not repeat bugs (and break less popular features), unit tests are run on [Travis CI](https://travis-ci.org/kylemanna/docker-openvpn). The goal of the tests are to be simple and to be placed in the `tests` directory where it will be automatically run. Review existing tests for an example.
|
||||
|
||||
## Style
|
||||
|
||||
The style of the repo follows that of the Linux kernel, in particular:
|
||||
|
||||
* Pull requests should be rebased to small atomic commits so that the merged history is more coherent
|
||||
* The subject of the commit should be in the form "<subsystem>: <subject>"
|
||||
* More details in the body
|
||||
* Match surrounding coding style (line wrapping, spaces, etc)
|
||||
|
||||
More details in the [SubmittingPatches](https://www.kernel.org/doc/Documentation/SubmittingPatches) document included with the Linux kernel. In particular the following sections:
|
||||
|
||||
* `2) Describe your changes`
|
||||
* `3) Separate your changes`
|
22
Dockerfile
22
Dockerfile
@ -1,26 +1,25 @@
|
||||
# Original credit: https://github.com/jpetazzo/dockvpn
|
||||
|
||||
# Leaner build then Ubunutu
|
||||
FROM debian:jessie
|
||||
# Smallest base image
|
||||
FROM alpine:3.2
|
||||
|
||||
MAINTAINER Kyle Manna <kyle@kylemanna.com>
|
||||
|
||||
RUN apt-get update && apt-get install -y openvpn iptables git-core
|
||||
|
||||
# Update checkout to use tags when v3.0 is finally released
|
||||
RUN git clone https://github.com/OpenVPN/easy-rsa.git /usr/local/share/easy-rsa
|
||||
RUN cd /usr/local/share/easy-rsa && git checkout -b tested 89f369c5bbd13fbf0da2ea6361632c244e8af532
|
||||
RUN ln -s /usr/local/share/easy-rsa/easyrsa3/easyrsa /usr/local/bin
|
||||
RUN echo "http://dl-4.alpinelinux.org/alpine/edge/community/" >> /etc/apk/repositories && \
|
||||
echo "http://dl-4.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories && \
|
||||
apk add --update openvpn iptables bash easy-rsa openvpn-auth-pam google-authenticator pamtester && \
|
||||
ln -s /usr/share/easy-rsa/easyrsa /usr/local/bin && \
|
||||
rm -rf /tmp/* /var/tmp/* /var/cache/apk/*
|
||||
|
||||
# Needed by scripts
|
||||
ENV OPENVPN /etc/openvpn
|
||||
ENV EASYRSA /usr/local/share/easy-rsa/easyrsa3
|
||||
ENV EASYRSA /usr/share/easy-rsa
|
||||
ENV EASYRSA_PKI $OPENVPN/pki
|
||||
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
|
||||
@ -28,3 +27,6 @@ CMD ["ovpn_run"]
|
||||
|
||||
ADD ./bin /usr/local/bin
|
||||
RUN chmod a+x /usr/local/bin/*
|
||||
|
||||
# Add support for OTP authentication using a PAM module
|
||||
ADD ./otp/openvpn /etc/pam.d/
|
||||
|
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.
|
95
README.md
95
README.md
@ -1,30 +1,69 @@
|
||||
# OpenVPN for Docker
|
||||
|
||||
[](https://travis-ci.org/kylemanna/docker-openvpn)
|
||||
[](https://hub.docker.com/r/kylemanna/openvpn/)
|
||||
[](https://hub.docker.com/r/kylemanna/openvpn/)
|
||||
[](https://hub.docker.com/r/kylemanna/openvpn/)
|
||||
[](https://hub.docker.com/r/kylemanna/openvpn/)
|
||||
|
||||
OpenVPN server in a Docker container complete with an EasyRSA PKI CA.
|
||||
|
||||
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://hub.docker.com/r/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
|
||||
|
||||
* Create the `openvpn-data` volume container
|
||||
* Create the `$OVPN_DATA` volume container, i.e. `OVPN_DATA="ovpn-data"`
|
||||
|
||||
docker run --name openvpn-data -v /etc/openvpn busybox
|
||||
docker run --name $OVPN_DATA -v /etc/openvpn busybox
|
||||
|
||||
* Initalize the `openvpn-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 openvpn-data kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM:1194
|
||||
docker run --volumes-from openvpn-data -it kylemanna/openvpn ovpn_initpki
|
||||
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
|
||||
|
||||
docker run --volumes-from openvpn-data -d -p 1194:1194/udp --privileged kylemanna/openvpn
|
||||
- On Docker [version 1.2](http://blog.docker.com/2014/08/announcing-docker-1-2-0/) and newer
|
||||
|
||||
docker run --volumes-from $OVPN_DATA -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
|
||||
|
||||
- On Docker older than version 1.2
|
||||
|
||||
docker run --volumes-from $OVPN_DATA -d -p 1194:1194/udp --privileged kylemanna/openvpn
|
||||
|
||||
* Generate a client certificate without a passphrase
|
||||
|
||||
docker run --volumes-from openvpn-data --rm -it kylemanna/openvpn easyrsa build-client-full CLIENTNAME nopass
|
||||
docker run --volumes-from $OVPN_DATA --rm -it kylemanna/openvpn easyrsa build-client-full CLIENTNAME nopass
|
||||
|
||||
* Retrieve the client configuration with embedded certificates
|
||||
|
||||
docker run --volumes-from openvpn-data --rm kylemanna/openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
|
||||
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
|
||||
|
||||
## Debugging Tips
|
||||
|
||||
* 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 -p 1194:1194/udp --privileged -e DEBUG=1 kylemanna/openvpn
|
||||
|
||||
* Test using a client that has openvpn installed correctly
|
||||
|
||||
$ openvpn --config CLIENTNAME.ovpn
|
||||
|
||||
* Run through a barrage of debugging checks on the client if things don't just work
|
||||
|
||||
$ ping 8.8.8.8 # checks connectivity without touching name resolution
|
||||
$ dig google.com # won't use the search directives in resolv.conf
|
||||
$ nslookup google.com # will use search
|
||||
|
||||
## How Does It Work?
|
||||
|
||||
@ -52,6 +91,7 @@ Conveniently, `kylemanna/openvpn` comes with a script called `ovpn_getclient`,
|
||||
which dumps an inline OpenVPN client configuration file. This single file can
|
||||
then be given to a client for access to the VPN.
|
||||
|
||||
To enable Two Factor Authentication for clients (a.k.a. OTP) see [this document](/docs/otp.md).
|
||||
|
||||
## OpenVPN Details
|
||||
|
||||
@ -88,33 +128,64 @@ 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
|
||||
* Proper PKI support integrated into image
|
||||
* OpenVPN config files, PKI keys and certs are stored on a storage
|
||||
volume for re-use across containers
|
||||
* Only offer UDP support for now, I don't have a good use case for TCP
|
||||
* Addition of tls-auth for HMAC security
|
||||
|
||||
## Tested On
|
||||
|
||||
* Docker hosts:
|
||||
* server a Digitial Ocean Droplet with 512 MB RAM running Ubuntu 14.04
|
||||
* server a [Digital Ocean](https://www.digitalocean.com/?refcode=d19f7fe88c94) Droplet with 512 MB RAM running Ubuntu 14.04
|
||||
* Clients
|
||||
* Android App OpenVPN Connect 1.1.14 (built 56)
|
||||
* OpenVPN core 3.0 android armv7a thumb2 32-bit
|
||||
* OS X Mavericks with Tunnelblick 3.4beta26 (build 3828) using openvpn-2.3.4
|
||||
* ArchLinux OpenVPN pkg 2.3.4-1
|
||||
*
|
||||
|
||||
## Having permissions issues with Selinux enabled?
|
||||
|
||||
See [this](docs/selinux.md)
|
||||
|
@ -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"
|
@ -36,32 +36,64 @@ usage() {
|
||||
echo " -u SERVER_PUBLIC_URL"
|
||||
echo " [-s SERVER_SUBNET]"
|
||||
echo " [-r ROUTE ...]"
|
||||
echo " [-p PUSH ...]"
|
||||
echo " [-n DNS_SERVER ...]"
|
||||
echo
|
||||
echo "optional arguments:"
|
||||
echo " -d Disable NAT routing and default route"
|
||||
echo " -c Enable client-to-client option"
|
||||
echo " -D Do not push dns servers"
|
||||
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)."
|
||||
echo " -z Enable comp-lzo compression."
|
||||
echo " -2 Enable two factor authentication using Google Authenticator."
|
||||
echo " -f Set the fragment directive."
|
||||
}
|
||||
|
||||
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_DNS_SERVERS=("8.8.8.8" "8.8.4.4")
|
||||
TMP_DNS_SERVERS=()
|
||||
OVPN_TLS_CIPHER=''
|
||||
OVPN_CIPHER=''
|
||||
OVPN_AUTH=''
|
||||
|
||||
# Import defaults if present
|
||||
[ -r "$OVPN_ENV" ] && source "$OVPN_ENV"
|
||||
|
||||
ORIG_OVPN_ROUTES=$OVPN_ROUTES
|
||||
OVPN_ROUTES=""
|
||||
|
||||
# Parse arguments
|
||||
while getopts ":r:s:du:" opt; do
|
||||
while getopts ":a:C:T:r:s:du:cp:n:DNmf:tz2" opt; do
|
||||
case $opt in
|
||||
a)
|
||||
OVPN_AUTH="$OPTARG"
|
||||
;;
|
||||
C)
|
||||
OVPN_CIPHER="$OPTARG"
|
||||
;;
|
||||
T)
|
||||
OVPN_TLS_CIPHER="$OPTARG"
|
||||
;;
|
||||
r)
|
||||
if [ -n "$OVPN_ROUTES" ]; then
|
||||
OVPN_ROUTES+=" $OPTARG"
|
||||
else
|
||||
OVPN_ROUTES+="$OPTARG"
|
||||
fi
|
||||
TMP_ROUTES+=("$OPTARG")
|
||||
;;
|
||||
s)
|
||||
OVPN_SERVER=$OPTARG
|
||||
@ -72,6 +104,36 @@ while getopts ":r:s:du:" opt; do
|
||||
u)
|
||||
OVPN_SERVER_URL=$OPTARG
|
||||
;;
|
||||
c)
|
||||
OVPN_CLIENT_TO_CLIENT=1
|
||||
;;
|
||||
p)
|
||||
TMP_PUSH+=("$OPTARG")
|
||||
;;
|
||||
n)
|
||||
TMP_DNS_SERVERS+=("$OPTARG")
|
||||
;;
|
||||
D)
|
||||
OVPN_DNS=0
|
||||
;;
|
||||
N)
|
||||
OVPN_NAT=1
|
||||
;;
|
||||
m)
|
||||
OVPN_MTU=$OPTARG
|
||||
;;
|
||||
t)
|
||||
OVPN_DEVICE="tap"
|
||||
;;
|
||||
z)
|
||||
OVPN_COMP_LZO=1
|
||||
;;
|
||||
2)
|
||||
OVPN_OTP_AUTH=1
|
||||
;;
|
||||
f)
|
||||
OVPN_FRAGMENT=$OPTARG
|
||||
;;
|
||||
\?)
|
||||
set +x
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
@ -87,9 +149,17 @@ while getopts ":r:s:du:" 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[@]}")
|
||||
|
||||
# if dns servers were not defined with -n, use google nameservers
|
||||
[ ${#TMP_DNS_SERVERS[@]} -gt 0 ] && OVPN_DNS_SERVERS=("${TMP_DNS_SERVERS[@]}")
|
||||
|
||||
# Server name is in the form "udp://vpn.example.com:1194"
|
||||
if [[ "$OVPN_SERVER_URL" =~ ^((udp|tcp)://)?([0-9a-zA-Z\.]+)(:([0-9]+))?$ ]]; then
|
||||
if [[ "$OVPN_SERVER_URL" =~ ^((udp|tcp)://)?([0-9a-zA-Z\.\-]+)(:([0-9]+))?$ ]]; then
|
||||
OVPN_PROTO=${BASH_REMATCH[2]};
|
||||
OVPN_CN=${BASH_REMATCH[3]};
|
||||
OVPN_PORT=${BASH_REMATCH[5]};
|
||||
@ -103,17 +173,15 @@ fi
|
||||
# Apply defaults
|
||||
[ -z "$OVPN_PROTO" ] && OVPN_PROTO=udp
|
||||
[ -z "$OVPN_PORT" ] && OVPN_PORT=1194
|
||||
|
||||
if [ -z "$OVPN_ROUTES" ]; then
|
||||
if [ -n "$ORIG_OVPN_ROUTES" ]; then
|
||||
OVPN_ROUTES=$ORIG_OVPN_ROUTES
|
||||
else
|
||||
OVPN_ROUTES=192.168.254.0/24
|
||||
fi
|
||||
fi
|
||||
[ ${#OVPN_ROUTES[@]} -eq 0 ] && OVPN_ROUTES=("192.168.254.0/24")
|
||||
|
||||
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 OVPN_NAT OVPN_DNS OVPN_MTU OVPN_DEVICE
|
||||
export OVPN_TLS_CIPHER OVPN_CIPHER OVPN_AUTH
|
||||
export OVPN_COMP_LZO
|
||||
export OVPN_OTP_AUTH
|
||||
export OVPN_FRAGMENT
|
||||
|
||||
# Preserve config
|
||||
if [ -f "$OVPN_ENV" ]; then
|
||||
@ -133,7 +201,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
|
||||
@ -143,25 +210,57 @@ 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_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"
|
||||
[ -n "$OVPN_COMP_LZO" ] && echo "comp-lzo" >> "$conf"
|
||||
|
||||
[ -n "$OVPN_FRAGMENT" ] && echo "fragment $OVPN_FRAGMENT" >> "$conf"
|
||||
|
||||
[ "$OVPN_DNS" == "1" ] && for i in "${OVPN_DNS_SERVERS[@]}"; do
|
||||
echo "push dhcp-option DNS $i" >> "$conf"
|
||||
done
|
||||
# Append Routes
|
||||
for i in ${OVPN_ROUTES[@]}; do
|
||||
for i in "${OVPN_ROUTES[@]}"; do
|
||||
# If user passed "0" skip this, assume no extra routes
|
||||
[ "$i" = "0" ] && break;
|
||||
echo route $(getroute $i) >> "$conf"
|
||||
echo route $(getroute "$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
|
||||
# Append push commands
|
||||
for i in "${OVPN_PUSH[@]}"; do
|
||||
echo push \"$i\" >> "$conf"
|
||||
done
|
||||
|
||||
# Optional OTP authentication support
|
||||
if [ -n "$OVPN_OTP_AUTH" ]; then
|
||||
echo -e "\n\n# Enable OTP+PAM for user authentication" >> "$conf"
|
||||
echo "plugin /usr/lib/openvpn/plugins/openvpn-plugin-auth-pam.so openvpn" >> "$conf"
|
||||
fi
|
||||
|
||||
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,43 +4,117 @@
|
||||
# Get an OpenVPN client configuration file
|
||||
#
|
||||
|
||||
set -ex
|
||||
|
||||
source "$OPENVPN/ovpn_env.sh"
|
||||
cn=$1
|
||||
|
||||
if [ ! -f "$EASYRSA_PKI/private/${cn}.key" ]; then
|
||||
easyrsa build-server-full $cn nopass
|
||||
if [ "$DEBUG" == "1" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
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" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
if [ -n "$OVPN_OTP_AUTH" ]; then
|
||||
echo "auth-user-pass"
|
||||
echo "auth-nocache"
|
||||
fi
|
||||
|
||||
if [ -n "$OVPN_COMP_LZO" ]; then
|
||||
echo "comp-lzo"
|
||||
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"
|
||||
|
||||
|
33
bin/ovpn_otp_user
Executable file
33
bin/ovpn_otp_user
Executable file
@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Generate OpenVPN users via google authenticator
|
||||
#
|
||||
|
||||
if ! source "$OPENVPN/ovpn_env.sh"; then
|
||||
echo "Could not source $OPENVPN/ovpn_env.sh."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "x$OVPN_OTP_AUTH" != "x1" ]; then
|
||||
echo "OTP authentication not enabled, please regenerate configuration using -2 flag"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z $1 ]; then
|
||||
echo "Usage: ovpn_otp_user USERNAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure the otp folder is present
|
||||
[ -d /etc/openvpn/otp ] || mkdir -p /etc/openvpn/otp
|
||||
|
||||
# Binary is present in image, save an $user.google_authenticator file in /etc/openvpn/otp
|
||||
if [ "$2" == "interactive" ]; then
|
||||
# Authenticator will ask for other parameters. User can choose rate limit, token reuse policy and time window policy
|
||||
# Always use time base OTP otherwise storage for counters must be configured somewhere in volume
|
||||
google-authenticator --time-based --force -l "${1}@${OVPN_CN}" -s /etc/openvpn/otp/${1}.google_authenticator
|
||||
else
|
||||
google-authenticator --time-based --disallow-reuse --force --rate-limit=3 --rate-time=30 --window-size=3 \
|
||||
-l "${1}@${OVPN_CN}" -s /etc/openvpn/otp/${1}.google_authenticator
|
||||
fi
|
55
bin/ovpn_run
55
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,19 +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
|
||||
|
||||
# Setup NAT forwarding if requested
|
||||
if [ "$OVPN_DEFROUTE" != "0" ];then
|
||||
iptables -t nat -A POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE
|
||||
# When using --net=host, use this to specify nat device.
|
||||
[ -z "$OVPN_NATDEVICE" ] && OVPN_NATDEVICE=eth0
|
||||
|
||||
for i in ${OVPN_ROUTES[@]}; do
|
||||
iptables -t nat -A POSTROUTING -s $i -o eth0 -j MASQUERADE
|
||||
# Setup NAT forwarding if requested
|
||||
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 $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 -w net.ipv6.conf.default.forwarding=1 || echo "Failed to enable IPv6 Forwarding default"
|
||||
sysctl -w 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
|
||||
|
20
docs/advanced.md
Normal file
20
docs/advanced.md
Normal file
@ -0,0 +1,20 @@
|
||||
# Advanced Configurations
|
||||
|
||||
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
|
||||
|
||||
* Refer to the Quick Start document, and substitute `--volumes-from $OVPN_DATA` with `-v /path/on/host/openvpn0:/etc/openvpn`
|
||||
* Quick example that is likely to be out of date, but here's how to get started:
|
||||
|
||||
mkdir openvpn0
|
||||
cd openvpn0
|
||||
docker run --rm -v $PWD:/etc/openvpn kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM:1194
|
||||
docker run --rm -v $PWD:/etc/openvpn -it kylemanna/openvpn ovpn_initpki
|
||||
vim openvpn.conf
|
||||
docker run --rm -v $PWD:/etc/openvpn -it kylemanna/openvpn easyrsa build-client-full CLIENTNAME nopass
|
||||
docker run --rm -v $PWD:/etc/openvpn kylemanna/openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
|
||||
|
||||
* 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 openvpn-data --rm busybox tar -cvf - -C /etc openvpn | xz > openvpn-backup.tar.xz
|
||||
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
|
||||
|
||||
xzcat openvpn-backup.tar.xz | docker run --name openvpn-data -v /etc/openvpn -i busybox tar -xvf - -C /etc
|
||||
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.
|
@ -2,6 +2,13 @@
|
||||
|
||||
Random things I do to debug the containers.
|
||||
|
||||
## Login Shells
|
||||
|
||||
* Create a shell in the running docker container (aka namespace) with [nsenter](https://github.com/jpetazzo/nsenter)
|
||||
* If you don't have nsenter/docker-enter, you can mount the data container and modify it with
|
||||
|
||||
docker run --rm -it --volumes-from $OVPN_DATA kylemanna/openvpn bash -l
|
||||
|
||||
## Stream OpenVPN Logs
|
||||
|
||||
1. Get the container's name or container ID:
|
||||
|
10
docs/docker-openvpn.te
Normal file
10
docs/docker-openvpn.te
Normal file
@ -0,0 +1,10 @@
|
||||
module docker-openvpn 1.0;
|
||||
|
||||
require {
|
||||
type svirt_lxc_net_t;
|
||||
class tun_socket create;
|
||||
}
|
||||
|
||||
#============= svirt_lxc_net_t ==============
|
||||
allow svirt_lxc_net_t self:tun_socket create;
|
||||
|
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
|
20
docs/faqs.md
Normal file
20
docs/faqs.md
Normal file
@ -0,0 +1,20 @@
|
||||
# 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`.
|
||||
|
||||
## How do I set up a split tunnel?
|
||||
|
||||
Split tunnels are configurations where only some of the traffic from a client goes to the VPN, with the remainder routed through the normal non-VPN interfaces. You'll want to disable a default route (-d) when you generate the configuration, but still use NAT (-N) to keep network address translation enabled.
|
||||
|
||||
ovpn_genconfig -N -d ...
|
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.
|
72
docs/otp.md
Normal file
72
docs/otp.md
Normal file
@ -0,0 +1,72 @@
|
||||
# Using two factor authentication for users
|
||||
|
||||
Instead of relying on complex passwords for client certificates (that usually get written somewhere) this image
|
||||
provides support for two factor authentication with OTP devices.
|
||||
|
||||
The most common app that provides OTP generation is Google Authenticator ([iOS](https://itunes.apple.com/it/app/google-authenticator/id388497605?mt=8) and
|
||||
[Android](https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=it)) you can download it
|
||||
and use this image to generate user configuration.
|
||||
|
||||
## Usage
|
||||
|
||||
In order to enable two factor authentication the following steps are required.
|
||||
|
||||
* Generate server configuration with `-2` option
|
||||
|
||||
docker run --volumes-from $OVPN_DATA --rm fabn/openvpn ovpn_genconfig -u udp://vpn.example.com -2
|
||||
|
||||
* Generate your client certificate (possibly without a password since you're using OTP)
|
||||
|
||||
docker run --volumes-from $OVPN_DATA --rm -it fabn/openvpn easyrsa build-client-full <user> nopass
|
||||
|
||||
* Generate authentication configuration for your client. -t is needed to show QR code, -i is optional for interactive usage
|
||||
|
||||
docker run --volumes-from $OVPN_DATA --rm -t fabn/openvpn ovpn_otp_user <user>
|
||||
|
||||
The last step will generate OTP configuration for the provided user with the following options
|
||||
|
||||
```
|
||||
google-authenticator --time-based --disallow-reuse --force --rate-limit=3 --rate-time=30 --window-size=3 \
|
||||
-l "${1}@${OVPN_CN}" -s /etc/openvpn/otp/${1}.google_authenticator
|
||||
```
|
||||
|
||||
It will also show a shell QR code in terminal you can scan with the Google Authenticator application. It also provides
|
||||
a link to a google chart url that will display a QR code for the authentication.
|
||||
|
||||
**Do not share QR code (or generated url) with anyone but final user, that is your second factor for authentication
|
||||
that is used to generate OTP codes**
|
||||
|
||||
Here's an example QR code generated for an hypotetical user@example.com user.
|
||||
|
||||

|
||||
|
||||
Generate client configuration for `<user>` and import it in OpenVPN client. On connection it will prompt for user and password.
|
||||
Enter your username and a 6 digit code generated by Authenticator app and you're logged in.
|
||||
|
||||
## TL;DR
|
||||
|
||||
Under the hood this configuration will setup an `openvpn` PAM service configuration (`/etc/pam.d/openvpn`)
|
||||
that relies on the awesome [Google Authenticator PAM module](https://github.com/google/google-authenticator).
|
||||
In this configuration the `auth` part of PAM flow is managed by OTP codes and the `account` part is not enforced
|
||||
because you're likely dealing with virtual users and you do not want to create a system account for every VPN user.
|
||||
|
||||
`ovpn_otp_user` script will store OTP credentials under `/etc/openvpn/otp/<user>.google_authentication`. In this
|
||||
way when you take a backup OTP users are included as well.
|
||||
|
||||
Finally it will enable the openvpn plugin `openvpn-plugin-auth-pam.so` in server configuration and append the
|
||||
`auth-user-pass` directive in client configuration.
|
||||
|
||||
## Debug
|
||||
|
||||
If something is not working you can verify your PAM setup with these commands
|
||||
|
||||
```
|
||||
# Start a shell in container
|
||||
docker run --volumes-from $OVPN_DATA --rm -it fabn/openvpn bash
|
||||
# Then in container install pamtester utility
|
||||
apt-get update && apt-get install -y pamtester
|
||||
# To check authentication use this command that will prompt for a valid code from Authenticator APP
|
||||
pamtester -v openvpn <user> authenticate
|
||||
```
|
||||
|
||||
If you configured everything correctly you should get authenticated by entering a OTP code from the app.
|
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.
|
25
docs/selinux.md
Normal file
25
docs/selinux.md
Normal file
@ -0,0 +1,25 @@
|
||||
# For hosts that use SELinux
|
||||
|
||||
Try this [policy file](docker-openvpn.te)
|
||||
|
||||
Run these commands to compile and load it:
|
||||
|
||||
```
|
||||
checkmodule -M -m -o docker-openvpn.mod docker-openvpn.te
|
||||
semodule_package -o docker-openvpn.pp -m docker-openvpn.mod
|
||||
sudo semodule -i docker-openvpn.pp
|
||||
```
|
||||
|
||||
Also, some configurations don't allow containers to load kernel modules, so on the host run this:
|
||||
|
||||
```
|
||||
sudo modprobe tun
|
||||
```
|
||||
|
||||
So the container doesn't have to load the `tun` module.
|
||||
|
||||
|
||||
# Still having issues?
|
||||
|
||||
In January 2016, Fedora based systems got an update that fixed an issue for labeling namespaced net objects under /proc
|
||||
to fix, make sure that you have run `sudo dnf update` and you need to reboot to load the new policies
|
@ -1,24 +1,24 @@
|
||||
# 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
|
||||
|
||||
1. Create a client specific configuration:
|
||||
|
||||
$ echo "ifconfig-push 192.168.254.1 192.168.254.2" | docker run --volumes-from openvpn-data -i --rm kylemanna/openvpn tee /etc/openvpn/ccd/CERT_COMMON_NAME
|
||||
$ echo "ifconfig-push 192.168.254.1 192.168.254.2" | docker run --volumes-from $OVPN_DATA -i --rm kylemanna/openvpn tee /etc/openvpn/ccd/CERT_COMMON_NAME
|
||||
ifconfig-push 192.168.254.1 192.168.254.2
|
||||
|
||||
2. Wait for client to reconnect if necessary
|
||||
|
||||
## Advanced Admin
|
||||
|
||||
Login to the openvpn-data volume with a `bash` container, note only changes in /etc/openvpn will persist:
|
||||
Login to the data volume with a `bash` container, note only changes in /etc/openvpn will persist:
|
||||
|
||||
docker run --volumes-from openvpn-data -it --rm kylemanna/openvpn bash -l
|
||||
docker run --volumes-from $OVPN_DATA -it --rm kylemanna/openvpn bash -l
|
||||
|
||||
## Upgrading from Old OpenVPN Configurations
|
||||
|
||||
If you're running an old configuration and need to upgrade it to pull in the ccd directory run the following:
|
||||
|
||||
docker run --volumes-from openvpn-data --rm kylemanna/openvpn ovpn_genconfig
|
||||
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_genconfig
|
||||
|
18
docs/tcp.md
Normal file
18
docs/tcp.md
Normal file
@ -0,0 +1,18 @@
|
||||
# TCP Protocol
|
||||
|
||||
## TCP vs. UDP - Pros & Cons
|
||||
By default, OpenVPN is configured to use the UDP protocol. Because UDP incurs minimal protocol overhead (for example, no acknowledgment is required upon successful packet receipt), it can sometimes result in slightly faster throughput. However, in situations where VPN service is needed over an unreliable connection, the user experience can benefit from the extra diagnostic features of the TCP protocol.
|
||||
|
||||
As an example, users connecting from an airplane wifi network may experience high packet drop rates, where the error detection and sliding window control of TCP can more readily adjust to the inconsistent connection.
|
||||
|
||||
## Using TCP
|
||||
Those requiring TCP connections should initialize the data container by specifying the TCP protocol and port number:
|
||||
|
||||
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_genconfig -u tcp://VPN.SERVERNAME.COM:443
|
||||
docker run --volumes-from $OVPN_DATA --rm -it kylemanna/openvpn ovpn_initpki
|
||||
|
||||
Because the server container always exposes port 1194, regardless of the
|
||||
specified protocol, adjust the mapping appropriately:
|
||||
|
||||
docker run --volumes-from $OVPN_DATA -d -p 443:1194/tcp --cap-add=NET_ADMIN kylemanna/openvpn
|
||||
|
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
|
7
otp/openvpn
Normal file
7
otp/openvpn
Normal file
@ -0,0 +1,7 @@
|
||||
# Uses google authenticator library as PAM module using a single folder for all users tokens
|
||||
# User root is required to stick with an hardcoded user when trying to determine user id and allow unexisting system users
|
||||
# See https://github.com/google/google-authenticator/tree/master/libpam#secretpathtosecretfile--usersome-user
|
||||
auth required pam_google_authenticator.so secret=/etc/openvpn/otp/${USER}.google_authenticator user=root
|
||||
|
||||
# Accept any user since we're dealing with virtual users there's no need to have a system account (pam_unix.so)
|
||||
account sufficient pam_permit.so
|
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
|
55
tests/openvpn_conf_options.test.sh
Executable file
55
tests/openvpn_conf_options.test.sh
Executable file
@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
OVPN_DATA=opvn-data
|
||||
|
||||
IMG=kylemanna/openvpn
|
||||
|
||||
# Function to fail
|
||||
abort() { cat <<< "$@" 1>&2; exit 1; }
|
||||
|
||||
#
|
||||
# Create a docker container with the config data
|
||||
#
|
||||
sudo docker run --name $OVPN_DATA -v /etc/openvpn busybox
|
||||
|
||||
#
|
||||
# Generate openvpn.config file
|
||||
#
|
||||
SERV_IP=$(ip -4 -o addr show scope global | awk '{print $4}' | sed -e 's:/.*::' | head -n1)
|
||||
sudo docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_genconfig -u udp://$SERV_IP -f 1400
|
||||
|
||||
#
|
||||
# grep for config lines from openvpn.conf
|
||||
# add more tests for more configs as required
|
||||
#
|
||||
|
||||
# 1. verb config
|
||||
CONFIG_REQUIRED_VERB="verb 3"
|
||||
CONFIG_MATCH_VERB=$(sudo docker run --rm -it --volumes-from $OVPN_DATA busybox grep verb /etc/openvpn/openvpn.conf)
|
||||
|
||||
# 2. fragment config
|
||||
CONFIG_REQUIRED_FRAGMENT="fragment 1400"
|
||||
CONFIG_MATCH_FRAGMENT=$(sudo docker run --rm -it --volumes-from $OVPN_DATA busybox grep fragment /etc/openvpn/openvpn.conf)
|
||||
|
||||
#
|
||||
# Clean up
|
||||
#
|
||||
# sudo docker rm -f $OVPN_DATA
|
||||
|
||||
#
|
||||
# Tests
|
||||
#
|
||||
|
||||
if [[ $CONFIG_MATCH_VERB =~ $CONFIG_REQUIRED_VERB ]]
|
||||
then
|
||||
echo "==> Config match found: $CONFIG_REQUIRED_VERB == $CONFIG_MATCH_VERB"
|
||||
else
|
||||
abort "==> Config match not found: $CONFIG_REQUIRED_VERB != $CONFIG_MATCH_VERB"
|
||||
fi
|
||||
|
||||
if [[ $CONFIG_MATCH_FRAGMENT =~ $CONFIG_REQUIRED_FRAGMENT ]]
|
||||
then
|
||||
echo "==> Config match found: $CONFIG_REQUIRED_FRAGMENT == $CONFIG_MATCH_FRAGMENT"
|
||||
else
|
||||
abort "==> Config match not found: $CONFIG_REQUIRED_FRAGMENT != $CONFIG_MATCH_FRAGMENT"
|
||||
fi
|
81
tests/otp.sh
Executable file
81
tests/otp.sh
Executable file
@ -0,0 +1,81 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
OVPN_DATA=basic-data-otp
|
||||
CLIENT=travis-client
|
||||
IMG=kylemanna/openvpn
|
||||
OTP_USER=otp
|
||||
# Function to fail
|
||||
abort() { cat <<< "$@" 1>&2; exit 1; }
|
||||
|
||||
#
|
||||
# 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)
|
||||
# Configure server with two factor authentication
|
||||
docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_genconfig -u udp://$SERV_IP -2
|
||||
|
||||
# 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
|
||||
|
||||
# Generate OTP credentials for user named test, should return QR code for test user
|
||||
docker run --volumes-from $OVPN_DATA --rm -it $IMG ovpn_otp_user $OTP_USER | tee client/qrcode.txt
|
||||
# Ensure a chart link is printed in client OTP configuration
|
||||
grep 'https://www.google.com/chart' client/qrcode.txt || abort 'Link to chart not generated'
|
||||
grep 'Your new secret key is:' client/qrcode.txt || abort 'Secret key is missing'
|
||||
# Extract an emergency code from textual output, grepping for line and trimming spaces
|
||||
OTP_TOKEN=$(grep -A1 'Your emergency scratch codes are' client/qrcode.txt | tail -1 | tr -d '[[:space:]]')
|
||||
# Token should be present
|
||||
if [ -z $OTP_TOKEN ]; then
|
||||
abort "QR Emergency Code not detected"
|
||||
fi
|
||||
|
||||
# Store authentication credentials in config file and tell openvpn to use them
|
||||
echo -e "$OTP_USER\n$OTP_TOKEN" > client/credentials.txt
|
||||
|
||||
# Override the auth-user-pass directive to use a credentials file
|
||||
docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_getclient $CLIENT | sed 's/auth-user-pass/auth-user-pass \/client\/credentials.txt/' | tee client/config.ovpn
|
||||
|
||||
#
|
||||
# Fire up the server
|
||||
#
|
||||
sudo iptables -N DOCKER || echo 'Firewall already configured'
|
||||
sudo iptables -I FORWARD -j DOCKER || echo 'Forward already configured'
|
||||
# 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
|
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