All Projects → wfg → docker-openvpn-client

wfg / docker-openvpn-client

Licence: MIT license
OpenVPN client with killswitch and proxy servers; built on Alpine

Programming Languages

shell
77523 projects
Smarty
1635 projects
python
139335 projects - #7 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to docker-openvpn-client

nimSocks
A filtering SOCKS proxy server and client library written in nim.
Stars: ✭ 51 (-76.5%)
Mutual labels:  proxy-server, socks-proxy
socks5 list
Auto-updated SOCKS5 proxy list + proxies for Telegram
Stars: ✭ 210 (-3.23%)
Mutual labels:  proxy-server, socks-proxy
3proxy
3proxy - tiny free proxy server
Stars: ✭ 2,493 (+1048.85%)
Mutual labels:  proxy-server, socks-proxy
Free Proxy List
🔥Free proxy servers list / Updated hourly!
Stars: ✭ 326 (+50.23%)
Mutual labels:  proxy-server, socks-proxy
3proxy
3proxy - tiny free proxy server
Stars: ✭ 2,263 (+942.86%)
Mutual labels:  proxy-server, socks-proxy
Flynet
A powerful TCP/UDP tool, which support socks5 proxy by tcp and udp, http proxy and NAT traversal. This tool can help you bypass gfw easily
Stars: ✭ 124 (-42.86%)
Mutual labels:  proxy-server, socks-proxy
srelay
Srelay - the SOCKS proxy and Relay (imported from sourceforge)
Stars: ✭ 41 (-81.11%)
Mutual labels:  proxy-server, socks-proxy
Tor Socks Proxy
🐳 Tiny Docker(🤏 10MB) image as 🧅 Tor SOCKS5 proxy 🛡
Stars: ✭ 218 (+0.46%)
Mutual labels:  proxy-server, socks-proxy
microsocks11
A cross-platform SOCKS5 library and server based on the microsocks project.
Stars: ✭ 22 (-89.86%)
Mutual labels:  proxy-server, socks-proxy
http-knocking
🚪HTTP-Knocking hides a Web server and open it by knocking sequence: Hide Web server until your knocks
Stars: ✭ 28 (-87.1%)
Mutual labels:  proxy-server
thumbai
Go Mod Repository, Go Vanity Server and Proxy Server
Stars: ✭ 84 (-61.29%)
Mutual labels:  proxy-server
p3y
A single binary reverse proxy written in go. It was developed for use in Kubernetes, to wrap services like Prometheus with simple BasicAuth and TLS encryption.
Stars: ✭ 15 (-93.09%)
Mutual labels:  proxy-server
sparql-proxy
SPARQL-proxy: provides cache, job control, and logging for any SPARQL endpoint
Stars: ✭ 26 (-88.02%)
Mutual labels:  proxy-server
proxy pool
A simple proxy pool
Stars: ✭ 73 (-66.36%)
Mutual labels:  proxy-server
LiveProxies
Asynchronous proxy checker
Stars: ✭ 17 (-92.17%)
Mutual labels:  proxy-server
shadowrocket
A socks5 proxy to build your own shadowsocks private network. PHP based & Composer supported.
Stars: ✭ 23 (-89.4%)
Mutual labels:  socks-proxy
Free-Proxy
Hi there will be a lot of proxies here.
Stars: ✭ 135 (-37.79%)
Mutual labels:  proxy-server
socks5-proxy
Socks5 Proxy with Go Lang. support USER_ID/PASSWORD. able to bypass HTTPS(SNI) censorship
Stars: ✭ 29 (-86.64%)
Mutual labels:  proxy-server
proxy-ng
No description or website provided.
Stars: ✭ 33 (-84.79%)
Mutual labels:  socks-proxy
bproxy
high-performance minimal HTTP reverse proxy
Stars: ✭ 28 (-87.1%)
Mutual labels:  proxy-server

OpenVPN Client for Docker

What is this and what does it do?

ghcr.io/wfg/openvpn-client is a containerized OpenVPN client. It has a kill switch built with nftables that kills Internet connectivity to the container if the VPN tunnel goes down for any reason. It also includes an HTTP proxy server (Tinyproxy) and a SOCKS proxy server (Dante). This allows hosts and non-containerized applications to use the VPN without having to run VPN clients on those hosts.

