[GH-ISSUE #1847] [Feature]: Log authentication failures with the client source IP (for fail2ban / rate limiting) #727

Closed
opened 2026-11-04 01:45:23 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @wszhoho on GitHub (Oct 10, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1847

What do you want to do?

Please log authentication failures (HTTP 401) with the client's source IP address, so that external tools such as fail2ban can detect and ban clients that keep trying wrong API keys against the server.

Background / current behavior

The server protects /v1/* with an API key (api_key in the config, or --api-key / STRATA_API_KEY). When authentication fails, _authorized() in serve/server.py only replies with a 401 JSON body (type authentication_error, message missing or wrong API key) and returns. No log line is written, and crucially no client IP is recorded.

Because there is nothing to match on, a self-hosted deployment cannot use fail2ban (or any IP-based rate limiting) to defend against brute-force attempts on the API key, even though the server is typically exposed on the public internet (e.g. behind a router DNAT to port 8080).

What already works elsewhere / the pattern that would help

llama.cpp's server logs exactly this line on a bad key:

unauthorized: Invalid API Key from <ip>

and a fail2ban filter + nftables jail matches that line to ban the offender. Strata's 401 path currently produces no such log line at all.

Suggested outcome (goal, not a specific implementation)

A single line to stderr on an authentication failure that includes the client IP (the code already has self.client_address[0] available in the handler). Format similar to llama.cpp would let the same fail2ban filter work unchanged for both servers.

Environment

  • Strata v0.1.41
  • 2 × RTX 2080 Ti, 62 GiB RAM, Linux
  • Server runs as a systemd service (non-root), logs land in the systemd journal
  • API used via public endpoint through router DNAT to 127.0.0.1:8080
Originally created by @wszhoho on GitHub (Oct 10, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1847 ## What do you want to do? **Please log authentication failures (HTTP 401) with the client's source IP address**, so that external tools such as fail2ban can detect and ban clients that keep trying wrong API keys against the server. ### Background / current behavior The server protects `/v1/*` with an API key (`api_key` in the config, or `--api-key` / `STRATA_API_KEY`). When authentication fails, `_authorized()` in `serve/server.py` only replies with a 401 JSON body (type `authentication_error`, message `missing or wrong API key`) and returns. **No log line is written, and crucially no client IP is recorded.** Because there is nothing to match on, a self-hosted deployment cannot use `fail2ban` (or any IP-based rate limiting) to defend against brute-force attempts on the API key, even though the server is typically exposed on the public internet (e.g. behind a router DNAT to port 8080). ### What already works elsewhere / the pattern that would help `llama.cpp`'s server logs exactly this line on a bad key: ``` unauthorized: Invalid API Key from <ip> ``` and a fail2ban `filter` + `nftables` jail matches that line to ban the offender. Strata's 401 path currently produces no such log line at all. ### Suggested outcome (goal, not a specific implementation) A single line to `stderr` on an authentication failure that includes the client IP (the code already has `self.client_address[0]` available in the handler). Format similar to llama.cpp would let the same fail2ban filter work unchanged for both servers. ### Environment - Strata v0.1.41 - 2 × RTX 2080 Ti, 62 GiB RAM, Linux - Server runs as a systemd service (non-root), logs land in the systemd journal - API used via public endpoint through router DNAT to `127.0.0.1:8080`
Author
Owner

@Niko1221 commented on GitHub (Oct 13, 2026):

Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.

If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.

<!-- gh-comment-id:6156232447 --> @Niko1221 commented on GitHub (Oct 13, 2026): Thanks for the report. To keep the tracker current we are closing issues older than three days: [0.1.44](https://github.com/Niko1221/Strata/releases/tag/v0.1.44) is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1. If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.
Author
Owner

@wszhoho commented on GitHub (Oct 16, 2026):

Reopening request: this was closed by the stale-issue sweep rather than a fix — I diffed _authorized() between v0.1.41 and v0.1.44.1 and it is byte-for-byte identical, so the silent-401 path described above still produces no log line on current releases.

I've submitted a fix in #2712: one line on the auth-failure branch that logs unauthorized: Invalid API Key from <client ip> to stderr, worded verbatim like llama.cpp's line so an existing fail2ban filter works against both servers unchanged. It applies cleanly to v0.1.44.1 (serve/server.py, _authorized()).

Happy to adjust wording/format or add anything you'd need (e.g. gating it behind a config flag). Thanks!

<!-- gh-comment-id:6206092237 --> @wszhoho commented on GitHub (Oct 16, 2026): Reopening request: this was closed by the stale-issue sweep rather than a fix — I diffed `_authorized()` between v0.1.41 and v0.1.44.1 and it is byte-for-byte identical, so the silent-401 path described above still produces no log line on current releases. I've submitted a fix in **#2712**: one line on the auth-failure branch that logs `unauthorized: Invalid API Key from <client ip>` to stderr, worded verbatim like llama.cpp's line so an existing fail2ban filter works against both servers unchanged. It applies cleanly to v0.1.44.1 (`serve/server.py`, `_authorized()`). Happy to adjust wording/format or add anything you'd need (e.g. gating it behind a config flag). Thanks!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#727
No description provided.