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?
sudo /usr/local/sbin/_oob_shim -u root cat /etc/shadow
which is a hole in your suggested version. You're totally right about the quoting though, I'll start withsudo -u "#$SUDO_UID" -g "#$SUDO_GID" -- "$@"
and keep looking for security holes. – Michael Shick Mar 13 '15 at 16:14--
if of course correct. I'd better edit that in to my answer! – Celada Mar 14 '15 at 09:21