2018-09-21 16:39:08 +02:00
# Private Internet Access Client (OpenVPN+Iptables+DNS over TLS on Alpine Linux)
2018-02-06 21:57:41 -05:00
2018-11-06 14:55:11 +01:00
*Lightweight VPN client to tunnel to private internet access servers*
2018-06-06 22:44:11 -04:00
2018-02-21 11:55:45 -05:00
[](https://hub.docker.com/r/qmcgaw/private-internet-access/)
2018-02-06 21:57:41 -05:00
2018-03-15 12:09:17 -04:00
[](https://travis-ci.org/qdm12/private-internet-access-docker)
2018-04-15 14:15:58 -04:00
[](https://hub.docker.com/r/qmcgaw/private-internet-access)
[](https://github.com/qdm12/private-internet-access-docker/issues)
[](https://github.com/qdm12/private-internet-access-docker/issues)
[](https://github.com/qdm12/private-internet-access-docker/issues)
[](https://hub.docker.com/r/qmcgaw/private-internet-access)
[](https://hub.docker.com/r/qmcgaw/private-internet-access)
[](https://hub.docker.com/r/qmcgaw/private-internet-access)
2018-03-15 12:09:17 -04:00
2018-10-29 16:32:11 +01:00
[](https://microbadger.com/images/qmcgaw/private-internet-access)
[](https://microbadger.com/images/qmcgaw/private-internet-access)
2018-04-01 13:56:56 -04:00
2019-01-14 14:14:40 +01:00
[](https://paypal.me/qdm12)
2018-10-29 16:32:11 +01:00
| Image size | RAM usage | CPU usage |
| --- | --- | --- |
2019-09-09 13:56:50 -04:00
| 23.3MB | 14MB to 80MB | Low to Medium |
2019-01-14 09:55:46 +01:00
2019-02-01 08:30:10 +01:00
<details><summary>Click to show base components</summary><p>
2018-10-29 16:32:11 +01:00
2019-06-26 17:23:24 +02:00
- [Alpine 3.10 ](https://alpinelinux.org ) for a tiny image
- [OpenVPN 2.4.7 ](https://pkgs.alpinelinux.org/package/v3.10/main/x86_64/openvpn ) to tunnel to PIA servers
- [IPtables 1.8.3 ](https://pkgs.alpinelinux.org/package/v3.10/main/x86_64/iptables ) enforces the container to communicate only through the VPN or with other containers in its virtual network (acts as a killswitch)
- [Unbound 1.9.1 ](https://pkgs.alpinelinux.org/package/v3.10/main/x86_64/unbound ) configured with Cloudflare's [1.1.1.1 ](https://1.1.1.1 ) DNS over TLS
2019-04-23 10:29:44 +02:00
- [Files and blocking lists built periodically ](https://github.com/qdm12/updated/tree/master/files ) used with Unbound (see `BLOCK_MALICIOUS` and `BLOCK_NSA` environment variables)
2019-06-27 13:12:03 +02:00
- [TinyProxy 1.10.0 ](https://pkgs.alpinelinux.org/package/v3.10/main/x86_64/tinyproxy )
2018-10-29 16:32:11 +01:00
2019-02-01 08:30:10 +01:00
</p></details>
2019-05-23 11:58:52 +02:00
## Features
- <details><summary>Configure everything with environment variables</summary><p>
- [Destination region ](https://www.privateinternetaccess.com/pages/network )
- Internet protocol
- Level of encryption
2019-06-27 13:10:51 +02:00
- PIA Username and password
- DNS over TLS
2019-05-23 11:58:52 +02:00
- Malicious DNS blocking
2019-06-27 13:10:51 +02:00
- Internal firewall
2019-06-29 13:42:44 +02:00
- Web HTTP proxy
2019-06-27 13:10:51 +02:00
- Run openvpn without root
2019-05-22 09:34:33 +02:00
</p></details>
2019-06-26 17:23:42 +02:00
- Connect other containers to it, [see this ](https://github.com/qdm12/private-internet-access-docker#connect-to-it )
2019-06-29 13:42:44 +02:00
- **ARM** compatible
- Port forwarding
2019-05-23 11:58:52 +02:00
- The * iptables * firewall allows traffic only with needed PIA servers (IP addresses, port, protocol) combinations
2019-06-26 17:23:42 +02:00
- OpenVPN reconnects automatically on failure
2019-05-23 11:58:52 +02:00
- Docker healthcheck pings the DNS 1.1.1.1 to verify the connection is up
2019-06-26 17:23:42 +02:00
- Unbound DNS runs * without root *
- OpenVPN can run * without root * but this disallows OpenVPN reconnecting, it can be set with `NONROOT=yes`
2019-09-09 20:39:47 -04:00
- Connect your LAN devices
- HTTP Web proxy * tinyproxy *
- SOCKS5 proxy * shadowsocks *
2019-06-29 13:42:44 +02:00
2018-04-15 14:15:58 -04:00
## Setup
2018-02-06 21:57:41 -05:00
2019-05-23 11:58:52 +02:00
1. <details><summary>Requirements</summary><p>
2018-06-01 14:38:27 -04:00
2019-05-23 11:58:52 +02:00
- A Private Internet Access **username ** and **password ** - [Sign up ](https://www.privateinternetaccess.com/pages/buy-vpn/ )
2019-06-29 13:42:44 +02:00
- External firewall requirements, if you have one
2019-05-23 11:58:52 +02:00
- Allow outbound TCP 853 to 1.1.1.1 to allow Unbound to resolve the PIA domain name at start. You can then block it once the container is started.
- For UDP strong encryption, allow outbound UDP 1197
- For UDP normal encryption, allow outbound UDP 1198
- For TCP strong encryption, allow outbound TCP 501
- For TCP normal encryption, allow outbound TCP 502
2019-06-29 13:42:44 +02:00
- For the built-in web HTTP proxy, allow inbound TCP 8888
2019-09-09 20:39:47 -04:00
- For the built-in SOCKS5 proxy, allow inbound TCP 8388 and UDP 8388
2019-07-28 18:18:59 -04:00
- Docker API 1.25 to support `init`
- If you use Docker Compose, docker-compose >= 1.22.0, to support `init: true`
2018-09-20 20:35:29 +02:00
2019-05-23 11:58:52 +02:00
</p></details>
2018-09-20 20:35:29 +02:00
2019-05-23 11:58:52 +02:00
1. Ensure `/dev/net/tun` is setup on your host with either:
```sh
insmod /lib/modules/tun.ko
# or...
2018-11-14 14:38:10 +02:00
modprobe tun
2018-04-13 15:35:31 -04:00
```
2018-02-21 11:55:45 -05:00
2019-05-22 09:34:33 +02:00
1. <details><summary>CLICK IF YOU HAVE AN ARM DEVICE</summary><p>
- If you have a ARM 32 bit v6 architecture
```sh
2019-05-22 22:47:13 +02:00
docker build -t qmcgaw/private-internet-access \
2019-05-22 09:34:33 +02:00
--build-arg BASE_IMAGE=arm32v6/alpine \
https://github.com/qdm12/private-internet-access-docker.git
```
- If you have a ARM 32 bit v7 architecture
```sh
2019-05-22 22:47:13 +02:00
docker build -t qmcgaw/private-internet-access \
2019-05-22 09:34:33 +02:00
--build-arg BASE_IMAGE=arm32v7/alpine \
https://github.com/qdm12/private-internet-access-docker.git
```
- If you have a ARM 64 bit v8 architecture
```sh
2019-05-22 22:47:13 +02:00
docker build -t qmcgaw/private-internet-access \
2019-05-22 09:34:33 +02:00
--build-arg BASE_IMAGE=arm64v8/alpine \
https://github.com/qdm12/private-internet-access-docker.git
```
</p></details>
2019-04-03 19:21:49 +02:00
2018-10-29 16:32:11 +01:00
1. Launch the container with:
2018-02-21 11:55:45 -05:00
2018-04-15 14:15:58 -04:00
```bash
2019-06-27 13:10:51 +02:00
docker run -d --init --name=pia --cap-add=NET_ADMIN --device=/dev/net/tun \
2019-05-23 11:58:52 +02:00
-e REGION="CA Montreal" -e USER=js89ds7 -e PASSWORD=8fd9s239G \
2018-04-15 14:15:58 -04:00
qmcgaw/private-internet-access
```
2018-02-21 11:55:45 -05:00
2018-10-29 16:32:11 +01:00
or use [docker-compose.yml ](https://github.com/qdm12/private-internet-access-docker/blob/master/docker-compose.yml ) with:
2018-03-31 20:33:45 -04:00
2018-09-20 20:35:29 +02:00
```bash
2018-03-31 20:33:45 -04:00
docker-compose up -d
```
2019-06-29 13:42:44 +02:00
Note that you can:
- Change the many [environment variables ](#environment-variables ) available
- Use `-p 8888:8888/tcp` to access the HTTP web proxy (and put your LAN in `EXTRA_SUBNETS` environment variable)
2019-09-09 20:39:47 -04:00
- Use `-p 8388:8388/tcp -p 8388:8388/udp` to access the SOCKS5 proxy (and put your LAN in `EXTRA_SUBNETS` environment variable)
2019-06-29 13:42:44 +02:00
- Pass additional arguments to * openvpn * using Docker's command function (commands after the image name)
2019-06-27 13:12:03 +02:00
2018-04-13 15:35:31 -04:00
## Testing
2019-05-23 11:58:52 +02:00
Check the PIA IP address matches your expectations
2018-03-31 20:33:45 -04:00
2019-05-23 11:58:52 +02:00
```sh
2019-06-26 17:23:24 +02:00
docker run --rm --network=container:pia alpine:3.10 wget -qO- https://ipinfo.io
2019-05-23 11:58:52 +02:00
```
2018-02-06 21:57:41 -05:00
2018-04-15 14:15:58 -04:00
## Environment variables
| Environment variable | Default | Description |
| --- | --- | --- |
2018-11-14 14:38:10 +02:00
| `REGION` | `CA Montreal` | One of the [PIA regions ](https://www.privateinternetaccess.com/pages/network/ ) |
2018-10-29 16:32:11 +01:00
| `PROTOCOL` | `udp` | `tcp` or `udp` |
2018-04-15 14:15:58 -04:00
| `ENCRYPTION` | `strong` | `normal` or `strong` |
2019-01-14 09:55:14 +01:00
| `USER` | | Your PIA username |
| `PASSWORD` | | Your PIA password |
2019-05-23 11:58:52 +02:00
| `NONROOT` | `no` | Run OpenVPN without root, `yes` or `no` |
2019-06-27 13:10:51 +02:00
| `DOT` | `on` | `on` or `off` , to activate DNS over TLS to 1.1.1.1 |
2019-04-23 10:29:44 +02:00
| `BLOCK_MALICIOUS` | `off` | `on` or `off` , blocks malicious hostnames and IPs |
| `BLOCK_NSA` | `off` | `on` or `off` , blocks NSA hostnames |
| `UNBLOCK` | | comma separated string (i.e. `web.com,web2.ca` ) to unblock hostnames |
2019-06-27 13:10:51 +02:00
| `EXTRA_SUBNETS` | | comma separated subnets allowed in the container firewall (i.e. `192.168.1.0/24,192.168.10.121,10.0.0.5/28` ) |
2019-09-09 12:34:05 -04:00
| `PORT_FORWARDING` | `off` | Set to `on` to forward a port on PIA server |
| `PORT_FORWARDING_STATUS_FILE` | `/forwarded_port` | File path to store the forwarded port number |
2019-09-09 12:40:00 -04:00
| `TINYPROXY` | `on` | `on` or `off` , to enable the internal HTTP proxy tinyproxy |
| `TINYPROXY_LOG` | `Critical` | `Info` , `Warning` , `Error` or `Critical` |
| `TINYPROXY_PORT` | `8888` | `1024` to `65535` internal port for HTTP proxy |
| `TINYPROXY_USER` | | Username to use to connect to the HTTP proxy |
| `TINYPROXY_PASSWORD` | | Passsword to use to connect to the HTTP proxy |
2019-09-09 20:39:47 -04:00
| `SHADOWSOCKS` | `on` | `on` or `off` , to enable the internal SOCKS5 proxy Shadowsocks |
| `SHADOWSOCKS_LOG` | `on` | `on` or `off` to enable logging for Shadowsocks |
| `SHADOWSOCKS_PORT` | `8388` | `1024` to `65535` internal port for SOCKS5 proxy |
| `SHADOWSOCKS_PASSWORD` | | Passsword to use to connect to the SOCKS5 proxy |
2018-02-21 11:55:45 -05:00
2019-05-23 11:58:52 +02:00
## Connect to it
2018-04-15 14:15:58 -04:00
2019-05-23 11:58:52 +02:00
There are various ways to achieve this, depending on your use case.
2018-11-18 19:31:09 +02:00
2019-06-29 13:42:44 +02:00
- <details><summary>Connect containers in the same docker-compose.yml as PIA</summary><p>
Add `network_mode: "service:pia"` to your * docker-compose.yml * (no need for `depends_on` )
</p></details>
2019-05-23 11:58:52 +02:00
- <details><summary>Connect other containers to PIA</summary><p>
2018-11-20 09:27:10 +02:00
2019-06-29 13:42:44 +02:00
Add `--network=container:pia` when launching the container, provided PIA is already running
2018-11-18 19:31:09 +02:00
2019-05-23 11:58:52 +02:00
</p></details>
- <details><summary>Connect containers from another docker-compose.yml</summary><p>
2019-04-26 21:43:26 +02:00
2019-06-29 13:42:44 +02:00
Add `network_mode: "container:pia"` to your * docker-compose.yml * , provided PIA is already running
2019-04-26 21:43:26 +02:00
2019-06-22 18:00:17 +02:00
</p></details>
2019-09-09 20:39:47 -04:00
- <details><summary>Connect LAN devices through the built-in HTTP proxy * Tinyproxy * (i.e. with Chrome, Kodi, etc.)</summary><p>
2019-06-22 18:00:17 +02:00
2019-06-29 13:42:44 +02:00
1. Setup a HTTP proxy client, such as [SwitchyOmega for Chrome ](https://chrome.google.com/webstore/detail/proxy-switchyomega/padekgcemlokbadohgkifijomclgjgif?hl=en )
1. Ensure the PIA container is launched with:
2019-09-09 20:39:47 -04:00
- port `8888` published `-p 8888:8888/tcp`
- your LAN subnet, i.e. `192.168.1.0/24` , set as `-e EXTRA_SUBNETS=192.168.1.0/24`
1. With your HTTP proxy client, connect to the Docker host (i.e. `192.168.1.10` ) on port `8888` . You need to enter your credentials if you set them with `TINYPROXY_USER` and `TINYPROXY_PASSWORD` .
1. If you set `PROXY_LOG_LEVEL` to `Info` , more information will be logged in the Docker logs, merged with the OpenVPN logs.
`TINYPROXY_LOG` defaults to `Critical` to avoid logging everything, for privacy purposes.
</p></details>
- <details><summary>Connect LAN devices through the built-in SOCKS5 proxy * Shadowsocks * (per app, system wide, etc.)</summary><p>
1. Setup a SOCKS5 proxy client, there is a list of [ShadowSocks clients for **all platforms** ](https://shadowsocks.org/en/download/clients.html )
1. Ensure the PIA container is launched with:
- port `8388` published `-p 8388:8388/tcp -p 8388:8388/udp`
- your LAN subnet, i.e. `192.168.1.0/24` , set as `-e EXTRA_SUBNETS=192.168.1.0/24`
1. With your SOCKS5 proxy client, connect to the Docker host (i.e. `192.168.1.10` ) on port `8388` , using the password you have set with `SHADOWSOCKS_PASSWORD` .
2019-09-09 12:26:30 -04:00
1. If you set `PROXY_LOG_LEVEL` to `Info` , more information will be logged in the Docker logs, merged with the OpenVPN logs.
2019-06-22 18:00:17 +02:00
2019-05-23 11:58:52 +02:00
</p></details>
- <details><summary>Access ports of containers connected to PIA</summary><p>
2018-11-18 19:31:09 +02:00
2019-06-29 17:20:10 +02:00
In example, to access port `8000` of container `xyz` and `9000` of container `abc` connected to PIA,
publish ports `8000` and `9000` for the PIA container and access them as you would with any other container
2018-11-18 19:31:09 +02:00
2019-05-23 11:58:52 +02:00
</p></details>
2019-06-22 18:00:17 +02:00
- <details><summary>Access ports of containers connected to PIA, all in the same docker-compose.yml</summary><p>
2019-05-23 11:58:52 +02:00
2019-06-29 13:42:44 +02:00
In example, to access port `8000` of container `xyz` and `9000` of container `abc` connected to PIA, publish port `8000` and `9000` for the PIA container.
The docker-compose.yml file would look like:
2019-05-23 11:58:52 +02:00
```yml
2019-07-28 18:18:59 -04:00
version: '3.7'
2019-05-23 11:58:52 +02:00
services:
2019-06-22 18:00:17 +02:00
pia:
2019-05-23 11:58:52 +02:00
image: qmcgaw/private-internet-access
container_name: pia
2019-07-28 18:18:59 -04:00
init: true
2019-05-23 11:58:52 +02:00
cap_add:
2019-06-22 18:00:17 +02:00
- NET_ADMIN
2019-05-23 11:58:52 +02:00
devices:
2019-06-22 18:00:17 +02:00
- /dev/net/tun
2019-05-23 11:58:52 +02:00
environment:
2019-06-22 18:00:17 +02:00
- USER=js89ds7
- PASSWORD=8fd9s239G
ports:
- 8000:8000/tcp
- 9000:9000/tcp
abc:
image: abc
container_name: abc
network_mode: "service:pia"
xyz:
image: xyz
container_name: xyz
network_mode: "service:pia"
2019-05-23 11:58:52 +02:00
```
2018-11-20 09:27:10 +02:00
2019-05-23 11:58:52 +02:00
</p></details>
2019-04-26 16:02:14 +02:00
2019-06-26 17:24:10 +02:00
## Port forwarding
2019-09-02 16:38:41 +02:00
By setting `PORT_FORWARDING` environment variable to `true` , the forwarded port will be read and written to the file specified in `PORT_FORWARDING_STATUS_FILE` (by default, this is set to `/forwarded_port` ). If the location for this file does not exist, it will be created automatically.
2019-07-15 22:02:40 +02:00
You can mount this file as a volume to read it from other containers.
2019-06-26 17:24:10 +02:00
Note that not all regions support port forwarding.
2018-11-14 14:38:10 +02:00
## For the paranoids
2018-02-21 11:55:45 -05:00
2019-05-22 09:34:33 +02:00
- You can review the code which essential consists in the [Dockerfile ](https://github.com/qdm12/private-internet-access-docker/blob/master/Dockerfile ) and [entrypoint.sh ](https://github.com/qdm12/private-internet-access-docker/blob/master/entrypoint.sh )
2018-11-14 14:38:10 +02:00
- Build the images yourself:
2018-06-03 18:05:10 -04:00
2018-09-20 20:35:29 +02:00
```bash
2018-11-14 14:38:10 +02:00
docker build -t qmcgaw/private-internet-access https://github.com/qdm12/private-internet-access-docker.git
2018-09-20 20:35:29 +02:00
```
2018-06-03 18:05:10 -04:00
2018-11-14 14:38:10 +02:00
- The download and unziping of PIA openvpn files is done at build for the ones not able to download the zip files
- Checksums for PIA openvpn zip files are not used as these files change often (but HTTPS is used)
- Use `-e ENCRYPTION=strong -e BLOCK_MALICIOUS=on`
2019-04-03 19:21:49 +02:00
- DNS Leaks tests might not work because of [this ](https://github.com/qdm12/cloudflare-dns-server#verify-dns-connection ) (*TLDR*: DNS server is a local caching intermediary)
2018-09-21 11:28:23 +02:00
2019-09-02 11:33:56 -04:00
## Troubleshooting
- Password problems `AUTH: Received control message: AUTH_FAILED`
- Your password may contain a special character such as `$` .
You need to escape it with `\` in your run command or docker-compose.yml.
For example you would set `-e PASSWORD=mypa\$\$word` .
2018-10-29 16:32:11 +01:00
## TODOs
2019-09-09 20:39:47 -04:00
- Shadowsocks
- Test DNS queries
- Get logs from file and merge with docker stdout
- Mix Logs of Unbound
2019-06-29 13:42:44 +02:00
- Maybe use `--inactive 3600 --ping 10 --ping-exit 60` as default behavior
- Try without tun
2019-06-29 00:42:30 +02:00
2018-10-29 16:32:11 +01:00
## License
2018-09-21 11:28:23 +02:00
2018-10-29 17:03:24 +01:00
This repository is under an [MIT license ](https://github.com/qdm12/private-internet-access-docker/master/license )