-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* This will enable us to gracefully exit when self-service admin is unavailable for users
- Loading branch information
1 parent
3686ea7
commit fc81d96
Showing
1 changed file
with
36 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
set -e | ||
set -o pipefail | ||
|
||
# Check to see if the currently logged in user is a sudoer | ||
function is_sudoer { | ||
# Check admin group membership (fastest, but not definitive) | ||
if groups "$USER" | grep -q "admin"; | ||
then | ||
GROUP_CHECK_RESULT=$? | ||
else | ||
GROUP_CHECK_RESULT=1 | ||
fi | ||
|
||
# Check sudo privileges using sudo -l (requires sudo, but avoids direct /etc/sudoers access) | ||
if sudo -l 2>/dev/null | grep -q "ALL"; | ||
then | ||
SUDO_CHECK_RESULT=0 | ||
else | ||
SUDO_CHECK_RESULT=1 | ||
fi | ||
|
||
# Return 0 only if BOTH group check (if applicable) AND sudo check pass | ||
if [[ $GROUP_CHECK_RESULT -eq 0 && $SUDO_CHECK_RESULT -eq 0 ]]; | ||
then | ||
echo "[i] $USER is a sudoer" | ||
return 0 | ||
elif [[ $GROUP_CHECK_RESULT -eq 1 && $SUDO_CHECK_RESULT -eq 0 ]]; | ||
then | ||
echo "[i] $USER is a sudoer, but is not in 'admin' group" | ||
return 0 | ||
else | ||
echo "[!] $USER is not a sudoer" >&2 | ||
return 1 | ||
fi | ||
} |