107 Commits
v0.2 ... v1.1.0

Author SHA1 Message Date
1498795de2 ovpn_copy_server_files: Use short flags with rm
* The busybox tool in the alpine distro doesn't support long flags.
2015-09-29 11:42:17 -07:00
f00de363c7 ovpn_copy_server_files: Copy files without rsync
* Hack around the missing rsync by using tar to preserve the directory
  structure.
* Fixes #73
2015-09-29 11:28:04 -07:00
7f58926aa2 tests: Add test for paranoid ovpn_copy_server_files
* Make sure this works
* Related to #73
2015-09-29 10:44:53 -07:00
98340d7602 Merge pull request #71 from kylemanna/travis-ci
Add Travis CI Testing
2015-09-22 15:02:50 -07:00
9459804a1d README: Add Travis CI build status
* Keeps people honest
2015-09-22 14:36:19 -07:00
b298eb16bc travis-ci: Extend test to actually do a connection
* Start the server
* Start the client
* Connect
* Profit
2015-09-22 14:32:55 -07:00
2c3284acd6 travis-ci: Initial build test
* Build and reports package version.
2015-09-22 08:59:15 -07:00
314eb15507 Merge pull request #69 from ypid/docker_no_network_paranoid_doc
Only setup networking for containers which need it.
2015-09-08 06:54:42 -07:00
ee9f4531ad Only setup networking for containers which need it.
This should mitigate a hypothetical compromise of the scripts used to
manage the CA and other sensitive material.

The examples should still work and make sense although I have not tried
all of them with this change applied.

Note that I did not append the --net=none to all examples because in
some cases network is probably wanted.

* Changing this for all docs was not accepted by @kylemanna.
  https://github.com/kylemanna/docker-openvpn/pull/65#issuecomment-138559257
2015-09-08 15:34:58 +02:00
41f7fd22ad Merge pull request #66 from ypid/copy_server_not_symlink
ovpn_copy_server_files: Copy openvpn.conf instead of symlinking locally.
2015-09-07 20:03:09 -07:00
d08df0189b Dockerfile: Chmod everything in /usr/local/bin
* Keep it simple.
* Nothing should ever be put in bin that isn't excutable.
2015-09-07 19:21:55 -07:00
d96378a391 Dockerfile: Streamline tarball extraction
* No point in writing it to the disk and then deleting it
* Extract it in place
2015-09-07 19:21:07 -07:00
32029c98c8 Update to easyrsa 3.0
virtual size 60mb smaller, git replaced by curl
2015-09-08 01:11:32 +03:00
3df53012b6 ovpn_copy_server_files: Copy openvpn.conf instead of symlinking locally.
Symlinked files can be resolved by rsync when using the configuration on remote
servers but for local testing having the actual file is beneficial.
2015-08-27 21:19:27 +02:00
74c4ca94a7 Merge pull request #62 from ypid/docs-rework
Updated documentation.
2015-08-26 08:42:58 -07:00
b96a91e876 Merge pull request #63 from ypid/allow_ciper_setting
Allow to change security related options tls-cipher, cipher and auth.
2015-08-26 08:42:30 -07:00
407506392f Merge pull request #64 from ypid/copy_server_files-ensure-rm
ovpn_copy_server_files: Ensure that no other keys then the one for the server is present.
2015-08-26 08:41:24 -07:00
bf9f58f8e1 Reverted Github flavored markdown Shell syntax highlighting.
Sorry again for the inconvenience.
2015-08-26 13:12:18 +02:00
050d4a1f82 ovpn_copy_server_files: Ensure that no other keys then the one for the server is present.
When creating a multi-server setup I used a partly copied, partly
symlinked directory structure for the different servers after creating a
certificate for each server with `easyrsa build-server-full`. In that
process I also copied the `server` directory.
The rsync command does not delete files which are not excluded so it
included the correct server key and the original one which can be a
security risk.
2015-08-26 13:00:17 +02:00
d6209eebc2 Allow to change security related options tls-cipher, cipher and auth. 2015-08-26 12:56:40 +02:00
2d16231c3c Updated documentation.
* Related to https://github.com/kylemanna/docker-openvpn/pull/54
* Allow better syntax highlighting.
* Added/Fixed hyperlinks.
* Spelling.
2015-08-25 12:40:02 +02:00
15ac3c89b0 Merge pull request #60 from wernerb/master
Set custom OVPN_NATDEVICE when using --net=host to custom interface.
2015-08-24 09:04:51 -07:00
0181bb93d6 Add ability to set OVPN_NATDEVICE to target specific interface when using net=host 2015-08-24 17:19:40 +02:00
e557222753 Merge pull request #59 from thomastweets/master
Add a parameter to use TAP instead of TUN device.
2015-08-18 16:38:18 -07:00
3703d3afc3 Add a parameter to use TAP instead of TUN device. 2015-08-19 00:46:07 +02:00
d3d11b660a docs: Update docker key resource
* Update link to docker.com as the previous URL would redirect
* Add `-L` flag to follow future location headers
2015-08-15 19:21:09 -07:00
4868a35bd3 docs: Second pass on IPv6
Still needs more work, but updated to reflect the templated systemd file.
2015-08-12 14:08:59 -07:00
bce012b92a Merge pull request #57 from ypid/fixed-ipv6-docs
Quick read of ipv6 docs and small fixes.
2015-08-12 13:58:57 -07:00
7007c49d34 Reverted docker service restart command to use systemctl directly. 2015-08-12 22:04:01 +02:00
c679404695 Quick read of ipv6 docs and small fixes.
* Why on earth does one directly edit the systemd/system/docker.service
  file just to add a start argument?
* Fixed typos.
* I have not fully tested it yet, but I will when I have time.
2015-08-11 23:18:41 +02:00
2508abd5ad run: Fail gracefully when IPv6 fails
* Fail gracefully but complain in the log when --privileged isn't used
  for docker run.
