Skip to content

Commit

Permalink
Local and Nephio User Validation (#249)
Browse files Browse the repository at this point in the history
* Add checks for passwordless sudo of current user and NEPHIO_USER

* Add checks for root user running init and non root user for NEPHIO_USER
  • Loading branch information
dkosteck authored Mar 2, 2024
1 parent e175645 commit 16fb429
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions e2e/provision/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,41 @@ FAIL_FAST=${FAIL_FAST:-$(get_metadata fail_fast "false")}
echo "$DEBUG, $DEPLOYMENT_TYPE, $RUN_E2E, $REPO, $BRANCH, $NEPHIO_USER, $HOME, $REPO_DIR, $DOCKERHUB_USERNAME, $DOCKERHUB_TOKEN"
trap get_status ERR

# Validate root permissions for current user and NEPHIO_USER
if ! sudo -n "true"; then
echo ""
echo "Passwordless sudo is needed for '$(id -nu)' user."
echo "Please fix your /etc/sudoers file. You likely want an"
echo "entry like the following one..."
echo ""
echo "$(id -nu) ALL=(ALL) NOPASSWD: ALL"
exit 1
fi

if ! sudo -u "$NEPHIO_USER" sudo -n "true"; then
echo ""
echo "Passwordless sudo is needed for '$(sudo -u "$NEPHIO_USER" id -nu)' user."
echo "Please fix your /etc/sudoers file. You likely want an"
echo "entry like the following one..."
echo ""
echo "$(sudo -u "$NEPHIO_USER" id -nu) ALL=(ALL) NOPASSWD: ALL"
exit 1
fi

if [[ $(id -u) -ne 0 ]]; then
echo ""
echo "This script must to be executed by the root user."
echo ""
exit 1
fi

if [[ $(sudo -u "$NEPHIO_USER" id -u) -eq 0 ]]; then
echo ""
echo "NEPHIO_USER cannot be root (user '$(sudo -u "$NEPHIO_USER" id -nu)')."
echo ""
exit 1
fi

if ! command -v git >/dev/null; then
source /etc/os-release || source /usr/lib/os-release
case ${ID,,} in
Expand Down

0 comments on commit 16fb429

Please sign in to comment.