From 37d99dd022e3b5c0c9d3437deedf3e19dc111016 Mon Sep 17 00:00:00 2001 From: TheMardy Date: Mon, 7 Oct 2019 19:05:14 +0200 Subject: [PATCH 1/3] Docs to wiki --- README.MD | 198 ++++++++++++++++++----------------------- docs/advanced.md | 20 ----- docs/backup.md | 21 ----- docs/clients.md | 47 ---------- docs/debug.md | 39 -------- docs/docker-compose.md | 77 ---------------- docs/docker-openvpn.te | 10 --- docs/docker.md | 52 ----------- docs/faqs.md | 26 ------ docs/ipv6.md | 101 --------------------- docs/otp.md | 76 ---------------- docs/paranoid.md | 49 ---------- docs/selinux.md | 25 ------ docs/static-ips.md | 24 ----- docs/systemd.md | 43 --------- docs/tcp.md | 45 ---------- 16 files changed, 85 insertions(+), 768 deletions(-) delete mode 100644 docs/advanced.md delete mode 100644 docs/backup.md delete mode 100644 docs/clients.md delete mode 100644 docs/debug.md delete mode 100644 docs/docker-compose.md delete mode 100644 docs/docker-openvpn.te delete mode 100644 docs/docker.md delete mode 100644 docs/faqs.md delete mode 100644 docs/ipv6.md delete mode 100644 docs/otp.md delete mode 100644 docs/paranoid.md delete mode 100644 docs/selinux.md delete mode 100644 docs/static-ips.md delete mode 100644 docs/systemd.md delete mode 100644 docs/tcp.md diff --git a/README.MD b/README.MD index 66148d6..8f30d39 100644 --- a/README.MD +++ b/README.MD @@ -1,6 +1,7 @@ # Multiplatform OpenVPN for Docker [![Version](https://img.shields.io/github/v/tag/themardy/docker-openvpn?label=version&style=flat-square)](https://github.com/TheMardy/docker-openvpn/releases) +![Travis (.org)](https://img.shields.io/travis/themardy/docker-openvpn) [![Actions Status](https://github.com/themardy/docker-openvpn/workflows/build/badge.svg)](https://github.com/themardy/docker-openvpn/actions) [![Docker Stars](https://img.shields.io/docker/stars/themardy/openvpn.svg)](https://hub.docker.com/r/themardy/openvpn/) [![Docker Pulls](https://img.shields.io/docker/pulls/themardy/openvpn.svg)](https://hub.docker.com/r/themardy/openvpn/) @@ -21,10 +22,87 @@ Original Credits: [kylemanna/docker-openvpn](https://github.com/kylemanna/docker | linux/386 | - | | linux/ppc64le | - | -Please [raise an issue 💬](https://github.com/TheMardy/docker-openvpn/issues) if you are able to test an untested platform 🙌 +Please [raise an issue 💬](https://github.com/TheMardy/docker-openvpn/issues) if you are able to test an untested platform 🙏 -# Original Readme: -## Quick Start +# Quick Start with docker-compose + +* Add a new service in docker-compose.yml + +```yaml +version: '2' +services: + openvpn: + cap_add: + - NET_ADMIN + image: themardy/openvpn + container_name: openvpn + ports: + - "1194:1194/udp" + restart: always + volumes: + - ./openvpn-data/conf:/etc/openvpn +``` + + +* Initialize the configuration files and certificates + +```bash +docker-compose run --rm openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM +docker-compose run --rm openvpn ovpn_initpki +``` + +* Fix ownership (depending on how to handle your backups, this may not be needed) + +```bash +sudo chown -R $(whoami): ./openvpn-data +``` + +* Start OpenVPN server process + +```bash +docker-compose up -d openvpn +``` + +* You can access the container logs with + +```bash +docker-compose logs -f +``` + +* Generate a client certificate + +```bash +export CLIENTNAME="your_client_name" +# with a passphrase (recommended) +docker-compose run --rm openvpn easyrsa build-client-full $CLIENTNAME +# without a passphrase (not recommended) +docker-compose run --rm openvpn easyrsa build-client-full $CLIENTNAME nopass +``` + +* Retrieve the client configuration with embedded certificates + +```bash +docker-compose run --rm openvpn ovpn_getclient $CLIENTNAME > $CLIENTNAME.ovpn +``` + +* Revoke a client certificate + +```bash +# Keep the corresponding crt, key and req files. +docker-compose run --rm openvpn ovpn_revokeclient $CLIENTNAME +# Remove the corresponding crt, key and req files. +docker-compose run --rm openvpn ovpn_revokeclient $CLIENTNAME remove +``` + +## Debugging Tips + +* Create an environment variable with the name DEBUG and value of 1 to enable debug output (using "docker -e"). + +```bash +docker-compose run -e DEBUG=1 -p 1194:1194/udp openvpn +``` + +# Quick Start with docker run * 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 @@ -58,7 +136,7 @@ Please [raise an issue 💬](https://github.com/TheMardy/docker-openvpn/issues) ### More Reading Miscellaneous write-ups for advanced configurations are available on the -[Wiki](../../wiki). +[Wiki](https://github.com/TheMardy/docker-openvpn/wiki/). ### Systemd Init Scripts @@ -66,11 +144,7 @@ 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 [Wiki](../../wiki) to learn more. - -### Docker Compose - -If you prefer to use `docker-compose` please refer to the [Wiki](../../wiki). +Please refer to the [Wiki](https://github.com/TheMardy/docker-openvpn/wiki/) to learn more. ## Debugging Tips @@ -88,108 +162,6 @@ If you prefer to use `docker-compose` please refer to the [Wiki](../../wiki). $ dig google.com # won't use the search directives in resolv.conf $ nslookup google.com # will use search -* Consider setting up a [systemd service](/docs/systemd.md) for automatic +* Consider setting up a [systemd service](https://github.com/TheMardy/docker-openvpn/wiki/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 `themardy/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, `themardy/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, `themardy/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 the [Wiki](../../wiki). - -## 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 uses`192.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`](/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 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 (themardy/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. + crashes. \ No newline at end of file diff --git a/docs/advanced.md b/docs/advanced.md deleted file mode 100644 index 75726db..0000000 --- a/docs/advanced.md +++ /dev/null @@ -1,20 +0,0 @@ -# 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 `-v $OVPN_DATA:/etc/openvpn` 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 themardy/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM:1194 - docker run --rm -v $PWD:/etc/openvpn -it themardy/openvpn ovpn_initpki - vim openvpn.conf - docker run --rm -v $PWD:/etc/openvpn -it themardy/openvpn easyrsa build-client-full CLIENTNAME nopass - docker run --rm -v $PWD:/etc/openvpn themardy/openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn - -* Start the server with: - - docker run -v $PWD:/etc/openvpn -d -p 1194:1194/udp --privileged themardy/openvpn diff --git a/docs/backup.md b/docs/backup.md deleted file mode 100644 index 30151b8..0000000 --- a/docs/backup.md +++ /dev/null @@ -1,21 +0,0 @@ -# Backing Up Configuration and Certificates - -## Security - -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](/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. Ensure there is very limited access to it.** - -## Backup to Archive - - docker run -v $OVPN_DATA:/etc/openvpn --rm themardy/openvpn tar -cvf - -C /etc openvpn | xz > openvpn-backup.tar.xz - -## Restore to New Data Volume - -Creates an volume container named `$OVPN_DATA` to extract the data to. - - docker volume create --name $OVPN_DATA - xzcat openvpn-backup.tar.xz | docker run -v $OVPN_DATA:/etc/openvpn -i themardy/openvpn tar -xvf - -C /etc diff --git a/docs/clients.md b/docs/clients.md deleted file mode 100644 index 15d6d41..0000000 --- a/docs/clients.md +++ /dev/null @@ -1,47 +0,0 @@ -# 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. - -## Client List - -See an overview of the configured clients, including revocation and expiration status: - - docker run --rm -it -v $OVPN_DATA:/etc/openvpn themardy/openvpn ovpn_listclients - - The output is generated using `openssl verify`. Error codes from the verification process different from `X509_V_ERR_CERT_HAS_EXPIRED` or `X509_V_ERR_CERT_REVOKED` will show the status `INVALID`. - -## 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 -v $OVPN_DATA:/etc/openvpn --volume /tmp/openvpn_clients:/etc/openvpn/clients themardy/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) using [`ovpn_revokeclient`](/bin/ovpn_revokeclient) script : - - docker run --rm -it -v $OVPN_DATA:/etc/openvpn themardy/openvpn ovpn_revokeclient client1 - -The OpenVPN server will read this change every time a client connects (no need to restart server) and deny clients access using revoked certificates. - -You can optionally pass `remove` as second parameter to ovpn_revokeclient to remove the corresponding crt, key and req files : - - docker run --rm -it -v $OVPN_DATA:/etc/openvpn themardy/openvpn ovpn_revokeclient client1 remove diff --git a/docs/debug.md b/docs/debug.md deleted file mode 100644 index dada112..0000000 --- a/docs/debug.md +++ /dev/null @@ -1,39 +0,0 @@ -# Debugging - -Random things I do to debug the containers. - -## Login Shells - -* Create a shell in the running docker container with `docker exec`. -* To modify the data, you can also mount the data container and modify it with - - docker run --rm -it -v $OVPN_DATA:/etc/openvpn themardy/openvpn bash -l - -## Stream OpenVPN Logs - -1. Get the container's name or container ID: - - root@vpn:~/docker-openvpn# docker ps - CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES - ed335aaa9b82 themardy/openvpn:latest ovpn_run 5 minutes ago Up 5 minutes 0.0.0.0:1194->1194/udp sad_lovelace - -2. Tail the logs: - - root@vpn:~/docker-openvpn# docker logs -f sad_lovelace - + mkdir -p /dev/net - + [ ! -c /dev/net/tun ] - + mknod /dev/net/tun c 10 200 - + [ ! -d /etc/openvpn/ccd ] - + iptables -t nat -A POSTROUTING -s 192.168.254.0/24 -o eth0 -j MASQUERADE - + iptables -t nat -A POSTROUTING -s 192.168.255.0/24 -o eth0 -j MASQUERADE - + conf=/etc/openvpn/openvpn.conf - + [ ! -s /etc/openvpn/openvpn.conf ] - + conf=/etc/openvpn/udp1194.conf - + openvpn --config /etc/openvpn/udp1194.conf - Tue Jul 1 06:56:48 2014 OpenVPN 2.3.2 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [eurephia] [MH] [IPv6] built on Mar 17 2014 - Tue Jul 1 06:56:49 2014 Diffie-Hellman initialized with 2048 bit key - Tue Jul 1 06:56:49 2014 Control Channel Authentication: using '/etc/openvpn/pki/ta.key' as a OpenVPN static key file - Tue Jul 1 06:56:49 2014 Outgoing Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication - Tue Jul 1 06:56:49 2014 Incoming Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication - Tue Jul 1 06:56:49 2014 Socket Buffers: R=[212992->131072] S=[212992->131072] - diff --git a/docs/docker-compose.md b/docs/docker-compose.md deleted file mode 100644 index 09e010f..0000000 --- a/docs/docker-compose.md +++ /dev/null @@ -1,77 +0,0 @@ -# Quick Start with docker-compose - -* Add a new service in docker-compose.yml - -```yaml -version: '2' -services: - openvpn: - cap_add: - - NET_ADMIN - image: themardy/openvpn - container_name: openvpn - ports: - - "1194:1194/udp" - restart: always - volumes: - - ./openvpn-data/conf:/etc/openvpn -``` - - -* Initialize the configuration files and certificates - -```bash -docker-compose run --rm openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM -docker-compose run --rm openvpn ovpn_initpki -``` - -* Fix ownership (depending on how to handle your backups, this may not be needed) - -```bash -sudo chown -R $(whoami): ./openvpn-data -``` - -* Start OpenVPN server process - -```bash -docker-compose up -d openvpn -``` - -* You can access the container logs with - -```bash -docker-compose logs -f -``` - -* Generate a client certificate - -```bash -export CLIENTNAME="your_client_name" -# with a passphrase (recommended) -docker-compose run --rm openvpn easyrsa build-client-full $CLIENTNAME -# without a passphrase (not recommended) -docker-compose run --rm openvpn easyrsa build-client-full $CLIENTNAME nopass -``` - -* Retrieve the client configuration with embedded certificates - -```bash -docker-compose run --rm openvpn ovpn_getclient $CLIENTNAME > $CLIENTNAME.ovpn -``` - -* Revoke a client certificate - -```bash -# Keep the corresponding crt, key and req files. -docker-compose run --rm openvpn ovpn_revokeclient $CLIENTNAME -# Remove the corresponding crt, key and req files. -docker-compose run --rm openvpn ovpn_revokeclient $CLIENTNAME remove -``` - -## Debugging Tips - -* Create an environment variable with the name DEBUG and value of 1 to enable debug output (using "docker -e"). - -```bash -docker-compose run -e DEBUG=1 -p 1194:1194/udp openvpn -``` diff --git a/docs/docker-openvpn.te b/docs/docker-openvpn.te deleted file mode 100644 index d3a1d22..0000000 --- a/docs/docker-openvpn.te +++ /dev/null @@ -1,10 +0,0 @@ -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; - diff --git a/docs/docker.md b/docs/docker.md deleted file mode 100644 index b7bede5..0000000 --- a/docs/docker.md +++ /dev/null @@ -1,52 +0,0 @@ -# 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@:/#` 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 diff --git a/docs/faqs.md b/docs/faqs.md deleted file mode 100644 index 59bf660..0000000 --- a/docs/faqs.md +++ /dev/null @@ -1,26 +0,0 @@ -# Frequently Asked Questions - -## How do I edit `openvpn.conf`? - -Use a Docker image with an editor and connect the volume container: - - docker run -v $OVPN_DATA:/etc/openvpn --rm -it themardy/openvpn vi /etc/openvpn/openvpn.conf - - -## Why not keep everything in one image? - -The run-time image (`themardy/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 themardy/openvpn` and then `docker run ... themardy/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 ... - -## I need to add some extra configurations to openvpn.conf, How can I do that ? - -You can pass multiple (**-e**) options to `ovpn_genconfig`. For example, if you need to add _'duplicate-cn'_ and _'topology subnet'_ to the server configuration you could do something like this: - - ovpn_genconfig -e 'duplicate-cn' -e 'topology subnet' -u udp://VPN.SERVERNAME.COM diff --git a/docs/ipv6.md b/docs/ipv6.md deleted file mode 100644 index bc715d6..0000000 --- a/docs/ipv6.md +++ /dev/null @@ -1,101 +0,0 @@ -# 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/themardy/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 - -This feature requires a docker daemon with working IPv6 support. - -This will allow connections over IPv4 and IPv6. - -Generate server configuration with the udp6 or tcp6 protocol: - - docker run -v $OVPN_DATA:/etc/openvpn --rm themardy/openvpn ovpn_genconfig -u udp6://VPN.SERVERNAME.COM - docker run -v $OVPN_DATA:/etc/openvpn --rm themardy/openvpn ovpn_genconfig -u tcp6://VPN.SERVERNAME.COM diff --git a/docs/otp.md b/docs/otp.md deleted file mode 100644 index ce0b045..0000000 --- a/docs/otp.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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. - -* Choose a more secure [cipher](https://community.openvpn.net/openvpn/wiki/SWEET32) to use because since [OpenVPN 2.3.13](https://community.openvpn.net/openvpn/wiki/ChangesInOpenvpn23#OpenVPN2.3.13) the default openvpn cipher BF-CBC will cause a renegotiated connection every 64 MB of data - -* Generate server configuration with `-2` and `-C $CIPHER` options - - docker run -v $OVPN_DATA:/etc/openvpn --rm themardy/openvpn ovpn_genconfig -u udp://vpn.example.com -2 -C $CIPHER - -* Generate your client certificate (possibly without a password since you're using OTP) - - docker run -v $OVPN_DATA:/etc/openvpn --rm -it themardy/openvpn easyrsa build-client-full nopass - -* Generate authentication configuration for your client. -t is needed to show QR code, -i is optional for interactive usage - - docker run -v $OVPN_DATA:/etc/openvpn --rm -t themardy/openvpn ovpn_otp_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. - -![Example QR Code](https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/user@example.com%3Fsecret%3DKEYZ66YEXMXDHPH5) - -Generate client configuration for `` 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/.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 -v $OVPN_DATA:/etc/openvpn --rm -it themardy/openvpn bash -# Then in container you have pamtester utility already installed -which pamtester -# To check authentication use this command that will prompt for a valid code from Authenticator APP -pamtester -v openvpn authenticate -``` - -In the last command `` should be replaced by the exact string you used in the ovpn_otp_user command. - -If you configured everything correctly you should get authenticated by entering a OTP code from the app. diff --git a/docs/paranoid.md b/docs/paranoid.md deleted file mode 100644 index 7c38470..0000000 --- a/docs/paranoid.md +++ /dev/null @@ -1,49 +0,0 @@ -# Advanced security - -## Keep the CA root key safe -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 themardy/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM - docker run --net=none --rm -t -i -v $PWD:/etc/openvpn themardy/openvpn ovpn_initpki - docker run --net=none --rm -t -i -v $PWD:/etc/openvpn themardy/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 ciphers 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 -v $OVPN_DATA:/etc/openvpn --net=none --rm themardy/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 - -## EasyRSA and 4096 bit RSA Keys - -EasyRSA will generate 4096 bit RSA keys when the `-e EASYRSA_KEY_SIZE=4096` argument is added to `ovpn_initpki` and `easyrsa build-client-full` commands. - - docker run -e EASYRSA_KEY_SIZE=4096 -v $OVPN_DATA:/etc/openvpn --rm -it themardy/openvpn ovpn_initpki - docker run -e EASYRSA_KEY_SIZE=4096 -v $OVPN_DATA:/etc/openvpn --rm -it themardy/openvpn easyrsa build-client-full CLIENTNAME nopass - -## Logging and stdout - -Because you are running within Docker, remember that any command that generates output to stdout may also log that output through Docker's log-driver mechanism. That may mean that e.g. keying material generated by `ovpn_getclient` will be logged somewhere that you don't want it to be logged. - -A simple way to avoid having Docker log output for a given command is to run with `--log-driver=none`, e.g - - docker run -v $OVPN_DATA:/etc/openvpn --log-driver=none --rm themardy/openvpn ovpn_getclient USER > USER.ovpn - -## Additional Resources - -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. diff --git a/docs/selinux.md b/docs/selinux.md deleted file mode 100644 index b70bd77..0000000 --- a/docs/selinux.md +++ /dev/null @@ -1,25 +0,0 @@ -# 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 diff --git a/docs/static-ips.md b/docs/static-ips.md deleted file mode 100644 index cc906d4..0000000 --- a/docs/static-ips.md +++ /dev/null @@ -1,24 +0,0 @@ -# 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 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 -v $OVPN_DATA:/etc/openvpn -i --rm themardy/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 data volume with a `bash` container, note only changes in /etc/openvpn will persist: - - docker run -v $OVPN_DATA:/etc/openvpn -it --rm themardy/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 -v $OVPN_DATA:/etc/openvpn --rm themardy/openvpn ovpn_genconfig diff --git a/docs/systemd.md b/docs/systemd.md deleted file mode 100644 index 2e01e09..0000000 --- a/docs/systemd.md +++ /dev/null @@ -1,43 +0,0 @@ -# Docker + OpenVPN systemd Service - -The systemd service aims to make the update and invocation of the -`docker-openvpn` container seamless. It automatically downloads the latest -`docker-openvpn` image and instantiates a Docker container with that image. At -shutdown it cleans-up the old container. - -In the event the service dies (crashes, or is killed) systemd will attempt to -restart the service every 10 seconds until the service is stopped with -`systemctl stop docker-openvpn@NAME.service`. - -A number of IPv6 hacks are incorporated to workaround Docker shortcomings and -are harmless for those not using IPv6. - -To use and enable automatic start by systemd: - -1. Create a Docker volume container named `ovpn-data-NAME` where `NAME` is the - user's choice to describe the use of the container. In this example - configuration, `NAME=example`. - - OVPN_DATA="ovpn-data-example" - docker volume create --name $OVPN_DATA - -2. Initialize the data container, but don't start the container : - - docker run -v $OVPN_DATA:/etc/openvpn --rm themardy/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM - docker run -v $OVPN_DATA:/etc/openvpn --rm -it themardy/openvpn ovpn_initpki - -3. Download the [docker-openvpn@.service](https://raw.githubusercontent.com/themardy/docker-openvpn/master/init/docker-openvpn%40.service) - file to `/etc/systemd/system`: - - curl -L https://raw.githubusercontent.com/themardy/docker-openvpn/master/init/docker-openvpn%40.service | sudo tee /etc/systemd/system/docker-openvpn@.service - -4. Enable and start the service with: - - systemctl enable --now docker-openvpn@example.service - -5. Verify service start-up with: - - systemctl status docker-openvpn@example.service - journalctl --unit docker-openvpn@example.service - -For more information, see the [systemd manual pages](https://www.freedesktop.org/software/systemd/man/index.html). diff --git a/docs/tcp.md b/docs/tcp.md deleted file mode 100644 index ca8bfea..0000000 --- a/docs/tcp.md +++ /dev/null @@ -1,45 +0,0 @@ -# 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. - -Another example would be trying to open a VPN connection from within a very restrictive network. In some cases port 1194, or even UDP traffic on any port, may be restricted by network policy. Because TCP traffic on port 443 is used for normal TLS (https) web browsing, it is very unlikely to be blocked. - -## Using TCP -Those requiring TCP connections should initialize the data container by specifying the TCP protocol and port number: - - docker run -v $OVPN_DATA:/etc/openvpn --rm themardy/openvpn ovpn_genconfig -u tcp://VPN.SERVERNAME.COM:443 - docker run -v $OVPN_DATA:/etc/openvpn --rm -it themardy/openvpn ovpn_initpki - -Because the server container always exposes port 1194, regardless of the -specified protocol, adjust the mapping appropriately: - - docker run -v $OVPN_DATA:/etc/openvpn -d -p 443:1194/tcp --cap-add=NET_ADMIN themardy/openvpn - -## Running a Second Fallback TCP Container -Instead of choosing between UDP and TCP, you can use both. A single instance of OpenVPN can only listen for a single protocol on a single port, but this image makes it easy to run two instances simultaneously. After building, configuring, and starting a standard container listening for UDP traffic on 1194, you can start a second container listening for tcp traffic on port 443: - - docker run -v $OVPN_DATA:/etc/openvpn --rm -p 443:1194/tcp --privileged themardy/openvpn ovpn_run --proto tcp - -`ovpn_run` will load all the values from the default config file, and `--proto tcp` will override the protocol setting. - -This allows you to use UDP most of the time, but fall back to TCP on the rare occasion that you need it. - -Note that you will need to configure client connections manually. At this time it is not possible to generate a client config that will automatically fall back to the TCP connection. - -## Forward HTTP/HTTPS connection to another TCP port -You might run into cases where you want your OpenVPN server listening on TCP port 443 to allow connection behind a restricted network, but you already have a webserver on your host running on that port. OpenVPN has a built-in option named `port-share` that allow you to proxy incoming traffic that isn't OpenVPN protocol to another host and port. - -First, change the listening port of your existing webserver (for instance from 443 to 4433). - -Then initialize the data container by specifying the TCP protocol, port 443 and the port-share option: - - docker run -v $OVPN_DATA:/etc/openvpn --rm themardy/openvpn ovpn_genconfig \ - -u tcp://VPN.SERVERNAME.COM:443 \ - -e 'port-share VPN.SERVERNAME.COM 4433' - -Then proceed to initialize the pki, create your users and start the container as usual. - -This will proxy all non OpenVPN traffic incoming on TCP port 443 to TCP port 4433 on the same host. This is currently only designed to work with HTTP or HTTPS protocol. From 8351a773e1f53fbc70a5d1312e814aec74c49c77 Mon Sep 17 00:00:00 2001 From: TheMardy Date: Mon, 7 Oct 2019 19:15:58 +0200 Subject: [PATCH 2/3] Set default DNS Servers to Cloudflare --- README.MD | 12 ++---------- bin/ovpn_genconfig | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/README.MD b/README.MD index 8f30d39..a1b3fc8 100644 --- a/README.MD +++ b/README.MD @@ -24,7 +24,7 @@ Original Credits: [kylemanna/docker-openvpn](https://github.com/kylemanna/docker Please [raise an issue 💬](https://github.com/TheMardy/docker-openvpn/issues) if you are able to test an untested platform 🙏 -# Quick Start with docker-compose +## Quick Start with docker-compose * Add a new service in docker-compose.yml @@ -94,15 +94,7 @@ docker-compose run --rm openvpn ovpn_revokeclient $CLIENTNAME docker-compose run --rm openvpn ovpn_revokeclient $CLIENTNAME remove ``` -## Debugging Tips - -* Create an environment variable with the name DEBUG and value of 1 to enable debug output (using "docker -e"). - -```bash -docker-compose run -e DEBUG=1 -p 1194:1194/udp openvpn -``` - -# Quick Start with docker run +## Quick Start with docker run * 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 diff --git a/bin/ovpn_genconfig b/bin/ovpn_genconfig index c2ebca6..56dc82c 100644 --- a/bin/ovpn_genconfig +++ b/bin/ovpn_genconfig @@ -285,7 +285,7 @@ fi # Apply defaults. If dns servers were not defined with -n, use google nameservers set +u -[ -z "$OVPN_DNS_SERVERS" ] && OVPN_DNS_SERVERS=("8.8.8.8" "8.8.4.4") +[ -z "$OVPN_DNS_SERVERS" ] && OVPN_DNS_SERVERS=("1.1.1.1" "1.0.0.1") [ -z "$OVPN_PROTO" ] && OVPN_PROTO=udp [ -z "$OVPN_PORT" ] && OVPN_PORT=1194 set -u From 3ded7c709964f9ba03e209b8aadae4af7f4b644c Mon Sep 17 00:00:00 2001 From: TheMardy Date: Mon, 7 Oct 2019 19:29:35 +0200 Subject: [PATCH 3/3] Fix DNS Check test --- test/tests/conf_options/container.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tests/conf_options/container.sh b/test/tests/conf_options/container.sh index b0fb07d..b74e83f 100644 --- a/test/tests/conf_options/container.sh +++ b/test/tests/conf_options/container.sh @@ -88,8 +88,8 @@ test_config "${SERVER_CONF}" "^route\s\+192.168.254.0\s\+255.255.255.0" test_config "${SERVER_CONF}" '^push\s\+"block-outside-dns"' # 10. Should see a push of 'dhcp-option DNS' by default -test_config "${SERVER_CONF}" '^push\s\+"dhcp-option\s\+DNS\s\+8.8.8.8"' -test_config "${SERVER_CONF}" '^push\s\+"dhcp-option\s\+DNS\s\+8.8.4.4"' +test_config "${SERVER_CONF}" '^push\s\+"dhcp-option\s\+DNS\s\+1.1.1.1"' +test_config "${SERVER_CONF}" '^push\s\+"dhcp-option\s\+DNS\s\+1.0.0.1"' ## Test for keepalive # 11. keepalive config