* IPv6 is in development for the time being.
* Closes #56
2015-08-09 18:04:05 -07:00
149cd3a3a3 systemd: Set upstream image to latest
* No longer is the image tagged dev following the merge.
2015-08-07 12:12:37 -07:00
1f47f361eb Merge pull request #55 from kylemanna/dev
Merge Development Branch
2015-08-07 11:14:59 -07:00
d89cbe5ba3 Merge pull request #54 from pushrax/remove-dh-client-config
Remove dh param from client config
2015-08-05 06:38:23 -07:00
02c3ee63a1 Remove dh param from client config 2015-08-04 23:07:47 -04:00
34d9601e6e ovpn_run: Assume /etc/openvpn is read-only
* Systemd service currently marks the mount as read-only, and this is
  regarded as good practice for server/daemon only operation.
* Don't create /etc/openvpn/ccd as the mount may be read-only.
* Append the client-config-dir command line argument if it is found to
  avoid mkdir operation.
* Mount can easily be modified using a different docker run line with
  ":ro" on the volume mount.
2015-07-27 20:26:43 -07:00
5a1e642177 init: systemd: Use systemd style config overrides
* RIP hacky /etc/default/foo style environement sourcing hack
2015-07-11 08:50:24 -07:00
313d1e756c init: Update init file to be a template
* Useful for systems with several OpenVPN docker containers running.
2015-07-11 08:31:58 -07:00
7a3cc674f0 docs: backup: Correct mindless typos
* Correct minor grammatical typos
2015-07-10 11:27:35 -07:00
08d8116e31 docs: faq: How do I edit openvpn.conf?
* It gets asked too many times.
2015-07-06 08:55:42 -07:00
017580fdaa docs: ipv6: Add section enabling Docker IPv6
* Oops, doesn't work without this.
2015-07-05 22:11:19 -07:00
0edc11b585 docs: docker: Install apt dependencies
* Otherwise it's annoying without it.
2015-07-05 21:52:19 -07:00
155c4d4b90 docs: docker: Crash course on installation
* Nothing less nothing more.
2015-07-05 21:48:10 -07:00
56a8e735b6 docs: ipv6: Add initial development guide
* Work in progress.
2015-07-05 21:28:44 -07:00
9c8d195880 init: Add docker-openvpn systemd service file
* Works with IPv6 thanks to ExecStartPost.
2015-07-05 21:08:47 -07:00
e6f7904344 run: Add IPv6 forwarding if default route
* Enable IPv6 forwarding if docker daemon provided a default route
* For now this requires the --privileged flag, but this could be hacked
  around using `ip netns` madness.
2015-07-05 21:07:06 -07:00
6aca273d89 getclient: Use openssl to prune comments
* The EasyRSA tools create a certificate file with all the metadata
  readable.  This makes the config file larger then it needs to be, so
  prune it.
* Retrieve text files with `openssl x509 -in <crt> -noout -text`
2015-07-05 21:07:04 -07:00
e3655b5115 init: Move upstart file to init directory
* No functional changes.
2015-07-05 21:07:00 -07:00
1078267db5 Dockerfile: Clarify port mapping
* Extend comment about port mapping since everyone seems to want to run
  on port 443/tcp.
* Accept that nobody (except the already competent) will read the
  comment and ask anyway.
2015-06-21 22:55:16 -07:00
27bb8c7149 README: Add example service
* Example service to demo the container.
2015-06-21 22:35:46 -07:00
868da2ddac Merge pull request #49 from ypid/copy-server-create-ccd
Create ccd directory to prevent error if /etc is mounted read-only.
2015-05-31 16:00:39 -07:00
7399ff7bbd Create ccd directory to prevent error if /etc is mounted read-only.
* mkdir: cannot create directory '/etc/openvpn/ccd': Read-only file system
2015-05-31 22:10:54 +02:00
e0f7856e6f Merge pull request #48 from ypid/optimized-copy-server-script
Optimized ovpn_copy_server_files script. No need to copy the config files.
2015-05-30 16:09:50 -07:00
a52a9cdc8d Merge pull request #47 from ypid/added-raw-client-config
Added variable OVPN_ADDITIONAL_CLIENT_CONFIG use arbitrary openvpn configuration options.
2015-05-30 16:09:25 -07:00
d1ae4dd305 Merge pull request #46 from ypid/fixed-docs
Using better example in docs.
2015-05-30 16:08:54 -07:00
e361e757da Optimized ovpn_copy_server_files script. No need to copy the config files.
* rsync can copy the actual files.
* This change makes it easier to modifier the configuration and sync it
  to the server. You only have to execute the ovpn_copy_server_files
  once.
2015-05-31 00:52:33 +02:00
ca78b46723 Added variable OVPN_ADDITIONAL_CLIENT_CONFIG use arbitrary openvpn configuration options. 2015-05-30 23:03:17 +02:00
2e2c66b978 Using better example in docs. 2015-05-30 23:00:53 +02:00
5e4bad7bc4 license: Migrate from AGPLv3 -> MIT
* More liberal license
* Closes #43
2015-05-12 12:52:25 -07:00
debf45ae46 Changed license of scripts I wrote to MIT. Related to #43. 2015-05-12 21:24:59 +02:00
e53492850f crl: Pass crl-verify if found
* Empty CRLs don't work.
* Avoids confusing easyrsa during the init step where it thinks an
  existing PKI configuration exists.
* Add to ovpn_run to help users that are upgrading and ran genconfig
  which now depends on the file being present.
* Use a hardlink to tip toe around permissions issues.
2015-05-12 02:10:43 -07:00
978e072d29 docs: Fix typo to CRL steps
* Copy paste error. Oops.
2015-05-11 10:48:09 -07:00
5021bad597 ovpn: Add support for revoking certificates (CRL)
* Add this much needed missing feature.  Easy RSA makes it... easy.
2015-05-11 10:41:25 -07:00
bcb55f6255 docs: Tweak case and arguments
* Makes the reading more uniform with the rest of the documentation.
2015-05-11 10:32:58 -07:00
c3024ce335 genconfig: Remove duplicate-cn mention
* Remove the commented out duplicate-cn configuration option
* Leads to confusion
* Related #42
2015-05-09 15:19:24 -07:00
2f9947c8e4 run: Pass cmd line arguments to openvpn
* Pass command line arguments to openvpn if passed in.  Enables users to
  easily override or add settings.
