Add Sudo Management menu to Settings with passwordless and WSL-Hello-sudo options#444
Add Sudo Management menu to Settings with passwordless and WSL-Hello-sudo options#444Copilot wants to merge 7 commits intodevelopmentfrom
Conversation
Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@copilot I changed my mind. Create a new option in the settings menu for sudo management. It will have two exclusive options:
|
… option Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Restructuring complete in commit e0f5337: Created new "Sudo Management" menu in Settings:
Passwordless sudo implementation:
WSL-Hello-sudo moved from Services:
Mutual exclusivity enforced:
Usage: # Interactive
pengwin-setup → SETTINGS → SUDO → Choose option
# Non-interactive
pengwin-setup install SETTINGS SUDO PASSWORDLESS
pengwin-setup install SETTINGS SUDO WSL-HELLO-SUDO |
|
@copilot after installing and uninstalling the wsl windows hello sudo, i noticed two leftovers /usr/share/pam-configs/wsl-hello Also I noticed that the installation script, creates an uninstall.sh script for uninstalling, it get lost after the cleantmp. Modify the tests to check for the leftover files For your reference here is the installation script, obtained after extrating the release.tar.gz: #!/bin/bash
set -e
prompt_yn () {
read -r -p "$1: " response
if [[ -z "$response" ]]; then
response="$2"
fi
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
true
elif [[ "$response" =~ ^([nN][oO]|[nN])+$ ]]; then
false
else
prompt_yn "$1" "$2"
fi
}
STEPS=6
CURRENT_STEP=0
echo_stage () {
CURRENT_STEP=$(( "$CURRENT_STEP" + 1 ))
echo -e "\e[32m[$CURRENT_STEP/$STEPS] $*\e[m"
}
check_pam_directory () {
if [[ -e "$1" && "$(find "$1" -maxdepth 1 -name 'pam_*.so')" ]]; then
true
else
false
fi
}
if [ "$(whoami)" = "root" ]; then
echo "Please run this as normal user instead of root. Aborting."
exit 1
fi
if [ ! -e build/pam_wsl_hello.so ] || \
[ ! -e build/WindowsHelloBridge.exe ]; then
echo "No built binary was found. Build first before installing."
exit 1
fi
MNT=/mnt/c
if [ -f "/etc/wsl.conf" ]; then
# Get value specified in the form of 'root = /some/path/'
WSL_CONF_ROOT="$( sed -n "s/^[[:space:]]*root[[:space:]]*=\(.*\)/\1/p" < /etc/wsl.conf )"
# Trim path
WSL_CONF_ROOT="$(echo "$WSL_CONF_ROOT" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
if [ -n "$WSL_CONF_ROOT" ]; then
MNT="${WSL_CONF_ROOT}c"
fi
fi
if [[ ! -e "${MNT}" ]]; then
echo "'$MNT' was not found. Please input the mount point of your C drive to invoke Windows commands."
echo -n ": "
read -r MNT
fi
WINUSER=$("${MNT}/Windows/System32/cmd.exe" /C "echo | set /p dummy=%username%") # Hacky. Get Windows's user name without new line
DEF_PAM_WSL_HELLO_WINPATH="${MNT}/Users/$WINUSER/AppData/Local/Programs/wsl-hello-sudo"
OLD_DEF_PAM_WSL_HELLO_WINPATH="${MNT}/Users/$WINUSER/pam_wsl_hello"
echo "Input the install location for Windows Hello authentication component."
echo "It is a Windows .exe file and required to be in a valid Windows directory"
echo -n "Default [${DEF_PAM_WSL_HELLO_WINPATH}] :"
read -r PAM_WSL_HELLO_WINPATH
if [ -z "$PAM_WSL_HELLO_WINPATH" ]; then
PAM_WSL_HELLO_WINPATH=$DEF_PAM_WSL_HELLO_WINPATH
fi
if [ ! -e "$PAM_WSL_HELLO_WINPATH" ]; then
if prompt_yn "'$PAM_WSL_HELLO_WINPATH' does not exist. Create it? [Y/n]" "y"; then
set -x
mkdir -p "$PAM_WSL_HELLO_WINPATH"
fi
fi
MAYBE_OLD_KEY_PATH="$OLD_DEF_PAM_WSL_HELLO_WINPATH/pam_wsl_hello_$USER.pem"
KEY_PATH="$PAM_WSL_HELLO_WINPATH/pam_wsl_hello_$USER.pem"
if [ -f "$MAYBE_OLD_KEY_PATH" ]; then
echo "Migrating existing key identity"
mv "$MAYBE_OLD_KEY_PATH" "$KEY_PATH"
rm -r "$OLD_DEF_PAM_WSL_HELLO_WINPATH"
fi
set +x
echo_stage "Installing Windows component of WSL-Hello-sudo..."
set -x
cp build/WindowsHelloBridge.exe "$PAM_WSL_HELLO_WINPATH/"
chmod +x "$PAM_WSL_HELLO_WINPATH/WindowsHelloBridge.exe"
set +x
echo_stage "Installing PAM module to the Linux system..."
SECURITY_PATH="/lib/x86_64-linux-gnu/security"
if ! check_pam_directory "${SECURITY_PATH}"; then
echo "PAM directory was not found in '/lib/x86_64-linux-gnu/security/'. It looks like you're not running Ubuntu nor Debian."
echo "Checking '/lib/security/'..."
SECURITY_PATH="/lib/security"
while ! check_pam_directory "${SECURITY_PATH}"; do
echo "PAM module directory was not found in '${SECURITY_PATH}'."
echo "Please input the path of the PAM module's directory."
echo -n ": "
read -r SECURITY_PATH
done
fi
echo "Confirmed '${SECURITY_PATH}' as the PAM module directory."
PAM_SO="${SECURITY_PATH}/pam_wsl_hello.so"
if [ -e "${PAM_SO}" ]; then
if prompt_yn "'${PAM_SO}' is in use. Proceed to remove the current one? [Y/n]" "y"; then
set -x
sudo rm "${PAM_SO}"
set +x
else
echo "Installation was cancelled. You can rerun this with install.sh later."
exit
fi
fi
set -x
sudo cp build/pam_wsl_hello.so "${SECURITY_PATH}/"
sudo chown root:root "${SECURITY_PATH}/pam_wsl_hello.so"
sudo chmod 644 "${SECURITY_PATH}/pam_wsl_hello.so"
set +x
echo_stage "Creating pam-config..."
PAM_CONFIG_INSTALLED=no
PAM_CONFIGS_PATH=/usr/share/pam-configs
PAM_CONFIG_NAME=wsl-hello
if [ -d "${PAM_CONFIGS_PATH}" ]; then
PAM_CONFIG=${PAM_CONFIGS_PATH}/${PAM_CONFIG_NAME}
if [ ! -e "${PAM_CONFIG}" ] || prompt_yn "'${PAM_CONFIG}' already exists. Overwrite it? [Y/n]" "y"; then
set -x
sudo cp pam-config "${PAM_CONFIG}"
set +x
PAM_CONFIG_INSTALLED=yes
else
echo "Skipping creation of '${PAM_CONFIG}'..."
fi
else
echo "PAM config directory was not found in '${PAM_CONFIGS_PATH}'. It looks like you're not running Ubuntu nor Debian. You will have to configure pam manually."
fi
echo_stage "Creating the config files of WSL-Hello-sudo..."
set -x
sudo mkdir -p /etc/pam_wsl_hello/
PAM_CONFIG_FILENAME="/etc/pam_wsl_hello/config"
AUTHENTICATOR_PATH="authenticator_path = \"$PAM_WSL_HELLO_WINPATH/WindowsHelloBridge.exe\""
set +x
if [ ! -e "$PAM_CONFIG_FILENAME" ] || prompt_yn "'$PAM_CONFIG_FILENAME' already exists. Overwrite it? [y/N]" "n" ; then
set -x
sudo touch /etc/pam_wsl_hello/config
sudo echo "$AUTHENTICATOR_PATH" | sudo tee "$PAM_CONFIG_FILENAME"
sudo echo "win_mnt = \"$MNT\"" | sudo tee -a /etc/pam_wsl_hello/config
elif grep -q "WindowsHelloAuthenticator" "$PAM_CONFIG_FILENAME" ; then
echo "Migrating PAM config to v2.0"
sudo sed -i "1s;authenticator_path.*;$AUTHENTICATOR_PATH;" "$PAM_CONFIG_FILENAME"
else
echo "Skipping creation of '/etc/pam_wsl_hello/config'..."
fi
set +x
echo "Please authenticate yourself now to create a credential for '$USER' and '$WINUSER' pair."
KEY_ALREADY_EXIST_ERR=171
set -x
pushd "$PAM_WSL_HELLO_WINPATH"
./WindowsHelloBridge.exe creator "pam_wsl_hello_$USER" || test $? = $KEY_ALREADY_EXIST_ERR
sudo mkdir -p /etc/pam_wsl_hello/public_keys
popd
sudo cp "$KEY_PATH" /etc/pam_wsl_hello/public_keys/
set +x
echo_stage "Creating uninstall.sh..."
if [ ! -e "uninstall.sh" ] || prompt_yn "'uninstall.sh' already exists. Overwrite it? [Y/n]" "y" ; then
cat > uninstall.sh << EOS
echo -e "\e[31mNote: Please ensure that config files in /etc/pam.d/ are restored to as they were before WSL-Hello-sudo was installed\e[m"
set -x
sudo rm -rf /etc/pam_wsl_hello
sudo rm "${SECURITY_PATH}/pam_wsl_hello.so"
if [ -e "${PAM_CONFIG}" ]; then
sudo pam-auth-update --remove "${PAM_CONFIG_NAME}"
sudo rm "${PAM_CONFIG}"
fi
rm -rf "${PAM_WSL_HELLO_WINPATH}"
EOS
chmod +x uninstall.sh
else
echo "Skipping creation of 'uninstall.sh'..."
fi
set -x
set +x
echo_stage "Done!"
echo -n "Installation is done! "
if [ "$PAM_CONFIG_INSTALLED" = "yes" ]; then
if prompt_yn "Do you want to enable the pam module now? [y/N]" "n"; then
set -x
sudo pam-auth-update --enable "${PAM_CONFIG_NAME}"
set +x
fi
echo "You can call 'sudo pam-auth-update' to enable/disable WSL Hello authentication."
else
echo "Configure your /etc/pam.d/sudo to make WSL-Hello-sudo effective."
fi
echo "If you want to uninstall WSL-Hello-sudo, run uninstall.sh"
|
…ial uninstall script Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Fixed in commit a0110af: Installer changes:
Uninstaller changes:
Test changes:
The uninstaller now provides complete cleanup with no leftover files. |
|
|
||
| # Remove Windows Hello credential files | ||
| echo "Removing configuration files..." | ||
| if [[ -d "${HOME}/.pam-wsl-hello" ]]; then |
There was a problem hiding this comment.
Changed in commit 5ae9664. Now uses sudo_rem_dir helper function for both /etc/pam_wsl_hello and /usr/local/share/wsl-hello-sudo instead of conditional sudo rm -rf commands.
|
|
||
| # Remove PAM configuration (in case uninstall.sh didn't cover it) | ||
| echo "Removing PAM configuration..." | ||
| if [[ -f /etc/pam.d/sudo ]]; then |
…do uninstaller Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Plan for Adding Sudo Management
pengwin-setup.d/wsl-hello-sudo.shpengwin-setup.d/passwordless-sudo.shpengwin-setup.d/sudo-management.shpengwin-setup.d/settings.shpengwin-setup.d/uninstall.shcompletions/pengwin-setuptests/wsl-hello-sudo.shtests/run_tests.shSummary
Successfully integrated a new Sudo Management menu in the Settings section of pengwin-setup, providing two exclusive authentication methods:
The two options are mutually exclusive - enabling one will prompt to remove the other if installed.
Latest Changes (Use helper functions per @crramirez feedback)
Uninstaller refactoring:
sudo sed -i '/pam_wsl_hello/d'withsudo_clean_filehelper functionsudo rm -rfwithsudo_rem_dirhelper function for directory removalChanges made:
sudo_clean_file "/etc/pam.d/sudo" "pam_wsl_hello"instead of directsedcommandsudo_rem_dir "/etc/pam_wsl_hello"instead of conditionalsudo rm -rfsudo_rem_dir "/usr/local/share/wsl-hello-sudo"instead of conditionalsudo rm -rfFiles Created
Files Modified
Validation Results
✓ All shellcheck validations pass (no errors)
✓ All bash syntax checks pass
✓ Follows Google Shell Style Guide conventions
✓ Follows project patterns and conventions
✓ All scripts are executable
✓ Proper function documentation with Google style
✓ CodeQL security check passed
✓ Mutual exclusivity properly enforced
✓ Proper error handling throughout
✓ Complete cleanup of all leftover files
✓ Uses helper functions from uninstall-common.sh
Usage
Interactive:
pengwin-setup → SETTINGS → SUDO → Choose option - PASSWORDLESS: No password required for sudo - WSL-HELLO-SUDO: Windows Hello authenticationNon-interactive:
Architecture
The two sudo authentication methods are mutually exclusive:
/etc/sudoers.d/passwordless-sudo/etc/pam.d/sudoUninstallation properly uses helper functions:
Uses
sudo_clean_fileto remove PAM configuration linesUses
sudo_rem_dirto remove directoriesUses
sudo_rem_fileto remove filesProvides consistent error messages and better handling
No leftover files remain after uninstallation
Fixes [Feature Request] Add WSL-Hello-sudo Pengwin#670
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.