Skip to content

Commit 1a4be14

Browse files
committed
Merge branch 'develop'
2 parents 97232dd + 3c118c3 commit 1a4be14

File tree

24 files changed

+594
-6
lines changed

24 files changed

+594
-6
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
### 1.0.3 - New examples, fixes, more docs
4+
5+
- Updated instructions
6+
- Improved `Makefile`
7+
- Allowed **ping** to the container
8+
- Added new examples **basic_nat_wlp** and **basic_routed**
9+
- Added **LAN protection** to original example
10+
- Added **docker-compose** for sample
11+
312
### 1.0.2 - Official release
413

514
- Fixed typo in `basic_nat` example config wizard

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ build:
2929
config:
3030
@echo "Running temporary container"
3131
mkdir -p data
32-
docker run -it --rm --cap-add NET_ADMIN -v ${DATA_DIR}:/config ${IMAGE_NAME}:latest bash
32+
docker run -it -e PUID=$(id -u) -e PGID=$(id -g) --rm --cap-add NET_ADMIN -v ${DATA_DIR}:/config ${IMAGE_NAME}:latest bash
3333

3434
#
3535
# Setups & starts real container
3636
# Run only once, then use docker start|stop|restart|exec
3737
#
3838
setup:
3939
@echo "Running temporary container"
40-
docker run -it --cap-add NET_ADMIN -p 1194:1194/udp -v ${DATA_DIR}:/config --name ${CONTAINER_NAME} ${IMAGE_NAME}:latest
40+
docker run -it -d -e PUID=$(id -u) -e PGID=$(id -g) --cap-add NET_ADMIN -p 1194:1194/udp -v ${DATA_DIR}:/config --name ${CONTAINER_NAME} ${IMAGE_NAME}:latest
4141

4242
#
4343
# Starts container

README.md

+37-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,37 @@ docker run \
3434

3535
### docker-compose
3636