* Resolves #42
2015-05-09 15:18:53 -07:00
35c5d7bf70 license: Add AGPLv3 license
* Not sure how I missed this for so long.
2015-03-20 22:32:48 -07:00
bf34f341fc Merge remote-tracking branch 'ypid/getclient' into dev 2015-03-20 16:54:22 -07:00
a42a42885e Merge pull request #37 from ypid/fix-docs-paranoid
Fix paranoid doc.
2015-03-20 11:49:26 -07:00
47cc0e3ae6 Fixed based on the review by @kylemanna. Thanks. 2015-03-14 13:22:28 +01:00
06c005a449 Fixed up Markdown. 2015-03-14 13:00:11 +01:00
190ab9ae51 Fixed typos. 2015-03-14 12:59:07 +01:00
f208847f54 Merge pull request #34 from ypid/master
Wrote script to copy only the needed files to the docker host which runs the docker openvpn server.
2015-03-12 21:03:28 -07:00
f431d179aa Fixed spelling. 2015-03-13 02:00:04 +01:00
fd4a5dc38e EASYRSA_PKI might not be defined. 2015-03-13 00:43:50 +01:00
e6e2221d8b Allow to export separated client config and wrote ovpn_getclient_all. 2015-03-13 00:32:40 +01:00
3c64367583 Removed the --dry-run from rsync. Make it actually do something. 2015-03-12 23:49:49 +01:00
5e514721ff Added documentation for ovpn_copy_server_files. 2015-03-12 23:11:33 +01:00
88c76c787e genconfig: Turn off exit on error at end
* Need to check return status of diff, but don't want a false return
  code to exit the script.
* Fixes #35
2015-03-09 09:19:38 -07:00
3d2d839d0b Wrote script to copy only the needed files to the docker host which runs the docker openvpn server.
* For the truly paranoid users, never keep any keys (i.e. client and
  certificate authority) in the docker container to begin with :).
2015-03-08 22:40:08 +01:00
8d8f19d951 genconfig: Describe backup conf deletion
* Handle back-up configuration deletion better by informing the user
  why the back-up vanished and why.
* Closes #33
2015-03-07 16:35:08 -08:00
96ffed0984 Merge pull request #32 from omriiluz/master
Disable default bash xtrace and fix but in variables
2015-03-01 22:50:35 -08:00
43ae3eb61d properly clone arrays 2015-02-28 03:22:08 -08:00
6b23cf8d88 do not accumulate routes and push directives from default if new directives were defined 2015-02-28 03:01:00 -08:00
e9d1022eb4 Disable bash debug (xtrace) by default, re-enable with -e DEBUG=1 2015-02-28 02:45:31 -08:00
42d95bd77a Merge pull request #31 from nuimk/master
Return correct exit status in ovpn_getclient script
2015-02-23 16:52:38 -08:00
e959dca048 Return correct exit status 2015-02-21 02:46:50 +07:00
862aa19017 README: Add missing newline
* Fixes rendering issue on Docker Hub.
* If only all the Markdown renders worked the same...
2015-02-10 08:48:28 -08:00
5eb8c4b054 docs: Add FAQs document
* Place to put questions rather then the README
2015-02-07 15:10:24 -08:00
1940434447 README: Add links to upstream
* Link back to upstream to make it simpler to hop around.
2015-02-07 15:00:19 -08:00
4cd6f89a5a README: Add Benefits section
* Write-up the benefits from a comment on the DO tutorial.
2015-02-07 15:00:19 -08:00
7f2ae880d5 README: Add link to DO Tutorial
* Add a link to the Digital Ocean tutorial I wrote up some time ago.
2015-02-07 15:00:19 -08:00
06aee5bc37 Merge pull request #28 from omriiluz/master
Include optional configuration options
2015-01-17 18:14:35 -08:00
1cb38ce146 Support client mtu push 2015-01-17 01:07:52 -08:00
3eeee022fd Create NAT if OVPN_NAT is set (flag -N) 2015-01-17 01:00:18 -08:00
1e2418ae37 Control external NAT creation 2015-01-17 00:56:46 -08:00
97f231b4e7 Control default DNS push with -D flag 2015-01-17 00:56:21 -08:00
bf50da4ee2 Remove hard coded DNS push.
TODO: control with cmdline option
2015-01-16 03:36:47 -08:00
f6b177df4e README: Update DO link to $5/mo page
* Update DO link to $5/mo pricing page.  Makes it easier to compare to
  standalone VPN providers.
2015-01-13 14:43:59 -08:00
b8de403958 README: Remove port on genconfig line
* The internal port is always 1194 in the container since f1e85c959
* Users wanting to operate on a different public port should change the
  `ovpn_run` line to do the the appropriate thing with `-p` argument.
2015-01-13 14:27:24 -08:00
31a8584685 Run daemon as nobody 2015-01-01 22:57:28 -08:00
384beb888a README: Miscellaneous Fixes
* Fix typo and grammar
2015-01-01 22:57:19 -08:00
52725702e2 init: Add upstart init file
* Add an Upstart init file to reliably start and stop the container.
2014-12-15 16:01:07 -08:00
8cd45f1139 Merge pull request #22 from ZackAdams/master
Fixed SIGTERM handling
2014-12-10 08:22:37 -08:00
73c206d14a Fixed SIGTERM handling 2014-12-10 10:36:00 -05:00
bfb896f716 Merge pull request #21 from flecno/master
no connection block in client config
2014-12-08 13:33:48 -08:00
f2148d99ae no connection block in client config 2014-12-08 21:07:46 +01:00
25 changed files with 775 additions and 61 deletions

21
.travis.yml Normal file
View File

