-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Configurable detection thresholds #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add detection threshold fields to SecurityConfig (detection_window, not_found_threshold, auth_failure_threshold, unique_paths_threshold, repeated_hits_threshold) - Update API handler to accept and persist new threshold settings - Apply thresholds to detector on startup and settings update - Add SetDetectorThresholds method to security manager Signed-off-by: nfebe <fenn25.fn@gmail.com>
Move GET /security/blocked-ips from protected routes to public routes so nginx Lua can fetch the blocked IPs list without authentication.
Code Review Summary✨ This pull request significantly enhances the security module by introducing an internal API token for secure communication between Nginx and the agent, and by adding more granular security detection thresholds. These changes improve both the security posture and the configurability of the agent's defense mechanisms. 🚀 Key Improvements
💡 Minor Suggestions
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review complete. No specific code suggestions were generated. See the overview comment for a summary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review complete. See the overview comment for a summary.
| if req.DetectionWindow != "" { | ||
| if d, err := time.ParseDuration(req.DetectionWindow); err == nil { | ||
| s.config.Security.DetectionWindow = d | ||
| updatedFields = append(updatedFields, "detection_window") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistent with previous duration parsing suggestions, explicitly handle errors for DetectionWindow to provide clear feedback to the API consumer.
| if req.DetectionWindow != "" { | |
| if d, err := time.ParseDuration(req.DetectionWindow); err == nil { | |
| s.config.Security.DetectionWindow = d | |
| updatedFields = append(updatedFields, "detection_window") | |
| } | |
| if req.DetectionWindow != "" { | |
| d, err := time.ParseDuration(req.DetectionWindow) | |
| if err != nil { | |
| c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid detection_window duration format"}) | |
| return | |
| } | |
| s.config.Security.DetectionWindow = d | |
| updatedFields = append(updatedFields, "detection_window") | |
| } |
Add secure internal endpoint for nginx to fetch blocked IPs without requiring user authentication credentials. - Add InternalAPIToken to SecurityConfig, auto-generated if empty - Create /_internal/blocked-ips endpoint with X-Internal-Token validation - Update Lua templates to include token in requests - Inject token into security.lua during template generation Signed-off-by: nfebe <fenn25.fn@gmail.com>
c1566be to
fd179b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review complete. See the overview comment for a summary.
| securityManager.SetDetectorThresholds( | ||
| cfg.Security.RateThreshold, | ||
| cfg.Security.NotFoundThreshold, | ||
| cfg.Security.AuthFailureThreshold, | ||
| cfg.Security.UniquePathsThreshold, | ||
| cfg.Security.RepeatedHitsThreshold, | ||
| cfg.Security.DetectionWindow, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SetDetectorThresholds call here correctly initializes the security manager on startup. However, the exact same call is also made in updateSecuritySettings. While not strictly an error, it's slightly redundant. Consider if the initial setup should just apply default values (or values from the config file at startup) and the API handler should be the sole source of runtime updates. If the manager is re-initialized or config reloaded without an API call, this is necessary. Current approach is defensive.
| securityManager.SetDetectorThresholds( | |
| cfg.Security.RateThreshold, | |
| cfg.Security.NotFoundThreshold, | |
| cfg.Security.AuthFailureThreshold, | |
| cfg.Security.UniquePathsThreshold, | |
| cfg.Security.RepeatedHitsThreshold, | |
| cfg.Security.DetectionWindow, | |
| ) | |
| // Thresholds are applied dynamically via updateSecuritySettings, ensuring consistency. | |
| // Initial values are sourced directly from config.Security. |
No description provided.