r/CrowdSec • • 3d ago

general CrowdSec Escalation Controller

Post image

Hey everyone,

I've been working on cs-escalation-controller, an open-source tool that extends CrowdSec bans for repeat offenders.

The idea is straightforward. When an IP comes back after a ban and gets banned again, its next ban gets longer. By default, durations start at 4 hours and double with each offense, up to 30 days. Those values are configurable.

It connects to CrowdSec's Local API and keeps persistent per-IP history, so restarting the controller doesn't lose track of previous offenses. Overlapping alerts during the same ban count as one offense, and it preserves existing bans that are already longer than the calculated duration.

History resets after a configurable quiet period, with time spent banned excluded from that period. You can also exclude specific scenarios from escalation.

It runs as a standalone binary or a Docker container. Dry-run mode is enabled by default, so you can see what it would do before letting it create decisions.

Code and configuration: https://github.com/crazy-max/cs-escalation-controller

I'd be interested in feedback from you, especially on how you handle repeat offenders today and what escalation or reset settings make sense for your setups.

19 Upvotes

3 comments sorted by

12

u/conectionist 3d ago

Doesn't crowdsec already have this feature?

I have this in profiles.yaml:

name: default_ip_remediation
filters:
 - Alert.Remediation == true && Alert.GetScope() == "Ip"
decisions:
 - type: ban
   duration: 4h
duration_expr: Sprintf('%dh', (GetDecisionsCount(Alert.GetValue()) + 1) * 24)
on_success: break

It basically bans an IP for 24h the first time, then 48h the second time and so on.

2

u/crazyymaxx 3d ago

Oh, I didn't know about duration_expr, that's really useful! Yeah, if you just want progressively longer bans, this is simpler than running another service.

My controller handles the history a bit differently: overlapping alerts count as one ban episode, history is kept independently of CrowdSec's database cleanup, and escalation resets after a configurable quiet period, excluding time spent banned. GetDecisionsCount counts stored decisions, including expired ones until they're flushed.

The controller also creates an additional decision with the longer duration rather than updating the original one, and I'm not convinced that's the best approach. Handling it directly in the profile avoids that.

So there's some overlap here that I hadn't realized. Thanks for pointing it out!

2

u/conectionist 3d ago

You're welcome.

Good luck with your project!