🔒 OpenVPN server in a Docker container complete with an EasyRSA PKI CA - ARM64v8 Raspberry Pi
1.3K
OpenVPN server in a Docker container complete with an EasyRSA PKI CA.
This image is deprecated. We will not support this image and it will not be updated. We recommend using Wireguard.
![]()
To have persistent data we need to use a volume, this can be a docker volume or a bind format. For this example I will use a static path where we will store the container data. This path has to be always the same when we work with this image.
/path/host/openvpn-config
Remember that you have to change the volume path in the following commands.
Now we will create the initial configuration. These commands will use a temporary container to create a certificate authority and the private key it will use. It may ask for a passphrase to protect the generated private key. You have to change the DNS domain name.
docker run -v /path/host/openvpn-config:/etc/openvpn --rm yerayvillamarin/openvpn-arm64v8 ovpn_genconfig -u udp://VPN.SERVERNAME.COM
docker run -v /path/host/openvpn-config:/etc/openvpn --rm -it yerayvillamarin/openvpn-arm64v8 ovpn_initpki
Note: This process may take several minutes, be patient.
Create the container to run the OpenVPN service on port 1194/UDP.
You have to change the CONTAINER_NAME.
docker run -d \
--name=CONTAINER_NAME \
-v /path/host/openvpn-config:/etc/openvpn \
-p 1194:1194/udp \
--cap-add=NET_ADMIN \
--restart unless-stopped \
yerayvillamarin/openvpn-arm64v8
Generate a client certificate without a passphrase.
You have to change CLIENTNAME to a user name. This name must be unique.
docker run -v /path/host/openvpn-config:/etc/openvpn --rm -it yerayvillamarin/openvpn-arm64v8 easyrsa build-client-full CLIENTNAME nopass
Finally, we will extract the client configuration with embedded certificates into an .ovpn file.
docker run -v /path/host/openvpn-config:/etc/openvpn --rm yerayvillamarin/openvpn-arm64v8 ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
The CLIENTNAME.ovpn file will be saved in the current path of our host.
In order to allow new clients / devices to connect to our server at the same time, we need to create new client certificates. For this we have to execute the last two commands of the initial configuration.
Generate a client certificate without a passphrase.
You have to change CLIENTNAME to a user name. This name must be unique.
docker run -v /path/host/openvpn-config:/etc/openvpn --rm -it yerayvillamarin/openvpn-arm64v8 easyrsa build-client-full CLIENTNAME nopass
Finally, we will extract the client configuration with embedded certificates into an .ovpn file.
docker run -v /path/host/openvpn-config:/etc/openvpn --rm yerayvillamarin/openvpn-arm64v8 ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
The CLIENTNAME.ovpn file will be saved in the current path of our host.
If we want to block the connection of a created client.
docker run --rm -it -v /path/host/openvpn-config:/etc/openvpn yerayvillamarin/openvpn-arm64v8 ovpn_revokeclient CLIENTNAME
And if we want to remove their corresponding files too, we only have to pass the parameter remove.
docker run --rm -it -v /path/host/openvpn-config:/etc/openvpn yerayvillamarin/openvpn-arm64v8 ovpn_revokeclient CLIENTNAME remove
In order to connect to the server from the client we need the CLIENTNAME.ovpn file generated when creating the client. This file contains the information for the connection and the necessary keys.
CLIENTNAME.ovpn file to the device from where we want to connect.CLIENTNAME.ovpnAs in the creation of the users we passed the parameter nopass, we could already connect without the need to set passwords. If we want more security in our client we can create the user without nopass and this way it will ask for a password for that client.
Remember to open port 1194/UDP in the router and route it to the IP where this container is located.
See an overview of the configured clients, including revocation and expiration status
docker run --rm -it -v /path/host/openvpn-config:/etc/openvpn yerayvillamarin/openvpn-arm64v8 ovpn_listclients
View OpenVPN log
docker logs CONTAINER_NAME
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).
ovpn_copy_server_files to accomplish this).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 be signed by the CA which the user hopefully configured with a passphrase
as described above.Content type
Image
Digest
sha256:2a25455e1…
Size
7.1 MB
Last updated
about 3 years ago
docker pull yerayvillamarin/openvpn-arm64v8