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-04-23 10:32:31 +02:00
| 19.6MB | 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-04-23 10:32:31 +02:00
- [Alpine 3.9 ](https://alpinelinux.org ) for a tiny image
- [OpenVPN 2.4.6-r3 ](https://pkgs.alpinelinux.org/package/v3.9/main/x86_64/openvpn ) to tunnel to PIA servers
- [IPtables 1.6.2-r0 ](https://pkgs.alpinelinux.org/package/v3.9/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.7.3-r0 ](https://pkgs.alpinelinux.org/package/v3.9/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)
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
- Username and password
- Malicious DNS blocking
- Extra subnets allowed by firewall
- Run openvpn without root (but will give reconnect problems)
2019-05-22 09:34:33 +02:00
</p></details>
2019-05-23 11:58:52 +02:00
- Connect other containers to it (and thus computers, [see this]())
- The * iptables * firewall allows traffic only with needed PIA servers (IP addresses, port, protocol) combinations
- OpenVPN restarts on failure using another PIA IP address for the same region encryption combination
- Docker healthcheck pings the DNS 1.1.1.1 to verify the connection is up
- Openvpn and Unbound run **without root **
2018-02-06 21:57:41 -05: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/ )
- Firewall requirements
- 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
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-05-23 11:58:52 +02:00
docker run -d --name=pia --cap-add=NET_ADMIN --device=/dev/net/tun \
-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
```
2018-11-14 14:38:10 +02:00
Note that you can change all the [environment variables ](#environment-variables )
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
docker run --rm --network=container:pia alpine:3.9 wget -qO- https://ipinfo.io
```
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-04-23 10:32:15 +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-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 |
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-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-05-23 11:58:52 +02:00
Add `--network=container:pia` when launching the container
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-05-23 11:58:52 +02:00
Add `network_mode: "container:pia"` to your * docker-compose.yml *
2019-04-26 21:43:26 +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-08 09:36:48 +02:00
To access port `8000` of container `xyz` and `9000` of container `abc` connected to PIA, you will need a reverse proxy such as `qmcgaw/caddy-scratch` (you can build it for **ARM ** , see its readme)
2018-11-18 19:31:09 +02:00
2019-05-23 11:58:52 +02:00
1. Create the file * Caddyfile * with:
2018-11-18 19:31:09 +02:00
2019-06-08 09:36:48 +02:00
```sh
touch Caddyfile
chown 1000 Caddyfile
chmod 600 Caddyfile
```
with this content:
2019-05-23 11:58:52 +02:00
```ruby
:8000 {
proxy / xyz:8000
2018-11-18 19:31:09 +02:00
}
2019-05-23 11:58:52 +02:00
:9000 {
proxy / abc:9000
2018-11-18 19:31:09 +02:00
}
2019-05-23 11:58:52 +02:00
```
2018-11-18 19:31:09 +02:00
2019-05-23 11:58:52 +02:00
You can of course make more complicated Caddyfile (such as proxying `/xyz` to xyz:8000 and `/abc` to abc:9000, just ask me!)
2018-11-18 19:31:09 +02:00
2019-05-23 11:58:52 +02:00
1. Run Caddy with
```sh
docker run -d -p 8000:8000/tcp -p 9000:9000/tcp \
--link pia:xyz --link pia:abc \
-v $(pwd)/Caddyfile:/Caddyfile:ro \
qmcgaw/caddy-scratch
```
**WARNING ** : Make sure the Docker network in which Caddy runs is the same as the one of PIA. It can be the default `bridge` network.
1. You can now access xyz:8000 at [localhost:8000 ](http://localhost:8000 ) and abc:9000 at [localhost:9000 ](http://localhost:9000 )
For more containers, add more `--link pia:xxx` and modify * nginx.conf * accordingly
If you want to user a * docker-compose.yml * , use this example:
```yml
version: '3'
services:
piaproxy:
image: qmcgaw/caddy-scratch
container_name: piaproxy
ports:
- 8000:8000/tcp
- 9000:9000/tcp
external_links:
- pia:xzy
- pia:abc
volumes:
- ./Caddyfile:/Caddyfile:ro
abc:
image: abc
container_name: abc
network_mode: "container:pia"
xyz:
image: xyz
container_name: xyz
network_mode: "container:pia"
2018-11-18 19:31:09 +02:00
```
2019-05-23 11:58:52 +02:00
</p></details>
- <details><summary>Access ports of containers connected to PIA, all in the same * docker-compose.yml * </summary><p>
To access port `8000` of container `xyz` and `9000` of container `abc` connected to PIA, you can put all the configuration in
one single * docker-compose.yml * file. According to [issue 21 ](https://github.com/qdm12/private-internet-access-docker/issues/21 ),
this should do (**untested**):
```yml
version: '3'
services:
pia:
image: qmcgaw/private-internet-access
container_name: pia
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun
environment:
- USER=
- PASSWORD=
- REGION=
abc:
image: abc
container_name: abc
network_mode: "service:pia"
ports:
- 8000:8000/tcp
xyz:
image: xyz
container_name: xyz
network_mode: "service:pia"
ports:
- 9000:9000/tcp
```
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-08 09:36:48 +02:00
- <details><summary>Connect to the PIA through an HTTP proxy (i.e. with Firefox)</summary><p>
* I cannot make it so far sadly.. maybe someone can enlighten ! *
</p></details>
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
2018-10-29 16:32:11 +01:00
## TODOs
2019-04-03 19:21:49 +02:00
- [ ] SOCKS/HTTP proxy or VPN server for LAN devices to use the container
2018-11-20 09:27:10 +02:00
- [ ] Port forwarding
2019-05-22 09:34:33 +02:00
- [ ] Nginx scratch
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 )