Convert Figma logo to code with AI

kylemanna logodocker-openvpn

🔒 OpenVPN server in a Docker container complete with an EasyRSA PKI CA

8,706
2,386
8,706
299

Top Related Projects

10,611

OpenVPN is an open source VPN daemon

OpenVPN road warrior installer for Ubuntu, Debian, AlmaLinux, Rocky Linux, CentOS and Fedora

Docker image to run an IPsec VPN server, with IPsec/L2TP, Cisco IPsec and IKEv2

28,648

Set up a personal VPN in the cloud

23,174

Streisand sets up a new server running your choice of WireGuard, OpenConnect, OpenSSH, OpenVPN, Shadowsocks, sslh, Stunnel, or a Tor bridge. It also generates custom instructions for all of these services. At the end of the run you are given an HTML file with instructions that can be shared with friends, family members, and fellow activists.

Quick Overview

kylemanna/docker-openvpn is a Docker image that simplifies the deployment and management of an OpenVPN server. It provides a containerized solution for running OpenVPN, making it easy to set up and maintain a secure VPN service.

Pros

  • Easy setup and deployment using Docker
  • Includes scripts for managing users and certificates
  • Supports both UDP and TCP protocols
  • Regular updates and active community support

Cons

  • Limited customization options compared to a manual OpenVPN setup
  • Requires basic Docker knowledge to use effectively
  • May have slightly higher resource usage due to containerization
  • Documentation could be more comprehensive for advanced use cases

Getting Started

To get started with kylemanna/docker-openvpn, follow these steps:

  1. Generate configuration files:
OVPN_DATA="ovpn-data-example"
docker volume create --name $OVPN_DATA
docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
  1. Start OpenVPN server:
docker run -v $OVPN_DATA:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
  1. Generate a client certificate:
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full CLIENTNAME nopass
  1. Retrieve client configuration:
docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn

Replace VPN.SERVERNAME.COM with your server's domain or IP address, and CLIENTNAME with the desired client name.

Competitor Comparisons

10,611

OpenVPN is an open source VPN daemon

Pros of openvpn

  • Official repository maintained by OpenVPN Inc., ensuring up-to-date and reliable codebase
  • Comprehensive documentation and extensive community support
  • Supports a wide range of platforms and configurations

Cons of openvpn

  • More complex setup process compared to docker-openvpn
  • Requires manual configuration and management of server and client settings
  • Less streamlined for containerized deployments

Code Comparison

openvpn:

./configure
make
make install

docker-openvpn:

docker run -v $PWD:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM
docker run -v $PWD:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki

The openvpn repository provides the core OpenVPN software, which requires manual compilation and installation. In contrast, docker-openvpn offers a pre-configured Docker image with simplified setup commands.

While openvpn provides more flexibility and control over the VPN setup, docker-openvpn streamlines the process for users who prefer a containerized solution with minimal configuration. The choice between the two depends on specific requirements, deployment environment, and user expertise.

OpenVPN road warrior installer for Ubuntu, Debian, AlmaLinux, Rocky Linux, CentOS and Fedora

Pros of openvpn-install

  • Simpler setup process with a single script installation
  • Easier management of users and certificates
  • Works on a wider range of Linux distributions

Cons of openvpn-install

  • Less containerized, potentially affecting system isolation
  • May require more manual configuration for advanced setups
  • Limited to running on the host system directly

Code Comparison

openvpn-install:

#!/bin/bash
# OpenVPN installer for Debian, Ubuntu, Fedora, CentOS, and Arch Linux
# https://github.com/Nyr/openvpn-install

# Detect Debian users running the script with "sh" instead of bash
if readlink /proc/$$/exe | grep -q "dash"; then
    echo 'This installer needs to be run with "bash", not "sh".'
    exit 1
fi

docker-openvpn:

FROM alpine:3.18

LABEL maintainer="Kyle Manna <kyle@kylemanna.com>"

RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community/" >> /etc/apk/repositories && \
    echo "http://dl-cdn.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/* /var/cache/distfiles/*

Docker image to run an IPsec VPN server, with IPsec/L2TP, Cisco IPsec and IKEv2

Pros of docker-ipsec-vpn-server

  • Supports multiple VPN protocols (IPsec/L2TP, IPsec/XAuth, and Cisco IPsec)
  • Easier setup for clients, especially on mobile devices
  • Built-in support for both IPv4 and IPv6

Cons of docker-ipsec-vpn-server

  • Less flexible configuration options compared to OpenVPN
  • May be less secure in certain network environments
  • Limited advanced features like traffic shaping or split tunneling

Code Comparison

docker-ipsec-vpn-server:

docker run \
    --name ipsec-vpn-server \
    --env-file ./vpn.env \
    --restart=always \
    -p 500:500/udp \
    -p 4500:4500/udp \
    -v /lib/modules:/lib/modules:ro \
    -d --privileged \
    hwdsl2/ipsec-vpn-server

docker-openvpn:

docker run \
    -v $OVPN_DATA:/etc/openvpn \
    -d -p 1194:1194/udp \
    --cap-add=NET_ADMIN \
    kylemanna/openvpn

The docker-ipsec-vpn-server requires more ports and privileges, while docker-openvpn has a simpler setup but needs additional steps for configuration.

