OpenVPN server in a Docker container complete with an EasyRSA PKI CA. (originally by kylemanna)
Extensively tested on Digital Ocean $5/mo node.
Create the $OVPN_DATA volume container, i.e. OVPN_DATA="ovpn-data"
docker run --name $OVPN_DATA -v /etc/openvpn busybox
Initialize the $OVPN_DATA container that will hold the configuration files and certificates
docker run --volumes-from $OVPN_DATA --rm 13yo/sambavpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM
docker run --volumes-from $OVPN_DATA --rm -it 13yo/sambavpn ovpn_initpki
Start OpenVPN server process
On Docker version 1.2 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 $OVPN_DATA --rm -it kylemanna/openvpn easyrsa build-client-full CLIENTNAME nopass
Retrieve the client configuration with embedded certificates
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
Initialize the volume container using the kylemanna/openvpn image with the
included scripts to automatically generate:
The OpenVPN server is started with the default run cmd of ovpn_run
The configuration is located in /etc/openvpn, and the Dockerfile
declares that directory as a volume. It means that you can start another
container with the --volumes-from flag, 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 the
easyrsa command in the container's path. The EASYRSA_* environmental
variables place the PKI CA under /etc/opevpn/pki.
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.
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 device
is 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 after
establishing the VPN connection, all traffic will go through the VPN.
This might cause problems if you use local DNS recursors which are not
directly reachable, since you will try to reach them through the VPN
and they might not answer to you. If that happens, use public DNS
resolvers like those of Google (8.8.4.4 and 8.8.8.8) or OpenDNS
(208.67.222.222 and 208.67.220.220).
The Docker container runs its own EasyRSA PKI Certificate Authority. This was
chosen as a good way to compromise on security and convenience. The container
runs under the assumption that the OpenVPN container is running on a secure
host, that is to say that an adversary does not have access to the PKI files
under /etc/openvpn/pki. This is a fairly reasonable compromise because if an
adversary had access to these files, the adversary could manipulate the
function of the OpenVPN server itself (sniff packets, create a new PKI CA, MITM
packets, etc).
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
as described above.Content type
Image
Digest
sha256:c347bb479…
Size
84.4 MB
Last updated
almost 11 years ago
docker pull 13yo/docker-openvpn