diff man/botblockd.8 @ 0:9f8d79c98fd2 0.4.0

initial public release
author Arkadiusz Juszczyk <ark@wobblyhead.net>
date 2026-10-26 11:29 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/man/botblockd.8	Mon Oct 26 11:29:10 2026 +0100
@@ -0,0 +1,268 @@
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\" Copyright (c) 2026 Arkadiusz Juszczyk <ark@wobblyhead.net>
+.\"
+.Dd October 25, 2026
+.Dt BOTBLOCKD 8
+.Os
+.Sh NAME
+.Nm botblockd
+.Nd nginx-to-pf bot blocker
+.Sh SYNOPSIS
+.Nm
+.Cm run
+.Op Fl f
+.Op Fl c Ar config
+.Op Fl p Ar pidfile
+.Nm
+.Cm check
+.Op Fl c Ar config
+.Nm
+.Cm list
+.Nm
+.Cm unblock
+.Ar address ...
+.Nm
+.Cm unblock Fl a
+.Nm
+.Cm help
+.Sh DESCRIPTION
+.Nm
+tails an nginx access log via
+.Xr kqueue 2 ,
+counts HTTP error responses per source IP, and blocks persistently
+abusive clients at the host
+.Xr pf 4
+firewall by adding them to the
+.Sy botblock
+table.
+It reads the standard combined log format, accepting both the raw form
+and the form produced when
+.Xr syslogd 8
+aggregates the log with a prepended syslog header.
+The log is followed across rotation and truncation.
+Only IPv4 is handled.
+.Pp
+Each source that produces an error response becomes a suspect.
+A periodic sweep evaluates suspects and moves them through a small state
+machine.
+An inspection window of
+.Va INSPECT_SECONDS
+seconds or
+.Va INSPECT_REQUEST_COUNT
+requests, whichever comes first, decides whether the error balance
+warrants a block.
+A blocked IP is released after
+.Va BLOCK_SECONDS
+seconds into a probation period, during which renewed bad behaviour
+re-blocks it.
+Suspects that cause no further errors are dropped after
+.Va COOLDOWN_SECONDS
+seconds.
+Successful requests count against errors.
+A client is blocked only when its errors reach
+.Va MIN_ERROR_COUNT
+and outnumber its successful requests.
+An occasional error among normal requests does not block a client, and a
+client can clear itself by behaving.
+.Pp
+A whitelist file protects operators.
+It lists addresses that are never blocked.
+.Pp
+.Nm
+logs to
+.Xr syslog 3
+under the
+.Dv LOG_DAEMON
+facility.
+The
+.Xr pf 4
+.Sy botblock
+table must exist and be referenced by a block rule in the host ruleset;
+a sample is installed under
+.Pa share/examples/botblockd .
+.Nm
+treats the table as its own and flushes it at startup and on exit.
+When an address is blocked, its existing
+.Xr pf 4
+states are killed as well, so connections it has already established
+are cut off.
+.Sh COMMANDS
+.Bl -tag -width "unblock"
+.It Cm run
+Run the daemon.
+It detaches into the background unless
+.Fl f
+is given, and writes a pidfile.
+The configuration, the whitelist, the input log and the
+.Sy botblock
+table are checked before detaching, so a problem with any of them is
+reported in the exit status.
+.It Cm check
+Parse the configuration and whitelist, open the input log, verify that
+the
+.Sy botblock
+table is loaded in
+.Xr pf 4 ,
+report the result, and exit.
+The table is only read, never modified.
+Run this as root before sending
+.Dv SIGHUP :
+a failed reload is reported only in the system log.
+.It Cm list
+Print the addresses currently in the
+.Sy botblock
+table.
+.It Cm unblock Ar address ...
+Remove one or more addresses from the
+.Sy botblock
+table.
+.It Cm unblock Fl a
+Remove all addresses from the table.
+.It Cm help
+Print the version and a usage summary.
+.El
+.Sh OPTIONS
+.Bl -tag -width Fl
+.It Fl c Ar config
+Read configuration from
+.Ar config
+instead of the default.
+With
+.Cm run ,
+the path must be absolute, so that a reload finds the file after the
+daemon has changed to the root directory.
+.It Fl f
+Run in the foreground without detaching, mirroring log output to
+standard error.
+.It Fl p Ar pidfile
+Write the pidfile to
+.Ar pidfile
+instead of the default.
+.El
+.Sh CONFIGURATION
+The configuration file holds
+.Sy KEY=VALUE
+lines.
+Blank lines and lines whose first non-blank character is
+.Ql #
+are ignored.
+Unset keys keep their compiled-in defaults, and if the file does not
+exist, all defaults apply.
+A key that is present must have a valid value.
+Numbers must be positive integers, and paths must be absolute.
+A malformed value, an unknown key or a line that is not
+.Sy KEY=VALUE
+is an error rather than ignored: at startup
+.Nm
+exits, and a reload is rejected.
+.Bl -tag -width "INSPECT_REQUEST_COUNT"
+.It Va INSPECT_SECONDS
+Length of the inspection window in seconds.
+The default is 30.
+.It Va INSPECT_REQUEST_COUNT
+Request count that also closes the inspection window.
+The default is 20.
+.It Va MIN_ERROR_COUNT
+Minimum number of errors a suspect must have caused before it is
+first blocked.
+Errors are counted from the first one and are not reset when the
+inspection window closes.
+The default is 2.
+.It Va ERROR_STATUSES
+Which HTTP status codes count as errors, as a comma-separated list of
+single codes and
+.Ar lo Ns - Ns Ar hi
+ranges, for example
+.Ql 401,403,404,444
+or
+.Ql 400-599 .
+Any status not listed counts as a successful request.
+The default is
+.Ql 400-599 .
+.It Va COOLDOWN_SECONDS
+A suspect that has caused no error for this many seconds is
+forgotten; successful requests do not keep it.
+An address on probation is forgotten this many seconds after its
+block was lifted.
+The default is 600.
+.It Va BLOCK_SECONDS
+How long, in seconds, an address stays blocked before entering probation.
+The default is 600.
+.It Va INPUT_LOG
+Path of the nginx access log to tail.
+A reload that changes it is rejected; the change takes effect when
+the daemon is restarted.
+The default is
+.Pa /var/log/nginx/access.log .
+.It Va WHITELIST_FILE
+Path of the whitelist, one IPv4 address or CIDR subnet per line.
+A bare address is treated as a single host
+.Pq Li /32 ;
+a prefix length must be between 1 and 32, as
+.Li /0
+would whitelist every address.
+Host bits below the prefix are accepted and masked off, so
+.Li 10.0.0.5/24
+is the same as
+.Li 10.0.0.0/24 .
+Blanks around an entry, blank lines and lines whose first non-blank
+character is
+.Ql #
+are ignored; any other line that does not parse fails startup or
+reload, just like a malformed configuration value.
+A missing file leaves the whitelist empty; a file that exists but
+cannot be read is an error.
+The default is
+.Pa /usr/local/etc/botblockd/whitelist .
+.El
+.Sh FILES
+.Bl -tag -width "/usr/local/etc/botblockd/whitelist"
+.It Pa /usr/local/etc/botblockd/conf
+Configuration file
+.It Pa /usr/local/etc/botblockd/whitelist
+IP whitelist
+.It Pa /usr/local/etc/rc.d/botblockd
+.Xr rc 8
+Startup script
+.It Pa /var/run/botblockd.pid
+Default pidfile
+.El
+.Sh SIGNALS
+.Bl -tag -width SIGTERM
+.It Dv SIGTERM , SIGINT
+Graceful shutdown; flush the
+.Xr pf 4
+table before exiting.
+.It Dv SIGHUP
+Reload the configuration file and whitelist.
+If either has an error, or
+.Va INPUT_LOG
+has changed, the reload is rejected: the error is logged and the
+previous configuration and whitelist stay in effect.
+.El
+.Sh EXIT STATUS
+.Cm run
+exits 0 when stopped by a signal and 1 on any error, at startup or
+while running.
+The other commands exit 0 on success and 1 on failure.
+.Sh SEE ALSO
+.Xr kqueue 2 ,
+.Xr syslog 3 ,
+.Xr pf 4 ,
+.Xr pfctl 8 ,
+.Xr rc 8 ,
+.Xr syslogd 8
+.Sh AUTHORS
+.An Arkadiusz Juszczyk Aq Mt ark@wobblyhead.net
+.Sh CAVEATS
+Only IPv4 is handled.
+Log lines from IPv6 clients are skipped, so these clients are never
+blocked.
+.Pp
+.Cm unblock
+works on the
+.Xr pf 4
+table only and does not inform a running daemon.
+The daemon still counts a manually unblocked address as blocked until
+its block interval ends, so the address is not blocked again before
+then, whatever errors it causes.