Repository navigation
fix(fail2ban): report unsuccessful jail activation - #779
Conversation
Signed-off-by: jdotc1 <[email protected]>
vladimirrott
left a comment
There was a problem hiding this comment.
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.
Closes #669.
When a jail override is written, a missing
fail2ban-clientor 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, andbash scripts/check_test_reachability.shpassed.Signed-off-by: jdotc1 [email protected]