Skip to content

Commit 00e1d13

Browse files
authored
Merge pull request #6 from SloCompTech/develop
Added multi-instance support
2 parents 4466d55 + 9ed2e99 commit 00e1d13

File tree

8 files changed

+40
-24
lines changed

8 files changed

+40
-24
lines changed

CHANGELOG.md

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

3+
### 2.0.2 - Added multi-instance support
4+
5+
- Added `TUNNEL_INTERFACE` to set interface name (in case of multiple containers)
6+
- Some fixes for general user
7+
- Changed generation of `include-conf.conf` to `dynamic.conf`
8+
39
### 2.0.1 - Fix service start
410

511
- Fixed command for starting service

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ ENV EASYRSA=/usr/share/easy-rsa \
4343
EASYRSA_VARS_FILE=/config/ssl/vars \
4444
#EASYRSA_SSL_CONF=/config/ssl/openssl-easyrsa.cnf \
4545
EASYRSA_SAFE_CONF=/config/ssl/safessl-easyrsa.cnf \
46-
EASYRSA_TEMP_FILE=/config/tmp/temp
46+
EASYRSA_TEMP_FILE=/config/tmp/temp \
47+
TUNNEL_INTERFACE="tun0"
4748

4849
# Install packages
4950
RUN apk add --no-cache \

Dockerfile.armhf

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ ENV EASYRSA=/usr/share/easy-rsa \
4343
EASYRSA_VARS_FILE=/config/ssl/vars \
4444
#EASYRSA_SSL_CONF=/config/ssl/openssl-easyrsa.cnf \
4545
EASYRSA_SAFE_CONF=/config/ssl/safessl-easyrsa.cnf \
46-
EASYRSA_TEMP_FILE=/config/tmp/temp
46+
EASYRSA_TEMP_FILE=/config/tmp/temp \
47+
TUNNEL_INTERFACE="tun0"
4748

4849
# Install packages
4950
RUN apk add --no-cache \

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ services:
7070
|`-e PUID=1000`|for UserID - see below for explanation|
7171
|`-e PGID=1000`|for GroupID - see below for explanation|
7272
|`-e PERSISTENT_INTERFACE=true`|Enable persistent TUN interface|
73+
|`-e TUNNEL_INTERFACE="tun0"`|Tunnel interface name (default: tun0)|
7374
|`-e USE_FIREWALL=false`|Disable any firewall related rules to be created, modified ... (must be implemented in example)|
7475
|`-v /config`|All the config files including OpenVPNs reside here|
7576
|`-v /log`|Log files reside here|
@@ -152,6 +153,10 @@ Just put *.ovpn* file in `/config/openvpn/config` and restart container.
152153

