diff --git a/Dockerfile b/Dockerfile index 05f4d72..874f5a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,21 +6,19 @@ # Note that the config must have embedded certs # See `start` in same repo for more ideas -FROM alpine:edge +FROM alpine -ADD sockd.sh /usr/local/bin/ +COPY sockd.sh /usr/local/bin/ RUN true \ - && echo "http://dl-4.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \ - && apk add --update-cache dante-server openvpn \ + && apk add --update-cache dante-server openvpn bash openresolv openrc \ && rm -rf /var/cache/apk/* \ && chmod a+x /usr/local/bin/sockd.sh \ && true -ADD sockd.conf /etc/ +COPY sockd.conf /etc/ ENTRYPOINT [ \ - "openvpn", \ - "--up", "/usr/local/bin/sockd.sh", \ - "--script-security", "2", \ - "--config", "/ovpn.conf"] + "/bin/bash", "-c", \ + "cd /etc/openvpn && /usr/sbin/openvpn --config *.conf --script-security 2 --up /usr/local/bin/sockd.sh" \ + ] diff --git a/LICENSE b/LICENSE index 6be61f8..9ae428b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,29 @@ The MIT License (MIT) +Copyright (c) 2016 Chris Yuen + +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. + +=== + +The MIT License (MIT) + Copyright (c) 2016 Mook Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/README.md b/README.md index 607f8fd..7b8aff1 100644 --- a/README.md +++ b/README.md @@ -4,23 +4,52 @@ This is a docker image of an OpenVPN client tied to a SOCKS proxy server. It is useful to isolate network changes (so the host is not affected by the modified routing). +This supports directory style (where the certificates are not bundled together in one `.ovpn` file) and those that contains `update-resolv-conf` + +(For the same thing in WireGuard, see [kizzx2/docker-wireguard-socks-proxy](https://github.com/kizzx2/docker-wireguard-socks-proxy)) + +## Why? + +This is arguably the easiest way to achieve "app based" routing. For example, you may only want certain applications to go through your WireGuard tunnel while the rest of your system should go through the default gateway. You can also achieve "domain name based" routing by using a [PAC file](https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_(PAC)_file) that most browsers support. + ## Usage Preferably, using `start` in this repository: ```bash -start client_config.ovpn +start /your/openvpn/directory ``` +`/your/openvpn/directory` should contain *one* OpenVPN `.conf` file. It can reference other certificate files or key files in the same directory. + Alternatively, using `docker run` directly: ```bash -docker run -t -i --device=/dev/net/tun --cap-add=NET_ADMIN \ - --volume client_config.ovpn:/ovpn.conf:ro \ - mook/openvpn-client-socks +docker run -it --rm --device=/dev/net/tun --cap-add=NET_ADMIN \ + --name openvpn-client \ + --volume /your/openvpn/directory/:/etc/openvpn/:ro -p 1080:1080 \ + kizzx2/openvpn-client-socks +``` + +Then connect to SOCKS proxy through through `localhost:1080` / `local.docker:1080`. For example: + +```bash +curl --proxy socks5h://local.docker:1080 ipinfo.io ``` -### OpenVPN Configuration Constraints +## Solutions to Common Problems -- The configuration file must have embedded certificates; references to other - files are not allowed. -- The configuration file must use `dev tun0`. +### I'm getting `RTNETLINK answers: Permission denied` + +Try adding `--sysctl net.ipv6.conf.all.disable_ipv6=0` to your docker command + +### DNS doesn't work + +You can put a `update-resolv-conf` as your `up` script. One simple way is to put [this file](https://gist.github.com/Ikke/3829134) as `up.sh` inside your OpenVPN configuration directory. + +## HTTP Proxy + +You can easily convert this to an HTTP proxy using [http-proxy-to-socks](https://github.com/oyyd/http-proxy-to-socks), e.g. + +```bash +hpts -s 127.0.0.1:1080 -p 8080 +``` diff --git a/sockd.sh b/sockd.sh index c33a690..8021a64 100644 --- a/sockd.sh +++ b/sockd.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e -/etc/openvpn/up.sh "$@" -exec /usr/sbin/sockd -D +[ -f /etc/openvpn/up.sh ] && /etc/openvpn/up.sh "$@" +/usr/sbin/sockd -D diff --git a/start b/start index 7bcad26..b3cfa06 100755 --- a/start +++ b/start @@ -1,11 +1,13 @@ -#!/bin/bash +#!/bin/sh exec docker run \ --rm \ --tty \ --interactive \ --device=/dev/net/tun \ + --name=openvpn-client \ --cap-add=NET_ADMIN \ - --publish 127.0.0.1:1081:1080 \ - --volume "$(realpath "$1"):/ovpn.conf:ro" \ - mook/openvpn-client-socks + --publish 127.0.0.1:1080:1080 \ + --volume "$(realpath "$1"):/etc/openvpn/:ro" \ + --sysctl net.ipv6.conf.all.disable_ipv6=0 \ + kizzx2/openvpn-client-socks