@ -0,0 +1,21 @@
# Disallowing packages: openvpn
# If you require these packages, please review the package approval process at: https://github.com/travis-ci/apt-package-whitelist#package-approval-process
#addons:
# apt:
# sources:
# - ubuntu-toolchain-r-test
# packages:
# - openvpn
services:
- docker
before_install:
- docker --version
- docker build -t kylemanna/openvpn .
- docker inspect kylemanna/openvpn
- docker run kylemanna/openvpn openvpn --version || true # why does it returns 1?
- docker run kylemanna/openvpn openssl version
script:
- pushd tests && for i in *.sh; do "./$i"; done && popd

View File

@ -6,11 +6,11 @@ FROM debian:jessie
MAINTAINER Kyle Manna <kyle@kylemanna.com>
RUN apt-get update && \
apt-get install -y openvpn iptables git-core && \
apt-get install -y openvpn iptables curl && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Update checkout to use tags when v3.0 is finally released
RUN git clone --depth 1 --branch v3.0.0-rc2 https://github.com/OpenVPN/easy-rsa.git /usr/local/share/easy-rsa && \
RUN mkdir -p /usr/local/share/easy-rsa && \
curl -L https://github.com/OpenVPN/easy-rsa/archive/v3.0.0.tar.gz | tar xzf - --strip=1 -C /usr/local/share/easy-rsa easy-rsa-3.0.0/easyrsa3 && \
ln -s /usr/local/share/easy-rsa/easyrsa3/easyrsa /usr/local/bin
# Needed by scripts
@ -21,7 +21,7 @@ ENV EASYRSA_VARS_FILE $OPENVPN/vars
VOLUME ["/etc/openvpn"]
# Internally uses port 1194, remap using docker
# Internally uses port 1194/udp, remap using `docker run -p 443:1194/tcp`
EXPOSE 1194/udp
WORKDIR /etc/openvpn

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Kyle Manna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,8 +1,20 @@
# OpenVPN for Docker
[![Build Status](https://travis-ci.org/kylemanna/docker-openvpn.svg)](https://travis-ci.org/kylemanna/docker-openvpn)
OpenVPN server in a Docker container complete with an EasyRSA PKI CA.
Extensively tested on [Digital Ocean](https://www.digitalocean.com/?refcode=d19f7fe88c94).
Extensively tested on [Digital Ocean $5/mo node](http://bit.ly/1C7cKr3) and has
a corresponding [Digital Ocean Community Tutorial](http://bit.ly/1AGUZkq).
#### Upstream Links
* Docker Registry @ [kylemanna/openvpn](https://registry.hub.docker.com/u/kylemanna/openvpn)
* GitHub @ [kylemanna/docker-openvpn](https://github.com/kylemanna/docker-openvpn)
#### Example Service
* [backroad.io](http://beta.backroad.io?utm_source=kylemanna/openvpn&utm_medium=readme&utm_campaign=20150621) - powered by *kylemanna/openvpn*
## Quick Start
@ -10,9 +22,9 @@ Extensively tested on [Digital Ocean](https://www.digitalocean.com/?refcode=d19f
docker run --name $OVPN_DATA -v /etc/openvpn busybox
* Initalize the `$OVPN_DATA` container that will hold the configuration files and certificates
* Initialize the `$OVPN_DATA` container that will hold the configuration files and certificates
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM:1194
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM
docker run --volumes-from $OVPN_DATA --rm -it kylemanna/openvpn ovpn_initpki
* Start OpenVPN server process
@ -21,7 +33,7 @@ Extensively tested on [Digital Ocean](https://www.digitalocean.com/?refcode=d19f
docker run --volumes-from $OVPN_DATA -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
- On Docker older than 1.2 version
- On Docker older than version 1.2
docker run --volumes-from $OVPN_DATA -d -p 1194:1194/udp --privileged kylemanna/openvpn
@ -33,6 +45,9 @@ Extensively tested on [Digital Ocean](https://www.digitalocean.com/?refcode=d19f
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
* Create an environment variable with the name DEBUG and value of 1 to enable debug output (using "docker -e").
docker run --volumes-from $OVPN_DATA -d -p 1194:1194/udp --privileged -e DEBUG=1 kylemanna/openvpn
## How Does It Work?
@ -96,18 +111,45 @@ packets, etc).
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 to accomplish this).
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 signed by the CA which the user hopefully configured with a passphrase
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 data image (using busybox as a
base). To remove it, remove the two Docker images and corresponding containers
and it's all gone. 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

View File

@ -4,7 +4,11 @@
# Import/export EasyRSA default settings
#
set -ex
if [ "$DEBUG" == "1" ]; then
set -x
fi
set -e
if [ $# -lt 1 ]; then
echo "No command provided"

41
bin/ovpn_copy_server_files Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
## @licence MIT <http://opensource.org/licenses/MIT>
## @author Copyright (C) 2015 Robin Schneider <ypid@riseup.net>
set -e
if [ -z "$OPENVPN" ]; then
export OPENVPN="$PWD"
fi
if ! source "$OPENVPN/ovpn_env.sh"; then
echo "Could not source $OPENVPN/ovpn_env.sh."
exit 1
fi
TARGET="$OPENVPN/server"
if [ -n "$1" ]; then
TARGET="$1"
fi
mkdir -p "${TARGET}"
## Ensure that no other keys then the one for the server is present.
rm -rf "$TARGET/pki/private" "$TARGET/pki/issued"
FILES=(
"openvpn.conf"
"ovpn_env.sh"
"pki/private/${OVPN_CN}.key"
"pki/issued/${OVPN_CN}.crt"
"pki/dh.pem"
"pki/ta.key"
"pki/ca.crt"
)
# rsync isn't available to keep size down
# cp --parents isn't in busybox version
# hack the directory structure with tar
tar cf - -C "${OPENVPN}" "${FILES[@]}" | tar xvf - -C "${TARGET}"
mkdir -p "$TARGET/ccd"
echo "Created the openvpn configuration for the server: $TARGET"

View File

@ -41,24 +41,53 @@ usage() {
echo "optional arguments:"
echo " -d Disable NAT routing and default route"
echo " -c Enable client-to-client option"
echo " -D Disable built in external dns (google dns)"
echo " -N Configure NAT to access external server network"
echo " -m Set client MTU"
echo " -t Use TAP device (instead of TUN device)"
echo " -T Encrypt packets with the given cipher algorithm instead of the default one (tls-cipher)."
echo " -C A list of allowable TLS ciphers delimited by a colon (cipher)."
echo " -a Authenticate packets with HMAC using the given message digest algorithm (auth)."
}
set -ex
if [ "$DEBUG" == "1" ]; then
set -x
fi
set -e
OVPN_ENV=$OPENVPN/ovpn_env.sh
OVPN_SERVER=192.168.255.0/24
OVPN_DEFROUTE=1
OVPN_NAT=0
OVPN_DNS=1
OVPN_DEVICE="tun"
OVPN_DEVICEN=0
OVPN_ROUTES=()
TMP_ROUTES=()
OVPN_PUSH=()
TMP_PUSH=()
OVPN_TLS_CIPHER=''
OVPN_CIPHER=''
OVPN_AUTH=''
# Import defaults if present
[ -r "$OVPN_ENV" ] && source "$OVPN_ENV"
# Parse arguments
while getopts ":r:s:du:cp:" opt; do
while getopts ":a:C:T:r:s:du:cp:DNm:t" opt; do
case $opt in
a)
OVPN_AUTH="$OPTARG"
;;
C)
OVPN_CIPHER="$OPTARG"
;;
T)
OVPN_TLS_CIPHER="$OPTARG"
;;
r)
OVPN_ROUTES+=("$OPTARG")
TMP_ROUTES+=("$OPTARG")
;;
s)
OVPN_SERVER=$OPTARG
@ -73,7 +102,19 @@ while getopts ":r:s:du:cp:" opt; do
OVPN_CLIENT_TO_CLIENT=1
;;
p)
OVPN_PUSH+=("$OPTARG")
TMP_PUSH+=("$OPTARG")
;;
D)
OVPN_DNS=0
;;
N)
OVPN_NAT=1
;;
m)
OVPN_MTU=$OPTARG
;;
t)
OVPN_DEVICE="tap"
;;
\?)
set +x
@ -90,6 +131,11 @@ while getopts ":r:s:du:cp:" opt; do
esac
done
# if new routes were not defined with -r, use default
[ ${#TMP_ROUTES[@]} -gt 0 ] && OVPN_ROUTES=("${TMP_ROUTES[@]}")
# if new push directives were not defined with -p, use default
[ ${#TMP_PUSH[@]} -gt 0 ] && OVPN_PUSH=("${TMP_PUSH[@]}")
# Server name is in the form "udp://vpn.example.com:1194"
if [[ "$OVPN_SERVER_URL" =~ ^((udp|tcp)://)?([0-9a-zA-Z\.\-]+)(:([0-9]+))?$ ]]; then
@ -110,7 +156,8 @@ fi
export OVPN_SERVER OVPN_ROUTES OVPN_DEFROUTE
export OVPN_SERVER_URL OVPN_ENV OVPN_PROTO OVPN_CN OVPN_PORT
export OVPN_CLIENT_TO_CLIENT OVPN_PUSH
export OVPN_CLIENT_TO_CLIENT OVPN_PUSH OVPN_NAT OVPN_DNS OVPN_MTU OVPN_DEVICE
export OVPN_TLS_CIPHER OVPN_CIPHER OVPN_AUTH
# Preserve config
if [ -f "$OVPN_ENV" ]; then
@ -130,7 +177,6 @@ fi
cat > "$conf" <<EOF
server $(getroute $OVPN_SERVER)
verb 3
#duplicate-cn
key $EASYRSA_PKI/private/${OVPN_CN}.key
ca $EASYRSA_PKI/ca.crt
cert $EASYRSA_PKI/issued/${OVPN_CN}.crt
@ -140,20 +186,24 @@ key-direction 0
keepalive 10 60
persist-key
persist-tun
push "dhcp-option DNS 8.8.4.4"
push "dhcp-option DNS 8.8.8.8"
proto $OVPN_PROTO
# Rely on Docker to do port mapping, internally always 1194
port 1194
dev tun0
dev $OVPN_DEVICE$OVPN_DEVICEN
status /tmp/openvpn-status.log
client-config-dir $OPENVPN/ccd
user nobody
group nogroup
EOF
[ -n "$OVPN_CLIENT_TO_CLIENT" ] && echo "client-to-client" >> "$conf"
[ -n "$OVPN_TLS_CIPHER" ] && echo "tls-cipher $OVPN_TLS_CIPHER" >> "$conf"
[ -n "$OVPN_CIPHER" ] && echo "cipher $OVPN_CIPHER" >> "$conf"
[ -n "$OVPN_AUTH" ] && echo "auth $OVPN_AUTH" >> "$conf"
[ -n "$OVPN_CLIENT_TO_CLIENT" ] && echo "client-to-client" >> "$conf"
[ "$OVPN_DNS" == "1" ] && echo push "dhcp-option DNS 8.8.4.4" >> "$conf"
[ "$OVPN_DNS" == "1" ] && echo push "dhcp-option DNS 8.8.8.8" >> "$conf"
# Append Routes
for i in "${OVPN_ROUTES[@]}"; do
# If user passed "0" skip this, assume no extra routes
@ -166,8 +216,16 @@ for i in "${OVPN_PUSH[@]}"; do
echo push \"$i\" >> "$conf"
done
# Clean-up duplicate configs (always return success)
diff -q "$bak_env" "$OVPN_ENV" 2> /dev/null && rm "$bak_env" || true
diff -q "$bak" "$conf" 2> /dev/null && rm "$bak" || true
set +e
# Clean-up duplicate configs
if diff -q "$bak_env" "$OVPN_ENV" 2>/dev/null; then
echo "Removing duplicate back-up: $bak_env"
rm -fv "$bak_env"
fi
if diff -q "$bak" "$conf" 2>/dev/null; then
echo "Removing duplicate back-up: $bak"
rm -fv "$bak"
fi
echo "Successfully generated config"

View File

@ -4,44 +4,108 @@
# Get an OpenVPN client configuration file
#
set -ex
if [ "$DEBUG" == "1" ]; then
set -x
fi
source "$OPENVPN/ovpn_env.sh"
cn=$1
set -e
if [ -z "$OPENVPN" ]; then
export OPENVPN="$PWD"
fi
if ! source "$OPENVPN/ovpn_env.sh"; then
echo "Could not source $OPENVPN/ovpn_env.sh."
exit 1
fi
if [ -z "$EASYRSA_PKI" ]; then
export EASYRSA_PKI="$OPENVPN/pki"
fi
cn="$1"
parm="$2"
if [ ! -f "$EASYRSA_PKI/private/${cn}.key" ]; then
echo "Unable to find ${cn}, please try again or generate the key first"
echo "Unable to find \"${cn}\", please try again or generate the key first" >&2
exit 1
fi
cat <<EOF
get_client_config() {
mode="$1"
echo "
client
nobind
dev tun
dev $OVPN_DEVICE
remote-cert-tls server
remote $OVPN_CN $OVPN_PORT $OVPN_PROTO
"
if [ "$mode" == "combined" ]; then
echo "
<key>
$(cat $EASYRSA_PKI/private/${cn}.key)
</key>
<cert>
$(cat $EASYRSA_PKI/issued/${cn}.crt)
$(openssl x509 -in $EASYRSA_PKI/issued/${cn}.crt)
</cert>
<ca>
$(cat $EASYRSA_PKI/ca.crt)
</ca>
<dh>
$(cat $EASYRSA_PKI/dh.pem)
</dh>
<tls-auth>
$(cat $EASYRSA_PKI/ta.key)
</tls-auth>
key-direction 1
"
elif [ "$mode" == "separated" ]; then
echo "
key ${cn}.key
ca ca.crt
cert ${cn}.crt
tls-auth ta.key 1
$OVPN_ADDITIONAL_CLIENT_CONFIG
"
fi
<connection>
remote $OVPN_CN $OVPN_PORT $OVPN_PROTO
</connection>
EOF
if [ "$OVPN_DEFROUTE" != "0" ];then
echo "redirect-gateway def1"
fi
if [ "$OVPN_DEFROUTE" != "0" ];then
echo "redirect-gateway def1"
fi
if [ -n "$OVPN_MTU" ]; then
echo "tun-mtu $OVPN_MTU"
fi
if [ -n "$OVPN_TLS_CIPHER" ]; then
echo "tls-cipher $OVPN_TLS_CIPHER"
fi
if [ -n "$OVPN_CIPHER" ]; then
echo "cipher $OVPN_CIPHER"
fi
if [ -n "$OVPN_AUTH" ]; then
echo "auth $OVPN_AUTH"
fi
}
dir="$OPENVPN/clients/$cn"
case "$parm" in
"separated")
mkdir -p "$dir"
get_client_config "$parm" > "$dir/${cn}.ovpn"
cp "$EASYRSA_PKI/private/${cn}.key" "$dir/${cn}.key"
cp "$EASYRSA_PKI/ca.crt" "$dir/ca.crt"
cp "$EASYRSA_PKI/issued/${cn}.crt" "$dir/${cn}.crt"
cp "$EASYRSA_PKI/ta.key" "$dir/ta.key"
;;
"" | "combined")
get_client_config "combined"
;;
"combined-save")
get_client_config "combined" > "$dir/${cn}-combined.ovpn"
;;
*)
echo "This script can produce the client configuration in to formats:" >&2
echo " 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
echo " 2. separated: Separated files." >&2
echo "Please specific one of those options as second parameter." >&2
;;
esac

25
bin/ovpn_getclient_all Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
## @licence MIT <http://opensource.org/licenses/MIT>
## @author Copyright (C) 2015 Robin Schneider <ypid@riseup.net>
if [ -z "$OPENVPN" ]; then
export OPENVPN="$PWD"
fi
if ! source "$OPENVPN/ovpn_env.sh"; then
echo "Could not source $OPENVPN/ovpn_env.sh."
exit 1
fi
if [ -z "$EASYRSA_PKI" ]; then
export EASYRSA_PKI="$OPENVPN/pki"
fi
pushd "$EASYRSA_PKI"
for name in issued/*.crt; do
name=${name%.crt}
name=${name#issued/}
if [ "$name" != "$OVPN_CN" ]; then
ovpn_getclient "$name" separated
ovpn_getclient "$name" combined-save
fi
done
popd

View File

@ -4,7 +4,11 @@
# Initialize the EasyRSA PKI
#
set -ex
if [ "$DEBUG" == "1" ]; then
set -x
fi
set -e
source "$OPENVPN/ovpn_env.sh"

View File

@ -4,7 +4,14 @@
# Run the OpenVPN server normally
#
set -ex
if [ "$DEBUG" == "1" ]; then
set -x
fi
set -e
# Build runtime arguments array based on environment
ARGS=("--config" "$OPENVPN/openvpn.conf")
source "$OPENVPN/ovpn_env.sh"
@ -13,22 +20,47 @@ if [ ! -c /dev/net/tun ]; then
mknod /dev/net/tun c 10 200
fi
if [ ! -d "$OPENVPN/ccd" ]; then
mkdir -p /etc/openvpn/ccd
if [ -d "$OPENVPN/ccd" ]; then
ARGS+=("--client-config-dir" "$OPENVPN/ccd")
fi
# When using --net=host, use this to specify nat device.
[ -z "$OVPN_NATDEVICE" ] && OVPN_NATDEVICE=eth0
# Setup NAT forwarding if requested
if [ "$OVPN_DEFROUTE" != "0" ];then
iptables -t nat -C POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE || {
iptables -t nat -A POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE
if [ "$OVPN_DEFROUTE" != "0" ] || [ "$OVPN_NAT" == "1" ] ; then
iptables -t nat -C POSTROUTING -s $OVPN_SERVER -o $OVPN_NATDEVICE -j MASQUERADE || {
iptables -t nat -A POSTROUTING -s $OVPN_SERVER -o $OVPN_NATDEVICE -j MASQUERADE
}
for i in "${OVPN_ROUTES[@]}"; do
iptables -t nat -C POSTROUTING -s "$i" -o eth0 -j MASQUERADE || {
iptables -t nat -A POSTROUTING -s "$i" -o eth0 -j MASQUERADE
iptables -t nat -C POSTROUTING -s "$i" -o $OVPN_NATDEVICE -j MASQUERADE || {
iptables -t nat -A POSTROUTING -s "$i" -o $OVPN_NATDEVICE -j MASQUERADE
}
done
fi
conf="$OPENVPN/openvpn.conf"
# Use a hacky hardlink as the CRL Needs to be readable by the user/group
# OpenVPN is running as. Only pass arguments to OpenVPN if it's found.
if [ -r "$EASYRSA_PKI/crl.pem" ]; then
if [ ! -r "$OPENVPN/crl.pem" ]; then
ln "$EASYRSA_PKI/crl.pem" "$OPENVPN/crl.pem"
chmod 644 "$OPENVPN/crl.pem"
fi
ARGS+=("--crl-verify" "$OPENVPN/crl.pem")
fi
openvpn --config "$conf"
ip -6 route show default 2>/dev/null
if [ $? = 0 ]; then
echo "Enabling IPv6 Forwarding"
# If this fails, ensure the docker container is run with --privileged
# Could be side stepped with `ip netns` madness to drop privileged flag
sysctl net.ipv6.conf.default.forwarding=1 || echo "Failed to enable IPv6 Forwarding default"
sysctl net.ipv6.conf.all.forwarding=1 || echo "Failed to enable IPv6 Forwarding"
fi
if [ "$#" -gt 0 ]; then
exec openvpn "$@"
else
exec openvpn ${ARGS[@]}
fi

View File

@ -3,7 +3,10 @@
#
# Get OpenVPN server status
#
if [ "$DEBUG" == "1" ]; then
set -x
fi
set -ex
set -e
tail -F /tmp/openvpn-status.log

View File

@ -1,6 +1,6 @@
# Advanced Configurations
The 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.
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
@ -18,4 +18,3 @@ The ovpn_genconfig script is intended for simple configurations that apply to th
* Start the server with:
docker run -v $PWD:/etc/openvpn -d -p 1194:1194/udp --privileged kylemanna/openvpn

View File

@ -2,17 +2,19 @@
## Security
The resulting archive from this back-up contains all credential to impersonate the server at a minimum. If the client 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.
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, never keep any keys (i.e. client and certificate authority) in the docker container to begin with :).
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, by ensure there is very limited access to it.
**TL;DR Protect the resulting archive file. Ensure there is very limited access to it.**
## Backup to Archive
docker run --volumes-from $OVPN_DATA --rm busybox tar -cvf - -C /etc openvpn | xz > openvpn-backup.tar.xz
## Retore to New Image
## Restore to New Container
Assumes an existing container named `$OVPN_DATA` to extract the data over the top.
xzcat openvpn-backup.tar.xz | docker run --name $OVPN_DATA -v /etc/openvpn -i busybox tar -xvf - -C /etc

36
docs/clients.md Normal file
View File

@ -0,0 +1,36 @@
# 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.
## 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 --volumes-from $OVPN_DATA --volume /tmp/openvpn_clients:/etc/openvpn/clients kylemanna/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):
docker run --rm -it --volumes-from $OVPN_DATA kylemanna/openvpn easyrsa revoke client1
docker run --rm -it --volumes-from $OVPN_DATA kylemanna/openvpn easyrsa gen-crl
The OpenVPN server will read this change every time a client connects (no need to restart server) and deny clients access using revoked certificates.

52
docs/docker.md Normal file
View File

@ -0,0 +1,52 @@
# 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@<container id>:/#` 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

14
docs/faqs.md Normal file
View File

@ -0,0 +1,14 @@
# Frequently Asked Questions
## How do I edit `openvpn.conf`?
Use a Docker image with a text editor pre-installed (i.e. Ubuntu) and connect the volume container:
docker run --volumes-from $OVPN_DATA --rm -it ubuntu vi /etc/openvpn/openvpn.conf
## Why not keep everything in one image?
The run-time image (`kylemanna/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 kylemanna/openvpn` and then `docker run ... kylemanna/openvpn`.

94
docs/ipv6.md Normal file
View File

@ -0,0 +1,94 @@
# 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/kylemanna/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
Not implemented, yet.

32
docs/paranoid.md Normal file
View File

@ -0,0 +1,32 @@
# Advanced security
## Keep the CA root key save
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 kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM
docker run --net=none --rm -t -i -v $PWD:/etc/openvpn kylemanna/openvpn ovpn_initpki
docker run --net=none --rm -t -i -v $PWD:/etc/openvpn kylemanna/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 cyphers 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 --volumes-from $OVPN_DATA --net=none --rm kylemanna/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
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.

View File

@ -1,6 +1,6 @@
# 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 octects need to be picked special, see [OpenVPN Documentation](https://openvpn.net/index.php/open-source/documentation/howto.html#policy) for more details.
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

View File

@ -0,0 +1,44 @@
[Unit]
Description=OpenVPN Docker Container
Documentation=https://github.com/kylemanna/docker-openvpn
After=network.target docker.socket
Requires=docker.socket
[Service]
RestartSec=10
Restart=always
# Modify IP6_PREFIX to match network config
#Environment="IP6_PREFIX=2001:db8::/64"
#Environment="ARGS=--config openvpn.conf --server-ipv6 2001:db8::/64"
Environment="NAME=ovpn-%i"
Environment="DATA_VOL=ovpn-data-%i"
Environment="IMG=kylemanna/openvpn:latest"
Environment="PORT=1194:1194/udp"
# To override environment variables, use local configuration directory:
# /etc/systemd/system/docker-openvpn@foo.d/local.conf
# http://www.freedesktop.org/software/systemd/man/systemd.unit.html
# Clean-up bad state if still hanging around
ExecStartPre=-/usr/bin/docker rm -f $NAME
# Attempt to pull new image for security updates
ExecStartPre=-/usr/bin/docker pull $IMG
# IPv6: Ensure forwarding is enabled on host's networking stack (hacky)
# Would be nice to use systemd-network on the host, but this doens't work
# http://lists.freedesktop.org/archives/systemd-devel/2015-June/032762.html
ExecStartPre=/bin/sh -c 'test -z "$IP6_PREFIX" && exit 0; sysctl net.ipv6.conf.all.forwarding=1'
# Main process
ExecStart=/usr/bin/docker run --rm --privileged --volumes-from ${DATA_VOL}:ro --name ${NAME} -p ${PORT} ${IMG} ovpn_run $ARGS
# IPv6: Add static route for IPv6 after it starts up
ExecStartPost=/bin/sh -c 'test -z "${IP6_PREFIX}" && exit 0; sleep 1; ip route replace ${IP6_PREFIX} via $(docker inspect -f "{{ .NetworkSettings.GlobalIPv6Address }}" $NAME ) dev docker0'
# IPv6: Clean-up
ExecStopPost=/bin/sh -c 'test -z "$IP6_PREFIX" && exit 0; ip route del $IP6_PREFIX dev docker0'
[Install]
WantedBy=multi-user.target

8
init/upstart.init Normal file
View File

@ -0,0 +1,8 @@
# Copy to /etc/init/docker-openvpn.conf
description "Docker container for OpenVPN server"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
script
exec docker run --volumes-from ovpn-data --rm -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
end script

61
tests/basic.sh Executable file
View File

@ -0,0 +1,61 @@
#!/bin/bash
set -ex
OVPN_DATA=basic-data
CLIENT=travis-client
IMG=kylemanna/openvpn
#
# Create a docker container with the config data
#
docker run --name $OVPN_DATA -v /etc/openvpn busybox
ip addr ls
SERV_IP=$(ip -4 -o addr show scope global | awk '{print $4}' | sed -e 's:/.*::' | head -n1)
docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_genconfig -u udp://$SERV_IP
# nopass is insecure
docker run --volumes-from $OVPN_DATA --rm -it -e "EASYRSA_BATCH=1" -e "EASYRSA_REQ_CN=Travis-CI Test CA" $IMG ovpn_initpki nopass
docker run --volumes-from $OVPN_DATA --rm -it $IMG easyrsa build-client-full $CLIENT nopass
docker run --volumes-from $OVPN_DATA --rm $IMG ovpn_getclient $CLIENT | tee client/config.ovpn
#
# Fire up the server
#
sudo iptables -N DOCKER
sudo iptables -I FORWARD -j DOCKER
# run in shell bg to get logs
docker run --name "ovpn-test" --volumes-from $OVPN_DATA --rm -p 1194:1194/udp --privileged $IMG &
#for i in $(seq 10); do
# SERV_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}')
# test -n "$SERV_IP" && break
#done
#sed -ie s:SERV_IP:$SERV_IP:g client/config.ovpn
#
# Fire up a client in a container since openvpn is disallowed by Travis-CI, don't NAT
# the host as it confuses itself:
# "Incoming packet rejected from [AF_INET]172.17.42.1:1194[2], expected peer address: [AF_INET]10.240.118.86:1194"
#
docker run --rm --net=host --privileged --volume $PWD/client:/client $IMG /client/wait-for-connect.sh
#
# Client either connected or timed out, kill server
#
kill %1
#
# Celebrate
#
cat <<EOF
___________
< it worked >
-----------
\ ^__^
\ (oo)\_______
(__)\ )\/\\
||----w |
|| ||
EOF

View File

@ -0,0 +1,35 @@
#!/bin/bash
set -ex
OPENVPN_CONFIG=${1:-/client/config.ovpn}
# Run in background, rely on bash for job management
openvpn --config "$OPENVPN_CONFIG" --management 127.0.0.1 9999 &
# Spin waiting for interface to exist signifying connection
timeout=10
for i in $(seq $timeout); do
# Break when connected
#echo state | busybox nc 127.0.0.1 9999 | grep -q "CONNECTED,SUCCESS" && break;
# Bash magic for tcp sockets
if exec 3<>/dev/tcp/127.0.0.1/9999; then
# Consume all header input
while read -t 0.1 <&3; do true; done
echo "state" >&3
read -t 1 <&3
echo -n $REPLY | grep -q "CONNECTED,SUCCESS" && break || true
exec 3>&-
fi
# Else sleep
sleep 1
done
if [ $i -ge $timeout ]; then
echo "Error starting OpenVPN, i=$i, exiting."
exit 2;
fi
# The show is over.
kill %1

22
tests/paranoid.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
set -ex
IMG=${IMG:-kylemanna/openvpn}
temp=$(mktemp -d)
pushd $temp
SERV_IP=$(ip -4 -o addr show scope global | awk '{print $4}' | sed -e 's:/.*::' | head -n1)
docker run --net=none --rm -t -i -v $PWD:/etc/openvpn $IMG ovpn_genconfig -u udp://$SERV_IP
docker run --net=none --rm -t -i -v $PWD:/etc/openvpn -e "EASYRSA_BATCH=1" -e "EASYRSA_REQ_CN=Travis-CI Test CA" kylemanna/openvpn ovpn_initpki nopass
docker run --net=none --rm -t -i -v $PWD:/etc/openvpn $IMG ovpn_copy_server_files
popd
# Can't delete the temp directory as docker creates some files as root.
# Just let it die with the test instance.
rm -rf $temp || true