How Does It Work?

Initialize the volume container using the kylemanna/openvpn image with theincluded scripts to automatically generate:

Diffie-Hellman parameters

a private key

a self-certificate matching the private key for the OpenVPN server

an EasyRSA CA key and certificate

a TLS auth key from HMAC security

The OpenVPN server is started with the default run cmd of ovpn_run

The configuration is located in /etc/openvpn, and the Dockerfiledeclares that directory as a volume. It means that you can start anothercontainer with the -v argument, and access the configuration.The volume also holds the PKI keys and certs so that it could be backed up.

To generate a client certificate, kylemanna/openvpn uses EasyRSA via theeasyrsa command in the container's path. The EASYRSA_* environmentalvariables place the PKI CA under /etc/openvpn/pki.

Conveniently, kylemanna/openvpn comes with a script called ovpn_getclient,which dumps an inline OpenVPN client configuration file. This single file canthen be given to a client for access to the VPN.

To enable Two Factor Authentication for clients (a.k.a. OTP) see this document.

OpenVPN Details

We use tun mode, because it works on the widest range of devices.tap mode, for instance, does not work on Android, except if the deviceis rooted.

The topology used is net30, because it works on the widest range of OS.p2p, for instance, does not work on Windows.

The UDP server uses192.168.255.0/24 for dynamic clients by default.

The client profile specifies redirect-gateway def1, meaning that afterestablishing the VPN connection, all traffic will go through the VPN.This might cause problems if you use local DNS recursors which are notdirectly reachable, since you will try to reach them through the VPNand they might not answer to you. If that happens, use public DNSresolvers like those of Google (8.8.4.4 and 8.8.8.8) or OpenDNS(208.67.222.222 and 208.67.220.220).

Security Discussion

The Docker container runs its own EasyRSA PKI Certificate Authority. This waschosen as a good way to compromise on security and convenience. The containerruns under the assumption that the OpenVPN container is running on a securehost, that is to say that an adversary does not have access to the PKI filesunder /etc/openvpn/pki. This is a fairly reasonable compromise because if anadversary had access to these files, the adversary could manipulate thefunction of the OpenVPN server itself (sniff packets, create a new PKI CA, MITMpackets, etc).

The certificate authority key is kept in the container by default forsimplicity. It's highly recommended to secure the CA key with somepassphrase to protect against a filesystem compromise. A more secure systemwould put the EasyRSA PKI CA on an offline system (can use the same Dockerimage and the script ovpn_copy_server_files to accomplish this).

It would be impossible for an adversary to sign bad or forged certificateswithout first cracking the key's passphase should the adversary have rootaccess to the filesystem.

The EasyRSA build-client-full command will generate and leave keys on theserver, again possible to compromise and steal the keys. The keys generatedneed to be signed by the CA which the user hopefully configured with a passphraseas described above.

Assuming the rest of the Docker container's filesystem is secure, TLS + PKIsecurity 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) onall distributions Linux distributions such as: Ubuntu, Arch, Debian, Fedora,etc. Furthermore, an old stable server can run a bleeding edge OpenVPN serverwithout having to install/muck with library dependencies (i.e. run latestOpenVPN 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 ephemeralrun time image (kylemanna/openvpn) and the $OVPN_DATA data volume. To removeit, remove the corresponding containers, $OVPN_DATA data volume and Dockerimage and it's completely removed. This also makes it easier to run multipleservers since each lives in the bubble of the container (of course multiple IPsor separate ports are needed to communicate with the world).

Some (arguable) Security Benefits

At the simplest level compromising the container may prevent additionalcompromise of the server. There are many arguments surrounding this, but thetake away is that it certainly makes it more difficult to break out of thecontainer. People are actively working on Linux containers to make this moreof 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 storagevolume for re-use across containers