feat: Implement session management and limits (#142)#159
Merged
Conversation
- Add SessionConfig for configurable session limits: - max_sessions_per_user: Limit concurrent sessions per user - max_total_sessions: Limit total concurrent sessions - idle_timeout: Detect idle sessions - session_timeout: Optional maximum session duration - Enhance SessionManager with per-user tracking: - user_sessions HashMap for tracking sessions by username - authenticate_session() method with per-user limit enforcement - touch() method for updating last_activity timestamp - get_idle_sessions() for timeout detection - get_stats() for session statistics - list_sessions() / list_user_sessions() for admin operations - kill_session() / kill_user_sessions() for forced disconnect - Add SessionError and SessionStats types - Enhance SessionInfo with activity tracking: - last_activity field for idle detection - idle_secs() and is_idle() methods - is_expired() for session timeout checks - Integrate per-user limits in SSH handler: - Check per-user session limits during authentication - Reject authentication if user has too many sessions - Update SessionManager's user tracking on auth success - Add session config to ServerConfig: - max_sessions_per_user field - session_timeout_secs field - session_config() helper method - Comprehensive test coverage (30+ new tests)
- Fix HIGH: Race condition in Drop - add retry mechanism with exponential backoff to ensure session cleanup under lock contention - Fix MEDIUM: Add input validation for SessionConfig - clamp max_sessions_per_user and max_total_sessions to minimum of 1 to prevent misconfiguration that could deny all connections - Add validate() method to SessionConfig for detecting potentially problematic configuration combinations - Fix MEDIUM: Atomic ordering - change SessionId counter from Ordering::Relaxed to Ordering::SeqCst for stricter ordering guarantees and consistent logging - Add tests for config validation and clamping behavior
- Fix code formatting issues (handler.rs, session.rs) - Fix unused variable warning in test (s2 -> _s2) - Add comprehensive session management documentation - Document session_timeout configuration option - Add session management API examples
Member
Author
PR Finalization ReportProject Structure Discovered
ChecklistTests
Documentation
Code Quality
Changes Made
VerificationAll checks passing:
|
Merge origin/main into feat/session-management-142. Both branches added new builder methods - kept all three: - scp_enabled (from main) - max_sessions_per_user (from current branch) - session_timeout_secs (from current branch)
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
Implements session management features including per-user session limits, idle timeout detection, and session tracking.
Changes
SessionConfig: Configurable session limits
max_sessions_per_user: Limit concurrent sessions per user (default: 10)max_total_sessions: Limit total concurrent sessions (default: 1000)idle_timeout: Duration for idle detection (default: 1 hour)session_timeout: Optional maximum session durationSessionManager enhancements:
user_sessionsHashMapauthenticate_session()with per-user limit enforcementtouch()for updating last activity timestampget_idle_sessions()for timeout detectionSessionInfo activity tracking:
last_activityfield for idle detectionidle_secs(),is_idle(),is_expired()methodsSSH handler integration:
Configuration:
max_sessions_per_user,session_timeout_secssession_config()helper for creating SessionConfigTest plan
Closes #142