Both projects offer easy-to-deploy VPN solutions, but cater to different use cases. docker-ipsec-vpn-server is more suitable for quick setups and mobile device compatibility, while docker-openvpn provides greater flexibility and advanced features for power users.

28,648

Set up a personal VPN in the cloud

Pros of algo

  • Supports multiple VPN protocols (WireGuard, IPsec/IKEv2)
  • Automated setup process for various cloud providers
  • Enhanced security features and hardened configurations

Cons of algo

  • Less flexible for customization compared to docker-openvpn
  • May require more technical knowledge for troubleshooting
  • Limited to specific supported platforms and providers

Code Comparison

algo:

- name: Install strongSwan
  apt:
    name:
      - strongswan
      - strongswan-plugin-eap-mschapv2
      - strongswan-plugin-eap-tls
    state: present

docker-openvpn:

FROM alpine:3.14

RUN echo "http://dl-cdn.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/* /var/cache/distfiles/*

The algo project focuses on automated deployment with predefined security configurations, while docker-openvpn provides a more flexible Docker-based solution. algo's code snippet shows package installation for strongSwan, while docker-openvpn's Dockerfile sets up the OpenVPN environment in an Alpine Linux container.

23,174

Streisand sets up a new server running your choice of WireGuard, OpenConnect, OpenSSH, OpenVPN, Shadowsocks, sslh, Stunnel, or a Tor bridge. It also generates custom instructions for all of these services. At the end of the run you are given an HTML file with instructions that can be shared with friends, family members, and fellow activists.

Pros of Streisand

  • Supports multiple VPN protocols and services (OpenVPN, WireGuard, Shadowsocks, etc.)
  • Automates the setup process for various cloud providers
  • Includes additional privacy-enhancing tools like Tor bridges

Cons of Streisand

  • More complex setup and maintenance due to its comprehensive nature
  • Potentially overkill for users who only need OpenVPN
  • Less frequently updated compared to docker-openvpn

Code Comparison

Streisand (Ansible playbook excerpt):

- name: Install OpenVPN
  apt:
    name: openvpn
    state: present

- name: Generate OpenVPN server config
  template:
    src: openvpn-server.conf.j2
    dest: /etc/openvpn/server.conf

docker-openvpn (Dockerfile excerpt):

FROM alpine:3.14

RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community/" >> /etc/apk/repositories && \
    apk add --update openvpn iptables bash easy-rsa && \
    ln -s /usr/share/easy-rsa/easyrsa /usr/local/bin && \
    rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /var/cache/distfiles/*

Both projects aim to simplify VPN deployment, but Streisand offers a broader range of services and automation for multiple cloud providers. docker-openvpn focuses solely on OpenVPN in a Docker container, providing a more lightweight and specialized solution. The code snippets highlight the different approaches: Streisand uses Ansible for configuration management, while docker-openvpn utilizes a Dockerfile for containerization.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

OpenVPN for Docker

Build Status Docker Stars Docker Pulls ImageLayers FOSSA Status

OpenVPN server in a Docker container complete with an EasyRSA PKI CA.

Extensively tested on Digital Ocean $5/mo node and has a corresponding Digital Ocean Community Tutorial.

Upstream Links

Quick Start

  • Pick a name for the $OVPN_DATA data volume container. It's recommended to use the ovpn-data- prefix to operate seamlessly with the reference systemd service. Users are encourage to replace example with a descriptive name of their choosing.

    OVPN_DATA="ovpn-data-example"
    
  • Initialize the $OVPN_DATA container that will hold the configuration files and certificates. The container will prompt for a passphrase to protect the private key used by the newly generated certificate authority.

    docker volume create --name $OVPN_DATA
    docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM
    docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
    
  • Start OpenVPN server process

    docker run -v $OVPN_DATA:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
    
  • Generate a client certificate without a passphrase

    docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full CLIENTNAME nopass
    
  • Retrieve the client configuration with embedded certificates

    docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
    

Next Steps

More Reading

Miscellaneous write-ups for advanced configurations are available in the docs folder.

Systemd Init Scripts

A systemd init script is available to manage the OpenVPN container. It will start the container on system boot, restart the container if it exits unexpectedly, and pull updates from Docker Hub to keep itself up to date.

Please refer to the systemd documentation to learn more.

Docker Compose

If you prefer to use docker-compose please refer to the documentation.

Debugging Tips

  • Create an environment variable with the name DEBUG and value of 1 to enable debug output (using "docker -e").

      docker run -v $OVPN_DATA:/etc/openvpn -p 1194:1194/udp --cap-add=NET_ADMIN -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
    
  • Consider setting up a systemd service for automatic start-up at boot time and restart in the event the OpenVPN daemon or Docker crashes.

How Does It Work?

Initialize the volume container using the kylemanna/openvpn image with the included 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 Dockerfile declares that directory as a volume. It means that you can start another container 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 the easyrsa command in the container's path. The EASYRSA_* environmental variables 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 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.

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 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).

Security Discussion

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).

  • The certificate authority key is kept in the container by default for 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 and the script ovpn_copy_server_files 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 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 $OVPN_DATA data volume. To remove it, remove the corresponding containers, $OVPN_DATA data volume and Docker image and it's completely removed. 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
  • Addition of tls-auth for HMAC security

Originally Tested On

  • Docker hosts:
    • server a Digital Ocean 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

License

FOSSA Status