37-
```
38-
37+
``` yml
38+
version: '2.2'
39+
services:
40+
ovpn:
41+
image: slocomptech/openvpn
42+
container_name: ovpn
43+
hostname: ovpn
44+
cap_add:
45+
- NET_ADMIN
46+
ports:
47+
- "1194:1194/udp"
48+
volumes:
49+
- ./data:/config
50+
environment:
51+
- PUID=1000
52+
- PGUID=1000
53+
restart: on-failure
54+
# If you want to build from source add build:
55+
build:
56+
context: .
57+
cache_from:
58+
- lsiobase/alpine.python3:latest
59+
networks:
60+
mynetwork:
61+
ipv4_address: 10.0.0.5
62+
ipv6_address: 2001:1111::5
63+
64+
networks:
65+
mynetwork:
66+
driver: host
67+
enable_ipv6: true
3968
```
4069
4170
## Parameters
@@ -112,6 +141,11 @@ For more infromation see:
112141
- **configuration example directory** (for more info about example)
113142
- [Contributing](CONTRIBUTING.md) (for explanation how container works, how to write an example config ...)
114143

144+
## Troubleshooting
145+
146+
- [OpenVPN troubleshoot guide](https://community.openvpn.net/openvpn/wiki/HOWTO#Troubleshooting)
147+
148+
115149
## Contribute
116150

117151
Feel free to contribute new features to this container, but first see [Contribute Guide](CONTRIBUTING.md).
@@ -128,7 +162,7 @@ Wanted features (please help implement):
128162
## Licenses
129163

130164
- [This project](LICENSE.md)
131-
- [OpenVPN]()
165+
- [OpenVPN](https://openvpn.net/terms/)
132166
- [Base image](https://github.com/linuxserver/docker-baseimage-alpine)
133167
- [s6 Layer](https://github.com/just-containers/s6-overlay/blob/master/LICENSE.md)
134168

docker-compose.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# OpenVPN server sample configuration
3+
#
4+
5+
version: '2.2'
6+
services:
7+
ovpn:
8+
image: slocomptech/openvpn
9+
container_name: ovpn
10+
hostname: ovpn
11+
cap_add:
12+
- NET_ADMIN
13+
ports:
14+
- "1194:1194/udp"
15+
volumes:
16+
- ./data:/config
17+
#environment:
18+
# - PUID=1000
19+
# - PGUID=1000
20+
restart: on-failure
21+
build:
22+
context: .
23+
cache_from:
24+
- lsiobase/alpine.python3:latest
25+
26+
network_mode: "bridge"
27+
#network_mode: "host"
28+

root/defaults/example/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ Hooks are located in `hook` directory. Please follow hook guidelines:
6767
- At the top of the script
6868
- Optionaly copyright notice
6969
- What this hook does
70-
- Setttings with comments and an example settings values
70+
- Setttings with comments and an example settings values
71+
72+
**Note:** All hooks run as non-root user so instead of using `ip` and `iptables` use `ovpn-ip` and `ovpn-iptables`.

root/defaults/example/config/basic_nat/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Features:
55
- Works out of the box on bridge or host network
66
- NAT (Network translation protocol)
77
- Has configuration wizard
8+
- LAN protection (does not allow traffic to LANs connected to server)
89

910
## Configure
1011

root/defaults/example/config/basic_nat/hooks/down/10-network.sh

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
# Close OpenVPN port to outside
88
ovpn-iptables -D INPUT -p udp -m udp --dport $PORT -j ACCEPT -m comment --comment "Open OpenVPN port"
99

10+
# Disable LAN protection of VPN
11+
ovpn-iptables -D FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o eth0 -d 10.0.0.0/8 -j REJECT -m comment --comment "Drop traffic VPN --> LANs"
12+
ovpn-iptables -D FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o eth0 -d 192.168.0.0/16 -j REJECT -m comment --comment "Drop traffic VPN --> LANs"
13+
ovpn-iptables -D FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o eth0 -d 172.16.0.0/12 -j REJECT -m comment --comment "Drop traffic VPN --> LANs"
14+
1015
# Disable Routing Internet <--> VPN network
1116
ovpn-iptables -D FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o eth0 -j ACCEPT -m comment --comment "Allow traffic VPN --> Internet"
1217
ovpn-iptables -D FORWARD -i eth0 -d $NETWORK_ADDRESS/24 -o tun0 -j ACCEPT -m comment --comment "Allow traffic Internet --> VPN"

root/defaults/example/config/basic_nat/hooks/init/10-network.sh

+3
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ ovpn-iptables -P INPUT DROP
1515
# Allow established connection
1616
ovpn-iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "Accept traffic from established connections"
1717

18+
# Allow ICMP ping request
19+
ovpn-iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
20+
1821
# Drop all forwarded traffic
1922
ovpn-iptables -P FORWARD DROP

root/defaults/example/config/basic_nat/hooks/up/10-network.sh

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
# Open OpenVPN port to outside
88
ovpn-iptables -A INPUT -p udp -m udp --dport $PORT -j ACCEPT -m comment --comment "Open OpenVPN port"
99

10+
# Protect LANs after VPN
11+
ovpn-iptables -A FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o eth0 -d 10.0.0.0/8 -j REJECT -m comment --comment "Drop traffic VPN --> LANs"
12+
ovpn-iptables -A FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o eth0 -d 192.168.0.0/16 -j REJECT -m comment --comment "Drop traffic VPN --> LANs"
13+
ovpn-iptables -A FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o eth0 -d 172.16.0.0/12 -j REJECT -m comment --comment "Drop traffic VPN --> LANs"
14+
1015
# Allow Routing Internet <--> VPN network
1116
ovpn-iptables -A FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o eth0 -j ACCEPT -m comment --comment "Allow traffic VPN --> Internet"
1217
ovpn-iptables -A FORWARD -i eth0 -d $NETWORK_ADDRESS/24 -o tun0 -j ACCEPT -m comment --comment "Allow traffic Internet --> VPN"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# basic_nat_wlp
2+
3+
Features:
4+
5+
- Works out of the box on bridge or host network
6+
- NAT (Network translation protocol)
7+
- Has configuration wizard
8+
- **WITHOUT** LAN protection (does not allow traffic to LANs connected to server), so you can still access devices in LAN (but **routed** example is recommended, because here traffic is still NAT-ed)
9+
10+
## Configure
11+
12+
``` bash
13+
ovpn_enconf basic_nat_wlp
14+
#Protocol udp, tcp, udp6, tcp6 [udp]:
15+
#VPN network [10.0.0.0]:
16+
#Port [1194]:
17+
#Public IP or domain of server: <PUBLIC IP>
18+
#DNS1 [8.8.8.8]:
19+
#DNS2 [8.8.4.4]:
20+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Basic OpenVPN server configuration
3+
# @author Martin Dagarin
4+
# @version 2
5+
# @since 12/03/2019
6+
#
7+
8+
# Basic info
9+
client
10+
dev tun0
11+
proto $PROTO
12+
nobind
13+
pull
14+
15+
16+
# Remote info
17+
remote $SERVER_IP $PORT
18+
19+
# Connection settings
20+
resolv-retry infinite
21+
persist-key
22+
persist-tun
23+
24+
# Encryption settings
25+
cipher AES-256-GCM
26+
27+
# Additional settings
28+
compress lzo
29+
verb 3
30+
ping 10 120
31+
32+
# Permissions
33+
user nobody
34+
group nogroup
35+
36+
# CA
37+
remote-cert-tls server
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
#
4+
# Network clear
5+
#
6+
7+
# Close OpenVPN port to outside
8+
ovpn-iptables -D INPUT -p udp -m udp --dport $PORT -j ACCEPT -m comment --comment "Open OpenVPN port"
9+
10+
# Disable Routing Internet <--> VPN network
11+
ovpn-iptables -D FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o eth0 -j ACCEPT -m comment --comment "Allow traffic VPN --> Internet"
12+
ovpn-iptables -D FORWARD -i eth0 -d $NETWORK_ADDRESS/24 -o tun0 -j ACCEPT -m comment --comment "Allow traffic Internet --> VPN"
13+
14+
# Disable NAT for VPN traffic
15+
ovpn-iptables -t nat -D POSTROUTING -s $NETWORK_ADDRESS/24 -o eth0 -j MASQUERADE -m comment --comment "NAT traffic VPN --> Internet"
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
#
4+
# Network initialization
5+
#
6+
7+
#
8+
# Because default iptables rules are set to ACCEPT all connection, we need to put some
9+
# security settings in place
10+
#
11+
12+
# Drop everything from input
13+
ovpn-iptables -P INPUT DROP
14+
15+
# Allow established connection
16+
ovpn-iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "Accept traffic from established connections"
17+
18+
# Allow ICMP ping request
19+
ovpn-iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
20+
21+
# Drop all forwarded traffic
22+
ovpn-iptables -P FORWARD DROP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
#
4+
# Network initialization
5+
#
6+
7+
# Open OpenVPN port to outside
8+
ovpn-iptables -A INPUT -p udp -m udp --dport $PORT -j ACCEPT -m comment --comment "Open OpenVPN port"
9+
10+
# Allow Routing Internet <--> VPN network
11+
ovpn-iptables -A FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o eth0 -j ACCEPT -m comment --comment "Allow traffic VPN --> Internet"
12+
ovpn-iptables -A FORWARD -i eth0 -d $NETWORK_ADDRESS/24 -o tun0 -j ACCEPT -m comment --comment "Allow traffic Internet --> VPN"
13+
14+
# Preform NAT for VPN traffic
15+
ovpn-iptables -t nat -A POSTROUTING -s $NETWORK_ADDRESS/24 -o eth0 -j MASQUERADE -m comment --comment "NAT traffic VPN --> Internet"
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
# Basic OpenVPN server configuration
3+
# @author Martin Dagarin
4+
# @version 3
5+
# @since 12/03/2019
6+
#
7+
8+
# Basic info
9+
proto $PROTO
10+
port $PORT
11+
12+
# Network info (local VPN network)
13+
topology subnet
14+
server $NETWORK_ADDRESS 255.255.255.0
15+
16+
push "redirect-gateway def1 bypass-dhcp"
17+
push "dhcp-option $DNS1"
18+
push "dhcp-option $DNS2"
19+
20+
ifconfig-pool-persist tmp/ipp.txt
21+
22+
# CA files
23+
ca pki/ca.crt
24+
cert pki/issued/server.crt
25+
key pki/private/server.key
26+
dh pki/dh.pem
27+
tls-crypt pki/ta.key
28+
remote-cert-tls client
29+
30+
# Connection settings
31+
persist-key
32+
persist-tun
33+
34+
# Encryption settings
35+
cipher AES-256-GCM
36+
37+
# Verify client certificate
38+
verify-client-cert require
39+
40+
# Additional settings
41+
client-to-client
42+
keepalive 10 120
43+
compress lzo
44+
explicit-exit-notify 1

0 commit comments

Comments
 (0)