Documentation
¶
Overview ¶
Package authlimit throttles repeated failed authentications, to slow down guessing of passwords. It is shared by every authentication surface (WebSocket group joins, the recordings pages, the administrative API), so failures on one surface escalate the delay on all of them.
Each failed attempt from an address sleeps for an exponentially growing delay, so a guesser is slowed to a crawl while a user who merely mistyped their password a few times is barely affected — and is cleared immediately once they get in. After banThreshold failures the address is refused outright for banDuration; the last BanWarn attempts before that carry a warning, so a legitimate user is never banned without notice. Every failure is logged with the offending address, so an external tool such as fail2ban can ban persistent guessers at the firewall (see contrib/fail2ban/).
NB: the key is the client's address as the web server resolves it: the connection's remote address, or, behind a proxy named by -trusted-proxy, the address that proxy reports in X-Forwarded-For. Behind a reverse proxy that is not so named, all clients share one key — and a ban then hits everyone behind it.
Index ¶
Constants ¶
const ( // BanWarn is how many attempts before the ban the user should start // being warned. BanWarn = 3 )
Variables ¶
This section is empty.
Functions ¶
func Banned ¶
Banned reports whether key is temporarily banned after too many failed authentications and, if so, for how much longer. Callers should check it before evaluating any credentials.
func Failure ¶
Failure records a failed authentication for key on the given surface and sleeps for an exponentially growing delay. It logs the failure in a fail2ban-friendly format and returns the number of attempts left before the address is temporarily banned (0 meaning it now is).
func HostKey ¶
HostKey reduces a "host:port" remote address (as found in an http.Request's RemoteAddr) to a stable key: the host without the port.
func Reset ¶
func Reset(key string)
Reset clears the throttle for key after a successful authentication.
func SetDisabled ¶
func SetDisabled(v bool)
SetDisabled turns throttling and banning off (or back on). For tests.
Types ¶
This section is empty.