Skip to content

Commit

Permalink
Make linuxnns and linuxvrf use of 'ip' more-secure. #1481
Browse files Browse the repository at this point in the history
  • Loading branch information
mfeit-internet2 committed Nov 7, 2024
1 parent 4fc12ee commit 51c2296
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 100 deletions.
3 changes: 2 additions & 1 deletion pscheduler-context-linuxnns/linuxnns/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ NAME=null
FILES=\
enumerate \
data-is-valid \
change
change \
change-secure


install: $(FILES)
Expand Down
49 changes: 2 additions & 47 deletions pscheduler-context-linuxnns/linuxnns/change
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,5 @@
# Change the context and do the next thing.
#

# Data-is-valid should cause non-Linux use of this plugin to be
# rejected, but an extra check doesn't hurt.
if [ "$(uname -s)" != "Linux" ]
then
echo "The linuxnns context is not supported on this platform." 1>&2
exit 1
fi


TMPBASE=${TMPDIR:-/tmp}/$WHOAMI.$$
cleanup()
{
if [ "$TMPBASE" ]
then
rm -rf $TMPBASE*
fi
}
trap cleanup EXIT


INPUT="${TMPBASE}.input"
cat > "${INPUT}"


OLD_USER=$(id -nu)


NAMESPACE=$(jq -r '.data.namespace' "${INPUT}")
if [ -z "${NAMESPACE}" ]
then
echo "Input is missing namespace." 1>&2
exit 1
fi


EXEC=$(jq -r '.exec' "${INPUT}")
if [ ! -x "${EXEC}" ]
then
echo "Cannot execute '${EXEC}'." 1>&2
exit 1
fi


# This becomes root to change the namespace and then becomes the prior
# user to exec whatever comes next.

exec sudo /sbin/ip netns exec "${NAMESPACE}" sudo -u "${OLD_USER}" "${EXEC}"
WHEREAMI=$(cd $(dirname "$0") && pwd)
exec sudo "${WHEREAMI}/$(basename "$0")-secure"
57 changes: 57 additions & 0 deletions pscheduler-context-linuxnns/linuxnns/change-secure
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh -e
#
# Change the context and do the next thing - Secure Part
#
# This must be executed by sudo(8).
#

# Data-is-valid should cause non-Linux use of this plugin to be
# rejected, but an extra check doesn't hurt.
if [ "$(uname -s)" != "Linux" ]
then
echo "The linuxnns context is not supported on this platform." 1>&2
exit 1
fi

if ! [ -n "$SUDO_USER" ]
then
echo "No SUDO_USER provided." 1>&2
exit 1
fi


TMPBASE=${TMPDIR:-/tmp}/$WHOAMI.$$
cleanup()
{
if [ "$TMPBASE" ]
then
rm -rf $TMPBASE*
fi
}
trap cleanup EXIT


INPUT="${TMPBASE}.input"
cat > "${INPUT}"


NAMESPACE=$(jq -r '.data.namespace' "${INPUT}")
if [ -z "${NAMESPACE}" ]
then
echo "Input is missing namespace." 1>&2
exit 1
fi


EXEC=$(jq -r '.exec' "${INPUT}")
if [ ! -x "${EXEC}" ]
then
echo "Cannot execute '${EXEC}'." 1>&2
exit 1
fi


# Change the namespace and then becomes the prior user to exec
# whatever comes next.

ip netns exec "${NAMESPACE}" sudo -u "${SUDO_USER}" "${EXEC}"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# pscheduler-context-linuxnns
#
Cmnd_Alias PSCHEDULER_CONTEXT_LINUXNNS=/sbin/ip netns exec *
Cmnd_Alias PSCHEDULER_CONTEXT_LINUXNNS=/usr/lib/pscheduler/libexec/classes/context/linuxnns/change-secure
pscheduler ALL = (root) NOPASSWD: PSCHEDULER_CONTEXT_LINUXNNS
Defaults!PSCHEDULER_CONTEXT_LINUXNNS !requiretty
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ cat > $RPM_BUILD_ROOT/%{_pscheduler_sudoersdir}/%{name} <<'EOF'
#
# %{name}
#
Cmnd_Alias PSCHEDULER_CONTEXT_LINUXNNS=/sbin/ip netns exec *
Cmnd_Alias PSCHEDULER_CONTEXT_LINUXNNS=%{dest}/change-secure
%{_pscheduler_user} ALL = (root) NOPASSWD: PSCHEDULER_CONTEXT_LINUXNNS
Defaults!PSCHEDULER_CONTEXT_LINUXNNS !requiretty
EOF
Expand Down
3 changes: 2 additions & 1 deletion pscheduler-context-linuxvrf/linuxvrf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
FILES=\
enumerate \
data-is-valid \
change
change \
change-secure


