feat: live IP reputation over the HAProxy peers protocol - #88
Draft
fionera wants to merge 6 commits into
Draft
Conversation
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
marked this pull request as draft
July 11, 2026 15:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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;rangescopes 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.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).cmd/feedupdateris a thin flags wrapper around the same service for deployments that isolate or scale the feed daemon.examples/haproxy/haproxy-reputation.cfg(peers section, reputation stick-tables, silent-drop + min-level policy),examples/crowdsec/(README, compose overlay, config).EntryUpdate.Marshal.Validation
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 -con the new example config; browser e2e suite still green; merged compose config validated.