I finally got the Crowdsec bouncer running on my OpenWrt router.
- Local Api is running on a different device, not the router itself
- Blocking only applies to WAN interface
This is a very lightweight implementation. Installing the crowdsec-openwrt-bouncer package ends with an error due to missing cscli in the package. This can be ignored, it will be removed in a newer version.
After install, I edited the /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
mode: "ipset"
pid_dir: /var/run/
update_frequency: 10s
daemonize: true
log_mode: file
log_dir: /var/log/
log_level: info
api_url: http://cs-lapi:8014/
api_key: ***********************************
disable_ipv6: false
deny_action: DROP
deny_log: true
supported_decisions_types:
- ban
#to change log prefix
#deny_log_prefix: "crowdsec: "
#to change the blacklists name
#blacklists_ipv4: crowdsec-blacklists
#blacklists_ipv6: crowdsec6-blacklists
#if present, insert rule in those chains
iptables_chains:
# - INPUT
# - FORWARD
# - DOCKER-USER
Disabling the entries for the iptables_chains makes it neccessary to create the rules manually, so I created the following in Firewall Custom Rules:
# Crowdsec Bouncer:
ipset create crowdsec-blacklists hash:ip timeout 0 maxelem 150000
ipset create crowdsec6-blacklists hash:ip timeout 0 family inet6 maxelem 150000
iptables -N crowdsec_bouncer
iptables -A crowdsec_bouncer -m hashlimit --hashlimit-name CROWDSEC --hashlimit-upto 1/hour --hashlimit-burst 1 --hashlimit-mode srcip -j LOG --log-level info --log-prefix '** crowdsec match: '
iptables -A crowdsec_bouncer -j DROP
iptables -I FORWARD 4 -i wan -m set --match-set crowdsec-blacklists src -j crowdsec_bouncer
ip6tables -N crowdsec_bouncer
ip6tables -A crowdsec_bouncer -m hashlimit --hashlimit-name CROWDSEC --hashlimit-upto 1/hour --hashlimit-burst 1 --hashlimit-mode srcip -j LOG --log-level info --log-prefix '** crowdsec match: '
ip6tables -A crowdsec_bouncer -j DROP
ip6tables -I FORWARD 4 -i wan -m set --match-set crowdsec6-blacklists src -j crowdsec_bouncer
That’s it.