feat: Implement authentication rate limiting (fail2ban-like)#155
Merged
feat: Implement authentication rate limiting (fail2ban-like)#155
Conversation
Add AuthRateLimiter with ban support to protect against brute-force attacks: - Track failed authentication attempts per IP address - Automatically ban IPs that exceed max attempts within time window - Configurable max attempts, time window, and ban duration - IP whitelist support for trusted addresses - Automatic cleanup of expired bans and failure records - Background cleanup task running every 60 seconds Configuration options added to SecurityConfig: - auth_window: Time window for counting attempts (default: 300s) - whitelist_ips: IPs exempt from rate limiting Integration with SSH handler: - Check if IP is banned before authentication - Record failures and trigger bans on threshold - Record success to reset failure counter - Logging for ban events Closes #140
- Use configuration values instead of hardcoded values for auth_window and ban_time - Integrate whitelist_ips from configuration with validation and logging - Fix TOCTOU race condition in record_failure by removing entry atomically - Add capacity limit (max_tracked_ips) to prevent memory exhaustion DoS - Use HashSet for whitelist O(1) lookups instead of Vec O(n) - Add auth rate limit config fields to ServerConfig - Propagate security config from ServerFileConfig to ServerConfig - Add test for capacity limit enforcement
- Fix code formatting (cargo fmt) - Update ARCHITECTURE.md with Server Security Module documentation - Update server-configuration.md with auth_window and whitelist_ips options - All 930 tests passing, clippy clean
Member
Author
PR Finalization ReportProject Structure Discovered
ChecklistTests
Documentation
Code Quality
Changes Made
SummaryThe AuthRateLimiter implementation is comprehensive with 13 unit tests covering all major functionality. The code follows Rust best practices with proper async/await patterns, thread-safe data structures, and memory-safe design with capacity limits. Documentation has been updated to reflect the new security features. |
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
AuthRateLimiterwith ban support to protect against brute-force attacksChanges
New Files
src/server/security/mod.rs- Security module rootsrc/server/security/rate_limit.rs- AuthRateLimiter implementation with 12 unit testsModified Files
src/server/config/types.rs- Addauth_windowandwhitelist_ipsto SecurityConfigsrc/server/handler.rs- Integrate AuthRateLimiter with auth methodssrc/server/mod.rs- Add security module and background cleanup taskFeatures
Configuration
Test Plan
Closes #140