Skip to content

fix: restore fail2ban after firewall start#13364

Open
ssongliu wants to merge 1 commit into
dev-v2from
fix/firewall-restore-fail2ban-state
Open

fix: restore fail2ban after firewall start#13364
ssongliu wants to merge 1 commit into
dev-v2from
fix/firewall-restore-fail2ban-state

Conversation

@ssongliu

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings July 24, 2026 11:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 firewallFail2BanState helper to persist a “needs restore” marker under /run.
  • Removes the direct toolbox.Fail2Ban dependency 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" {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants