I have a cell modem connected to my server that I want to use as a means to get notification emails out when the landline dies.
To nicely separate normal network access and this exceptional cell modem access, I created a network namespace and created the network device in there as the only device. To have a program use the cell modem I simply use ip netns exec
.
The wrinkle is that I want to allow any user to run any program they wish in the namespace, but netns exec
requires root. My solution is as follows:
/usr/local/sbin/_oob_shim:
#!/bin/sh
cmd_line="$@"
/bin/ip netns exec oob \
/usr/bin/sudo -u "#$SUDO_UID" -g "#$SUDO_GID" /bin/sh -c "$cmd_line"
/etc/sudoers:
ALL ALL=NOPASSWD: /usr/local/sbin/_oob_shim
I figure the only way to run the shim without already being root or knowing the root password is through sudo, and I can trust sudo to set $SUDO_UID and $SUDO_GID to the right values.
Am I opening myself up to significant risk? Or, should I say am I missing any obvious caveats?