Skip to content

feat: live IP reputation over the HAProxy peers protocol - #88

Draft
fionera wants to merge 6 commits into
masterfrom
agent/reputation-peers
Draft

feat: live IP reputation over the HAProxy peers protocol#88
fionera wants to merge 6 commits into
masterfrom
agent/reputation-peers

Conversation

@fionera

@fionera fionera commented Jul 11, 2026

Copy link
Copy Markdown
Member

Closes #82.

What

  • internal/peerserver: the sending side of the HAProxy peers protocol — handshake handling with validation (503 on peer-name mismatch), table definitions, entry updates with stable per-entry update IDs replayed in teach order on resync, 3s heartbeats, and multi-connection broadcast. Built for meshes where the daemon is not the only peer: entry updates taught by the other peers are parsed and acknowledged, so they treat us as synced instead of re-teaching forever. Per-entry expiries go out as timed updates; deletes are taught as zero-with-bounded-expiry so reconnecting peers converge.
  • internal/reputation: one service, two deployment modes. It polls the CrowdSec LAPI decision stream as a bouncer (ban→silent-drop, captcha→minimum challenge level, unknown types fail closed; per-decision durations honored; range scopes skipped with a warning since stick-tables cannot prefix-match) and refreshes static feeds (Tor exits → challenge, optional banlist → block, Cloudflare CIDRs → map file). Sources are merged before pushing — block beats challenge, longer-lived wins — so one source refreshing never clears another's entries.
  • Embedded mode: a reputation: section in the spop config runs the service in-process, keeping the simple docker setup at HAProxy + one berghain container (+ CrowdSec via the compose overlay).
  • Standalone mode: cmd/feedupdater is a thin flags wrapper around the same service for deployments that isolate or scale the feed daemon.
  • Examples: examples/haproxy/haproxy-reputation.cfg (peers section, reputation stick-tables, silent-drop + min-level policy), examples/crowdsec/ (README, compose overlay, config).
  • Bumps haproxy-go to v0.1.1 for the fixed EntryUpdate.Marshal.

Validation

  • Unit tests: peerserver (push, timed entries, handshake reject, acks, delete convergence), reputation (LAPI stream incl. startup/delta/delete/range-skip, source merge precedence, static feeds), spop config parsing.
  • test/e2e/peers_test.go (runs in the existing e2e job): the daemon + two real HAProxy instances in one peers mesh — entries reach both admin sockets, the 4h decision arrives as a timed update (exp ≈ 4h, not the 24h table default), HAProxy↔HAProxy replication keeps working with the daemon acking in the mesh, deleted decisions zero out everywhere, and a killed+restarted HAProxy resyncs to full state.
  • haproxy -c on the new example config; browser e2e suite still green; merged compose config validated.

fionera added 6 commits July 11, 2026 07:21
Brings the fixed EntryUpdate.Marshal data encoding needed to send
stick-table entry updates over the peers protocol.
Extracted from the reputation prototype and hardened: handshakes are
validated (503 on peer-name mismatch), entry updates taught by other
peers in the mesh are parsed and acknowledged so they consider us
synced, entries carry stable update IDs replayed in teach order on
resync, per-entry expiries go out as timed updates, and deletes are
zeroed with a bounded expiry so reconnecting peers converge.
One service, two deployment modes: it polls the CrowdSec LAPI decision
stream as a bouncer (ban->block, captcha->challenge, per-decision
durations as timed entries, range scopes skipped) and refreshes static
URL feeds (Tor exits) plus CIDR map files. Sources are merged before
pushing — block beats challenge, longer-lived entries win — so one
source refreshing never clears another source's entries.
cmd/feedupdater is a thin flags wrapper around internal/reputation for
deployments that isolate the feed daemon; a reputation: section in the
spop config runs the same service in-process so the simple docker setup
stays HAProxy plus one berghain container.
haproxy-reputation.cfg is a standalone alternative config with the
peers section, reputation stick-tables and the block/min-level policy;
the crowdsec example overlays a CrowdSec container onto the regular
single-container docker setup with the reputation service embedded in
the agent.
Runs the feedupdater with a fake CrowdSec LAPI as one peer among two
real HAProxy instances and asserts via the admin sockets that entries
reach both, per-decision durations arrive as timed updates, deletes
zero out everywhere, HAProxy-to-HAProxy replication keeps working with
the daemon in the mesh, and a restarted instance resyncs.
@fionera
fionera marked this pull request as draft July 11, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IP reputation feed integration (CrowdSec)

1 participant