install: $(FILES)
Expand Down
49 changes: 2 additions & 47 deletions pscheduler-context-linuxvrf/linuxvrf/change
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,5 @@
# Change the context and do the next thing.
#

# Data-is-valid should cause non-Linux use of this plugin to be
# rejected, but an extra check doesn't hurt.
if [ "$(uname -s)" != "Linux" ]
then
echo "The linuxvrf context is not supported on this platform." 1>&2
exit 1
fi


TMPBASE=${TMPDIR:-/tmp}/$WHOAMI.$$
cleanup()
{
if [ "$TMPBASE" ]
then
rm -rf $TMPBASE*
fi
}
trap cleanup EXIT


INPUT="${TMPBASE}.input"
cat > "${INPUT}"


OLD_USER=$(id -nu)


VRF=$(jq -r '.data.vrf' "${INPUT}")
if [ -z "${VRF}" ]
then
echo "Input is missing VRF name." 1>&2
exit 1
fi


EXEC=$(jq -r '.exec' "${INPUT}")
if [ ! -x "${EXEC}" ]
then
echo "Cannot execute '${EXEC}'." 1>&2
exit 1
fi


# This becomes root to change the VRFand then becomes the prior
# user to exec whatever comes next.

exec sudo /sbin/ip vrf exec "${VRF}" sudo -u "${OLD_USER}" "${EXEC}"
WHEREAMI=$(cd $(dirname "$0") && pwd)
exec sudo "${WHEREAMI}/$(basename "$0")-secure"
54 changes: 54 additions & 0 deletions pscheduler-context-linuxvrf/linuxvrf/change-secure
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh -e
#
# Change the context and do the next thing - Secure Part
#
# This must be executed by sudo(8).
#

# Data-is-valid should cause non-Linux use of this plugin to be
# rejected, but an extra check doesn't hurt.
if [ "$(uname -s)" != "Linux" ]
then
echo "The linuxvrf context is not supported on this platform." 1>&2
exit 1
fi


TMPBASE=${TMPDIR:-/tmp}/$WHOAMI.$$
cleanup()
{
if [ "$TMPBASE" ]
then
rm -rf $TMPBASE*
fi
}
trap cleanup EXIT


INPUT="${TMPBASE}.input"
cat > "${INPUT}"


OLD_USER=$(id -nu)


VRF=$(jq -r '.data.vrf' "${INPUT}")
if [ -z "${VRF}" ]
then
echo "Input is missing VRF name." 1>&2
exit 1
fi


EXEC=$(jq -r '.exec' "${INPUT}")
if [ ! -x "${EXEC}" ]
then
echo "Cannot execute '${EXEC}'." 1>&2
exit 1
fi


# This becomes root to change the VRFand then becomes the prior
# user to exec whatever comes next.

exec sudo /sbin/ip vrf exec "${VRF}" sudo -u "${OLD_USER}" "${EXEC}"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# pscheduler-context-linuxvrf
#
Cmnd_Alias PSCHEDULER_CONTEXT_LINUXVRF=/sbin/ip vrf exec *
Cmnd_Alias PSCHEDULER_CONTEXT_LINUXVRF=/usr/lib/pscheduler/libexec/classes/context/linuxvrf/change-secure
pscheduler ALL = (root) NOPASSWD: PSCHEDULER_CONTEXT_LINUXVRF
Defaults!PSCHEDULER_CONTEXT_LINUXVRF !requiretty
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ cat > $RPM_BUILD_ROOT/%{_pscheduler_sudoersdir}/%{name} <<'EOF'
#
# %{name}
#
Cmnd_Alias PSCHEDULER_CONTEXT_LINUXVRF=/sbin/ip vrf exec *
Cmnd_Alias PSCHEDULER_CONTEXT_LINUXVRF=%{dest}/change-secure
%{_pscheduler_user} ALL = (root) NOPASSWD: PSCHEDULER_CONTEXT_LINUXVRF
Defaults!PSCHEDULER_CONTEXT_LINUXVRF !requiretty
EOF
Expand Down

0 comments on commit 51c2296

Please sign in to comment.