This image requires you to supply the necessary OpenVPN configuration file(s). Because of this, any VPN provider should work.

If you find something that doesn't work or have an idea for a new feature, issues and pull requests are welcome.

Why?

Having a containerized VPN client lets you use container networking to easily choose which applications you want using the VPN instead of having to set up split tunnelling. It also keeps you from having to install an OpenVPN client on the underlying host.

How do I use it?

Getting the image

You can either pull it from GitHub Container Registry or build it yourself.

To pull it from GitHub Container Registry, run

docker pull ghcr.io/wfg/openvpn-client

To build it yourself, run

docker build -t ghcr.io/wfg/openvpn-client https://github.com/wfg/docker-openvpn-client.git

Creating and running a container

The image requires the container be created with the NET_ADMIN capability and /dev/net/tun accessible. Below are bare-bones examples for docker run and Compose; however, you'll probably want to do more than just run the VPN client. See the sections below to learn how to use the proxies and have other containers use openvpn-client's network stack.

docker run

docker run --detach \
  --name=openvpn-client \
  --cap-add=NET_ADMIN \
  --device=/dev/net/tun \
  --volume <path/to/config/dir>:/data/vpn \
  ghcr.io/wfg/openvpn-client

docker-compose

services:
  openvpn-client:
    image: ghcr.io/wfg/openvpn-client
    container_name: openvpn-client
    cap_add:
      - NET_ADMIN
    devices:
      - /dev/net/tun
    volumes:
      - <path/to/config/dir>:/data/vpn
    restart: unless-stopped

Environment variables

Variable Default (blank is unset) Description
USE_VPN_DNS on Whether or not to use the DNS servers pushed from the VPN server. It's best to leave this enabled unless you have a good reason to disable it.
VPN_CONFIG_FILE The OpenVPN configuration file to use. If unset, the VPN_CONFIG_PATTERN is used.
VPN_CONFIG_PATTERN The search pattern to use when looking for an OpenVPN configuration file. If unset, the search will include *.conf and *.ovpn.
VPN_AUTH_SECRET Docker secret that contain the credentials for accessing the VPN.
VPN_LOG_LEVEL 3 OpenVPN logging verbosity (1-11)
SUBNETS A list of one or more comma-separated subnets (e.g. 192.168.0.0/24,192.168.1.0/24) to allow outside of the VPN tunnel.
KILL_SWITCH iptables Which packet filterer to use for the kill switch. This value likely depends on your underlying host. Recommended to leave default unless you have problems. Acceptable values are iptables and nftables. To disable the kill switch, set to any other value.
HTTP_PROXY Whether or not to enable the built-in HTTP proxy server. To enable, set to any "truthy" value (see below the table). Any other value (including unset) will cause the proxy server to not run. It listens on port 8080.
HTTP_PROXY_USERNAME Credentials for accessing the HTTP proxy. If HTTP_PROXY_USERNAME is specified, you should also specify HTTP_PROXY_PASSWORD.
HTTP_PROXY_PASSWORD Credentials for accessing the HTTP proxy. If HTTP_PROXY_PASSWORD is specified, you should also specify HTTP_PROXY_USERNAME.
HTTP_PROXY_USERNAME_SECRET Docker secrets that contain the credentials for accessing the HTTP proxy. If HTTP_PROXY_USERNAME_SECRET is specified, you should also specify HTTP_PROXY_PASSWORD_SECRET.
HTTP_PROXY_PASSWORD_SECRET Docker secrets that contain the credentials for accessing the HTTP proxy. If HTTP_PROXY_PASSWORD_SECRET is specified, you should also specify HTTP_PROXY_USERNAME_SECRET.
SOCKS_PROXY Whether or not to enable the built-in SOCKS proxy server. To enable, set to any "truthy" value (see below the table). Any other value (including unset) will cause the proxy server to not run. It listens on port 1080.
SOCKS_LISTEN_ON Address the proxies will be listening on. Set to 0.0.0.0 to listen on all IP addresses.
SOCKS_PROXY_USERNAME Credentials for accessing the proxies. If SOCKS_PROXY_USERNAME is specified, you should also specify SOCKS_PROXY_PASSWORD.
SOCKS_PROXY_PASSWORD Credentials for accessing the proxies. If SOCKS_PROXY_PASSWORD is specified, you should also specify SOCKS_PROXY_USERNAME.
SOCKS_PROXY_USERNAME_SECRET Docker secrets that contain the credentials for accessing the proxies. If SOCKS_PROXY_USERNAME_SECRET is specified, you should also specify SOCKS_PROXY_PASSWORD_SECRET.
SOCKS_PROXY_PASSWORD_SECRET Docker secrets that contain the credentials for accessing the proxies. If SOCKS_PROXY_PASSWORD_SECRET is specified, you should also specify SOCKS_PROXY_USERNAME_SECRET.
"Truthy" values are the following: true, t, yes, y, 1, on, enable, or enabled.
Environment variable considerations
SUBNETS