153154
- [OpenVPN troubleshoot guide](https://community.openvpn.net/openvpn/wiki/HOWTO#Troubleshooting)
154155

156+
### Cannot ioctl TUNSETIFF tun0: Operation not permitted (errno=1)
157+
158+
Just manualy remove **tun0** manually `openvpn --rmtun --dev tun0`.
159+
155160
## Contribute
156161

157162
Feel free to contribute new features to this container, but first see [Contribute Guide](CONTRIBUTING.md).

root/defaults/openvpn/system.conf

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
# Change permissions (user & group)
1111
iproute "/usr/local/sbin/ovpn-ip"
1212

13-
# Static interface
14-
dev tun0
15-
1613
# Script security level
1714
script-security 2
1815

@@ -54,4 +51,4 @@ client-config-dir /config/openvpn/ccd
5451
crl-verify /config/pki/crl.pem
5552

5653
# Include configs
57-
config /config/openvpn/include-conf.conf
54+
config /config/openvpn/dynamic.conf

root/etc/cont-finish.d/60-network.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66

77
# Delete tunnel interface (if not persistant)
8-
if [ -n "$(cat /proc/net/dev | grep tun0)" ] && { [ -z "$PERSISTENT_INTERFACE" ] || [ "$PERSISTENT_INTERFACE" != "true" ]; }; then
9-
echo "Removing tun0 interface"
10-
openvpn --rmtun --dev tun0
8+
if [ -n "$(cat /proc/net/dev | grep $TUNNEL_INTERFACE)" ] && { [ -z "$PERSISTENT_INTERFACE" ] || [ "$PERSISTENT_INTERFACE" != "true" ]; }; then
9+
echo "Removing $TUNNEL_INTERFACE interface"
10+
openvpn --rmtun --dev $TUNNEL_INTERFACE
1111
fi

root/etc/cont-init.d/60-network.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ if [ ! -c "/dev/net/tun" ]; then
1919
fi
2020

2121
# Remove existing interface if not persistent interface selected
22-
if [ -n "$(cat /proc/net/dev | grep tun0)" ] && { [ -z "$PERSISTENT_INTERFACE" ] || [ "$PERSISTENT_INTERFACE" != "true" ]; }; then
23-
echo "Removing tun0 interface"
24-
openvpn --rmtun --dev tun0
22+
if [ -n "$(cat /proc/net/dev | grep $TUNNEL_INTERFACE)" ] && { [ -z "$PERSISTENT_INTERFACE" ] || [ "$PERSISTENT_INTERFACE" != "true" ]; }; then
23+
echo "Removing $TUNNEL_INTERFACE interface"
24+
openvpn --rmtun --dev $TUNNEL_INTERFACE
2525
fi
2626

2727
# Create tunnel interface
28-
if [ -z "$(cat /proc/net/dev | grep tun0)" ]; then
29-
echo "Creating tun0 interface"
30-
openvpn --mktun --dev tun0 --dev-type tun --user abc --group abc
28+
if [ -z "$(cat /proc/net/dev | grep $TUNNEL_INTERFACE)" ]; then
29+
echo "Creating $TUNNEL_INTERFACE interface"
30+
openvpn --mktun --dev $TUNNEL_INTERFACE --dev-type tun --user $CONTAINER_USER --group $CONTAINER_USER
3131
fi

root/etc/cont-init.d/70-config.sh

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
#!/usr/bin/with-contenv bash
22

33
#
4-
# Link OpenVPN configs
4+
# Dynamic OpenVPN configs
55
#
66

7-
LINK_FILE=/config/openvpn/include-conf.conf
7+
DYNAMIC_FILE=/config/openvpn/dynamic.conf
88

99
# Build link file
10-
echo "#" > $LINK_FILE
11-
echo "# DO NOT EDIT" >> $LINK_FILE
12-
echo "# Autogenerated file, based on /config/openvpn/config" >> $LINK_FILE
13-
echo "#" >> $LINK_FILE
14-
echo "" >> $LINK_FILE
10+
echo "#" > $DYNAMIC_FILE
11+
echo "# DO NOT EDIT" >> $DYNAMIC_FILE
12+
echo "# Autogenerated file, based on /config/openvpn/config" >> $DYNAMIC_FILE
13+
echo "#" >> $DYNAMIC_FILE
14+
echo "" >> $DYNAMIC_FILE
1515

16+
# Set interface name
17+
echo "# Interface" >> $DYNAMIC_FILE
18+
echo "dev $TUNNEL_INTERFACE" >> $DYNAMIC_FILE
19+
echo "" >> $DYNAMIC_FILE
20+
21+
# Include all configuration files
1622
for file in /config/openvpn/config/*
1723
do
1824
[ -e "$file" ] || continue
1925

20-
echo "config $file" >> $LINK_FILE
26+
echo "config $file" >> $DYNAMIC_FILE
2127
done
2228

23-
chown abc:abc $LINK_FILE
29+
chown $CONTAINER_USER:$CONTAINER_USER $DYNAMIC_FILE

0 commit comments

Comments
 (0)