-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make linuxnns and linuxvrf use of 'ip' more-secure. #1481
- Loading branch information
1 parent
4fc12ee
commit 51c2296
Showing
10 changed files
with
123 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ NAME=null | |
FILES=\ | ||
enumerate \ | ||
data-is-valid \ | ||
change | ||
change \ | ||
change-secure | ||
|
||
|
||
install: $(FILES) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
2 changes: 1 addition & 1 deletion
2
pscheduler-context-linuxnns/linuxnns/unibuild-packaging/deb/sudoers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
FILES=\ | ||
enumerate \ | ||
data-is-valid \ | ||
change | ||
change \ | ||
change-secure | ||
|
||
|
||
install: $(FILES) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
2 changes: 1 addition & 1 deletion
2
pscheduler-context-linuxvrf/linuxvrf/unibuild-packaging/deb/sudoers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters