fix: restore fail2ban after firewall start#13364
Open
ssongliu wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts the agent’s firewall operation flow to preserve/restore Fail2Ban behavior around firewalld lifecycle changes by tracking state with a runtime marker and restarting Fail2Ban when appropriate.
Changes:
- Replaces the previous “save banned IPs + re-ban after firewall start/restart” approach with a marker-based “remember before stop / restore after start” flow for
firewalld. - Adds a new
firewallFail2BanStatehelper to persist a “needs restore” marker under/run. - Removes the direct
toolbox.Fail2Bandependency from firewall operations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| agent/app/service/firewall.go | Integrates Fail2Ban state tracking into firewall start/stop flow and removes the previous banned-IP restore logic. |
| agent/app/service/firewall_fail2ban_state.go | Introduces marker-based state tracking to restore Fail2Ban after firewall lifecycle events. |
Comments suppressed due to low confidence (1)
agent/app/service/firewall.go:218
- Fail2Ban restoration only runs after the "start" operation. If the firewall is brought up via "restart" (systemd restart will also start an inactive unit), the restore marker will never be consumed and Fail2Ban won’t be restarted.
if client.Name() == "firewalld" && req.Operation == "start" {
if err := fail2BanState.restoreAfterFirewallStart(); err != nil {
return err
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+22
to
+29
| checkExist: func(serviceName string) (bool, error) { | ||
| exists, _ := controller.CheckExist(serviceName) | ||
| return exists, nil | ||
| }, | ||
| checkActive: func(serviceName string) (bool, error) { | ||
| active, _ := controller.CheckActive(serviceName) | ||
| return active, nil | ||
| }, |
| if req.Operation == "start" || req.Operation == "restart" { | ||
| bannedIPs = loadFail2BanBannedIPs() | ||
| fail2BanState := newFirewallFail2BanState() | ||
| if client.Name() == "firewalld" && req.Operation == "stop" { |
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.
No description provided.