socks5-server icon indicating copy to clipboard operation
socks5-server copied to clipboard

Add fail2ban-friendly auth failure logging and regression test

Open rezdm opened this issue 9 months ago • 0 comments

Closes #90

Summary

This PR improves authentication failure observability and fail2ban integration by adding a stable, parseable auth failure log line with source IP details.

What Changed

  • Added structured auth failure metadata in vendored go-socks5 auth flow (method, username, reason, remote_ip, remote_addr).
  • Added a dedicated warning log line in ServeConn for auth failures:
    • auth_failed remote_ip=... remote_addr=... username=... method=... reason=...
  • Added regression test TestAuthFailureLogsIncludeFail2banFields that performs a real SOCKS5 username/password handshake with invalid credentials and validates:
    • auth response failure (0x01 0x01)
    • presence of auth_failed, remote_ip, username, method, and reason=invalid_credentials in logs
  • Updated Changelog.md under Unreleased.

Example Log

[WARN] socks: auth_failed remote_ip=127.0.0.1 remote_addr="127.0.0.1:47966" username="testuser" method=2 reason=invalid_credentials

Validation

  • GOCACHE=/tmp/go-build-cache go test ./...
  • GOCACHE=/tmp/go-build-cache go vet ./...

rezdm avatar Feb 25 '26 08:02 rezdm