OpenVPN typically requires being run with sudo privileges - which is bad for security. This would also require night_watchman to have setuid privileges in order to spawn OpenVPN.
So to increase security we're going to run OpenVPN run without requiring root privileges.
OpenVPN provides a how-to guide on their website. I've summarized the steps below. Alternatively, the shell commands are provided in night_watchman/setup_openvpn.sh.
touch /usr/local/unpriv-ip
chmod 755 /usr/local/unpriv-ip
echo "#!/bin/sh\nsudo /sbin/ip $*" > /usr/local/unpriv-ip
echo "#!/bin/sh\nopenvpn --rmtun --dev tun0\nopenvpn --mktun --dev tun0 --dev-type tun --user openvpn --group openvpn" > /etc/openvpn/openvpn-startup
useradd -s /sbin/nologin openvpn
mkdir /var/lib/openvpn
chown openvpn:openvpn /var/lib/openvpn
usermod -d /var/lib/openvpn -s /sbin/nologin openvpn
mkdir /var/log/openvpn
mkdir /var/run/openvpn
chown openvpn:openvpn /var/run/openvpn /var/log/openvpn /etc/openvpn -R
chmod u+w /var/run/openvpn /var/log/openvpn -R
Then add these two lines by editing /etc/sudo
or running visudo
:
openvpn ALL=(ALL) NOPASSWD: /sbin/ip
Defaults:openvpn !requiretty
log /var/log/openvpn/openvpn
iproute /usr/local/sbin/unpriv-ip
dev tun0
persist-tun
Done! Openvpn is now set up to run without root privileges.
To manually run openvpn without root, run:
sudo -u openvpn openvpn --config <config>
SELinux users: if you're using SELinux there is one final step at the bottom of the OpenVPN guide you must follow.