Skip to content

fix(fail2ban): report unsuccessful jail activation - #779

Merged
vladimirrott merged 2 commits into
lacs-project:mainfrom
jdotc1:fix/fail2ban-reload-status-20261111
Nov 15, 2026
Merged

vladimirrott merged 2 commits into
lacs-project:mainfrom
jdotc1:fix/fail2ban-reload-status-20261111

Conversation

@jdotc1

@jdotc1 jdotc1 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Closes #669.

When a jail override is written, a missing fail2ban-client or failed reload currently looks like success even though the protection is not active. This change exits nonzero in both cases, with a clear diagnostic and reload stderr, while preserving the valid override for troubleshooting.

Adds rootless regression tests using a stubbed fail2ban client for missing client, unsuccessful reload, and successful reload.

Validation: bash tests/release/fail2ban-ban.test.sh, bash tests/release/helper-anchoring.test.sh, and bash scripts/check_test_reachability.sh passed.

Signed-off-by: jdotc1 [email protected]

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @jdotc1. You made both "written but not active" paths fail the same way, which is the one decision #669 left open, and you kept the valid override on disk so an operator can still see what was written. Your test drives the real main() with a stubbed subprocess.run, so it needs neither root nor a running fail2ban. I'm approving this at d0a3c17.

The live path: ConfigureFail2banJail runs sudo /usr/lib/sysknife/fail2ban-jail-edit (JAIL_HELPER, crates/sysknife-daemon/src/actions/fail2ban.rs:83), so a nonzero exit from the helper is what the daemon reports as a failed step. Before this change a stopped fail2ban made a High-risk jail change look like it took effect.

I didn't run your branch on my machine. I ran your test in a container with no network, as uid 1000, once at your head and once with each half of the fix taken out:

$ git archive --format=tar p779 | podman run -i --rm --network=none --user 1000:1000 docker.io/library/python:3.12-slim bash -c "$(cat run779.sh)"
[pristine] rc=0
ok: fail2ban jail edits fail visibly when the override cannot become active
mutant A lines changed: 1          # s/if reload.returncode != 0:/if False:/
[mutantA] rc=1
AssertionError: (0, '')
mutant B: die-lines=0              # the missing-client die() replaced by return
[mutantB] rc=1
AssertionError: (0, '')
restored
[pristine-again] rc=0
ok: fail2ban jail edits fail visibly when the override cannot become active

Each mutant fails on the assertion written for it (line 51 for the reload, line 32 for the missing client). shellcheck 0.10.0 is clean on the test file, and the commit carries your sign-off.

Nothing blocks this. As with #778, your workflow runs are waiting for my approval because this is your first contribution, and I'll merge once they're green.

You clearly run fail2ban on machines that take SSH traffic. If you'd like to try SysKnife on one, the read-only side is the place to start: sysknife --dry-run "show the status of the sshd jail" shows the plan and executes nothing. No pressure either way.

@vladimirrott
vladimirrott merged commit 2b70bae into lacs-project:main Nov 15, 2026
14 checks passed
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.

ConfigureFail2banJail exits 0 when fail2ban never loaded the new jail settings

2 participants