Skip to content

Added multi-instance support #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### 2.0.2 - Added multi-instance support

- Added `TUNNEL_INTERFACE` to set interface name (in case of multiple containers)
- Some fixes for general user
- Changed generation of `include-conf.conf` to `dynamic.conf`

### 2.0.1 - Fix service start

- Fixed command for starting service
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ ENV EASYRSA=/usr/share/easy-rsa \
EASYRSA_VARS_FILE=/config/ssl/vars \
#EASYRSA_SSL_CONF=/config/ssl/openssl-easyrsa.cnf \
EASYRSA_SAFE_CONF=/config/ssl/safessl-easyrsa.cnf \
EASYRSA_TEMP_FILE=/config/tmp/temp
EASYRSA_TEMP_FILE=/config/tmp/temp \
TUNNEL_INTERFACE="tun0"

# Install packages
RUN apk add --no-cache \
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.armhf
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ ENV EASYRSA=/usr/share/easy-rsa \
EASYRSA_VARS_FILE=/config/ssl/vars \
#EASYRSA_SSL_CONF=/config/ssl/openssl-easyrsa.cnf \
EASYRSA_SAFE_CONF=/config/ssl/safessl-easyrsa.cnf \
EASYRSA_TEMP_FILE=/config/tmp/temp
EASYRSA_TEMP_FILE=/config/tmp/temp \
TUNNEL_INTERFACE="tun0"

# Install packages
RUN apk add --no-cache \
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ services:
|`-e PUID=1000`|for UserID - see below for explanation|
|`-e PGID=1000`|for GroupID - see below for explanation|
|`-e PERSISTENT_INTERFACE=true`|Enable persistent TUN interface|
|`-e TUNNEL_INTERFACE="tun0"`|Tunnel interface name (default: tun0)|
|`-e USE_FIREWALL=false`|Disable any firewall related rules to be created, modified ... (must be implemented in example)|
|`-v /config`|All the config files including OpenVPNs reside here|
|`-v /log`|Log files reside here|
Expand Down Expand Up @@ -152,6 +153,10 @@ Just put *.ovpn* file in `/config/openvpn/config` and restart container.

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

### Cannot ioctl TUNSETIFF tun0: Operation not permitted (errno=1)

Just manualy remove **tun0** manually `openvpn --rmtun --dev tun0`.

## Contribute

Feel free to contribute new features to this container, but first see [Contribute Guide](CONTRIBUTING.md).
Expand Down
5 changes: 1 addition & 4 deletions root/defaults/openvpn/system.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
# Change permissions (user & group)
iproute "/usr/local/sbin/ovpn-ip"

# Static interface
dev tun0

# Script security level
script-security 2

Expand Down Expand Up @@ -54,4 +51,4 @@ client-config-dir /config/openvpn/ccd
crl-verify /config/pki/crl.pem

# Include configs
config /config/openvpn/include-conf.conf
config /config/openvpn/dynamic.conf
6 changes: 3 additions & 3 deletions root/etc/cont-finish.d/60-network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#

# Delete tunnel interface (if not persistant)
if [ -n "$(cat /proc/net/dev | grep tun0)" ] && { [ -z "$PERSISTENT_INTERFACE" ] || [ "$PERSISTENT_INTERFACE" != "true" ]; }; then
echo "Removing tun0 interface"
openvpn --rmtun --dev tun0
if [ -n "$(cat /proc/net/dev | grep $TUNNEL_INTERFACE)" ] && { [ -z "$PERSISTENT_INTERFACE" ] || [ "$PERSISTENT_INTERFACE" != "true" ]; }; then
echo "Removing $TUNNEL_INTERFACE interface"
openvpn --rmtun --dev $TUNNEL_INTERFACE
fi
12 changes: 6 additions & 6 deletions root/etc/cont-init.d/60-network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ if [ ! -c "/dev/net/tun" ]; then
fi

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

# Create tunnel interface
if [ -z "$(cat /proc/net/dev | grep tun0)" ]; then
echo "Creating tun0 interface"
openvpn --mktun --dev tun0 --dev-type tun --user abc --group abc
if [ -z "$(cat /proc/net/dev | grep $TUNNEL_INTERFACE)" ]; then
echo "Creating $TUNNEL_INTERFACE interface"
openvpn --mktun --dev $TUNNEL_INTERFACE --dev-type tun --user $CONTAINER_USER --group $CONTAINER_USER
fi
24 changes: 15 additions & 9 deletions root/etc/cont-init.d/70-config.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
#!/usr/bin/with-contenv bash

#
# Link OpenVPN configs
# Dynamic OpenVPN configs
#

LINK_FILE=/config/openvpn/include-conf.conf
DYNAMIC_FILE=/config/openvpn/dynamic.conf

# Build link file
echo "#" > $LINK_FILE
echo "# DO NOT EDIT" >> $LINK_FILE
echo "# Autogenerated file, based on /config/openvpn/config" >> $LINK_FILE
echo "#" >> $LINK_FILE
echo "" >> $LINK_FILE
echo "#" > $DYNAMIC_FILE
echo "# DO NOT EDIT" >> $DYNAMIC_FILE
echo "# Autogenerated file, based on /config/openvpn/config" >> $DYNAMIC_FILE
echo "#" >> $DYNAMIC_FILE
echo "" >> $DYNAMIC_FILE

# Set interface name
echo "# Interface" >> $DYNAMIC_FILE
echo "dev $TUNNEL_INTERFACE" >> $DYNAMIC_FILE
echo "" >> $DYNAMIC_FILE

# Include all configuration files
for file in /config/openvpn/config/*
do
[ -e "$file" ] || continue

echo "config $file" >> $LINK_FILE
echo "config $file" >> $DYNAMIC_FILE
done

chown abc:abc $LINK_FILE
chown $CONTAINER_USER:$CONTAINER_USER $DYNAMIC_FILE