-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Problem
Currently, bssh cannot automatically respond to sudo password prompts when executing commands that require sudo privileges across multiple cluster nodes. Users must resort to workarounds such as:
- Configuring NOPASSWD in sudoers
- Using
echo password | sudo -Swhich exposes passwords in shell history - Manual password entry per node (not practical for parallel execution)
This limitation makes it difficult to perform automated administrative tasks like system updates, service restarts, or configuration changes across clusters that require sudo authentication.
Proposed Solution
Add a --sudo-password (or -S) flag that:
- Prompts for sudo password securely (no echo in terminal)
- Detects sudo password prompts from command output
- Automatically sends the password to all nodes when sudo prompts are detected
- Works seamlessly with parallel execution across multiple nodes
Implementation Details
CLI Changes
- Add
--sudo-passwordflag to CLI (boolean) - When flag is present, securely prompt for password before command execution
- Support environment variable
BSSH_SUDO_PASSWORDas alternative input method
Core Logic
-
Password Input (in
src/cli.rs):- Use
rpasswordcrate for secure password input (no terminal echo) - Validate password is provided before execution begins
- Use
-
Prompt Detection (in
src/ssh/client/command.rs):- Monitor SSH channel output for sudo password prompts:
[sudo] password for {user}:Password:{user}'s password:
- Pattern matching should be case-insensitive and handle variations
- Monitor SSH channel output for sudo password prompts:
-
Password Injection (in
src/executor/parallel.rs):- When sudo prompt detected, write password + newline to stdin
- Handle timeout if prompt doesn't appear within reasonable time
- Clear password from memory after use (use
zeroizecrate)
-
Error Handling:
- Detect "incorrect password" responses
- Provide clear error messages per node
- Continue execution on other nodes if one fails authentication
Usage Examples
# Interactive password prompt
bssh -C production --sudo-password "sudo apt update && sudo apt upgrade -y"
Enter sudo password: ******
# Using environment variable (not recommended for production)
export BSSH_SUDO_PASSWORD='mypassword'
bssh -C production --sudo-password "sudo systemctl restart nginx"
# Combined with other options
bssh -C staging -i ~/.ssh/key --sudo-password "sudo reboot"
# With TUI mode
bssh -C production --sudo-password "sudo tail -f /var/log/syslog"Security Considerations
Must implement:
- ✅ Zero-copy password handling with
zeroizecrate - ✅ Never log or print sudo password
- ✅ Clear password from memory immediately after use
- ✅ Warn users about environment variable security risks in documentation
- ✅ No password in command history (prompt-based input)
Documentation requirements:
- Security best practices for sudo password usage
- Recommendation to use NOPASSWD sudoers when possible
- Warning about
BSSH_SUDO_PASSWORDenvironment variable risks - Comparison with alternative approaches
Files to Modify
src/
├── cli.rs # Add --sudo-password flag
├── commands/exec.rs # Handle sudo password parameter
├── executor/parallel.rs # Pass password to execution logic
└── ssh/
├── client/
│ └── command.rs # Detect sudo prompts, inject password
└── tokio_client/
└── channel_manager.rs # Low-level stdin writing
Cargo.toml # Add dependencies: rpassword, zeroize
README.md # Document new feature
ARCHITECTURE.md # Document implementation approach
Dependencies to Add
[dependencies]
rpassword = "7.4" # Secure password input
zeroize = "1.8" # Secure password clearingTesting Plan
-
Unit Tests:
- Sudo prompt pattern matching
- Password injection logic
- Error handling for incorrect passwords
-
Integration Tests:
- Execute sudo command with correct password
- Handle incorrect password gracefully
- Multi-node parallel execution
- Timeout scenarios
-
Manual Testing Scenarios:
- Single node sudo command
- Multi-node cluster update
- Interactive mode with sudo
- Various sudo prompt formats
- Password rejection handling
Related Issues/PRs
- Related to authentication improvements
- Complements existing password authentication (
--passwordflag) - Part of broader automation capabilities
Priority
Medium - This is a quality-of-life improvement that makes cluster administration significantly easier, though workarounds exist.
Additional Notes
- Consider adding
--sudo-userflag forsudo -uscenarios in future - May want to support different sudo prompt patterns per cluster in config file
- Could extend to support
doas(OpenBSD sudo alternative) in future