If you intend on connecting to containers that use the OpenVPN container's network stack (which you probably do), you will probably want to use this variable. Regardless of whether or not you're using the kill switch, the entrypoint script also adds routes to each of the SUBNETS to allow network connectivity from outside of Docker.

HTTP_PROXY and SOCKS_PROXY

If enabling the the proxy server(s), you'll want to publish the appropriate port(s) in order to access the server(s). To do that using docker run, add -p <host_port>:8080 and/or -p <host_port>:1080 where <host_port> is whatever port you want to use on the host. If you're using docker-compose, add the relevant port specification(s) from the snippet below to the openvpn-client service definition in your Compose file.

ports:
  - <host_port>:8080
  - <host_port>:1080
*_PROXY_USERNAME_SECRET, *_PROXY_PASSWORD_SECRET, and VPN_AUTH_SECRET

Compose has support for Docker secrets. See the Compose file in this repository for example usage of passing proxy credentials as Docker secrets.

Using with other containers

Once you have your openvpn-client container up and running, you can tell other containers to use openvpn-client's network stack which gives them the ability to utilize the VPN tunnel. There are a few ways to accomplish this depending how how your container is created.

If your container is being created with

  1. the same Compose YAML file as openvpn-client, add network_mode: service:openvpn-client to the container's service definition.
  2. a different Compose YAML file than openvpn-client, add network_mode: container:openvpn-client to the container's service definition.
  3. docker run, add --network=container:openvpn-client as an option to docker run.

Once running and provided your container has wget or curl, you can run docker exec <container_name> wget -qO - ifconfig.me or docker exec <container_name> curl -s ifconfig.me to get the public IP of the container and make sure everything is working as expected. This IP should match the one of openvpn-client.

Handling ports intended for connected containers

If you have a connected container and you need to access a port that container, you'll want to publish that port on the openvpn-client container instead of the connected container. To do that, add -p <host_port>:<container_port> if you're using docker run, or add the below snippet to the openvpn-client service definition in your Compose file if using docker-compose.

ports:
  - <host_port>:<container_port>

In both cases, replace <host_port> and <container_port> with the port used by your connected container.

Verifying functionality

Once you have container running ghcr.io/wfg/openvpn-client, run the following command to spin up a temporary container using openvpn-client for networking. The wget -qO - ifconfig.me bit will return the public IP of the container (and anything else using openvpn-client for networking). You should see an IP address owned by your VPN provider.

docker run --rm -it --network=container:openvpn-client alpine wget -qO - ifconfig.me

Troubleshooting

can't initialize iptables

If you see a message like the below in your logs, try setting KILL_SWITCH to nftables:

iptables v1.8.8 (legacy): can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

VPN authentication

Your OpenVPN configuration file may not come with authentication baked in. To provide OpenVPN the necessary credentials, create a file (any name will work, but this example will use credentials.txt) next to the OpenVPN configuration file with your username on the first line and your password on the second line.

For example:

vpn_username
vpn_password

In the OpenVPN configuration file, add the following line:

auth-user-pass credentials.txt

This will tell OpenVPN to read credentials.txt whenever it needs credentials.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].