feat: Implement PTY/shell session support for server (#129)#153
Merged
feat: Implement PTY/shell session support for server (#129)#153
Conversation
Add Unix PTY handling for interactive shell sessions in bssh-server: - Create pty.rs module for PTY master/slave pair management with async I/O - Create shell.rs module for shell process spawning and I/O forwarding - Implement shell_request handler to start interactive shell sessions - Implement window_change_request handler for terminal resizing - Update data handler to forward SSH data to active shell sessions - Add shell session state tracking to ChannelState - Enable nix crate 'term' and 'fs' features for PTY operations
Member
Author
Security & Performance ReviewAnalysis Summary
Prioritized Fix RoadmapCRITICAL
HIGH
MEDIUM
LOW
Progress Log
Manual Review Required
|
Priority: CRITICAL/MEDIUM Issues addressed: - Fixed file descriptor leak via mem::forget by using dup() for each stdio fd - Added shell path validation before spawning process - Added bounds checking for window size dimensions (clamp to u16::MAX) - Improved error context for TIOCSWINSZ ioctl failures - Fixed clippy warning for const assertions in tests Review-Iteration: 1
Member
Author
Security & Performance Review - UpdateAnalysis Summary
Fixes Applied (commit
|
Member
Author
Security & Performance Review - CompleteFinal Summary
Status: Review CompleteFixed Issues (commit
|
| Severity | Issue | Status |
|---|---|---|
| CRITICAL | File descriptor leak via mem::forget(slave_file) |
Fixed - Now uses dup() for separate fds |
| MEDIUM | Integer truncation in window size (u32 to u16) | Fixed - Values clamped to u16::MAX |
| MEDIUM | Improved ioctl error context | Fixed - Added operation name to error |
| MEDIUM | Clippy warning for const assertions | Fixed - Uses const { assert!(..) } |
| HIGH | Shell path not validated | Fixed - Added existence check |
Remaining Items (Design Decisions Required)
| Severity | Issue | Recommendation |
|---|---|---|
| HIGH | Missing uid/gid privilege drop | Design decision needed: The shell runs as the server's user. For multi-user servers, consider adding optional setuid/setgid in pre_exec. Document as limitation or add config option. |
| LOW | Hardcoded PATH | Consider making configurable for production deployments |
Test Results
test result: ok. 156 passed; 0 failed; 0 ignored
Code Quality
- Library builds successfully
- All server module tests pass
- PTY module tests: 8 passed (including new overflow clamping test)
- Shell module tests: 1 passed
Security Analysis Summary
What the PR does well:
- Uses
setsid()to create a new session (prevents terminal hijacking) - Uses
TIOCSCTTYto properly set controlling terminal - Clears environment before setting up shell environment
- Uses
kill_on_drop(true)for proper process cleanup - Handles shutdown signals properly via oneshot channel
- Has proper Drop implementation to clean up resources
Areas addressed by this review:
- Fixed unsafe fd handling that could lead to double-close or leaks
- Added shell existence validation before execution
- Added bounds checking for terminal dimensions
Areas requiring team discussion:
- Privilege separation model (setuid/setgid)
- Shell whitelist/validation beyond existence check
- Environment variable configuration
Review Status: Complete. Recommend merge after team confirms privilege separation design.
- Add unit tests for PTY configuration, winsize, and boundary values - Add unit tests for PTY master operations (resize, config, path) - Add tests for shell session structures and validation - Update ARCHITECTURE.md with PTY/shell module documentation - Update server-configuration.md with shell session architecture
Member
Author
PR Finalization ReportProject Structure Discovered
ChecklistTests
Documentation
Code Quality
Changes Made
Notes
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
Key Features
Platform
Test Plan
Closes #129