Firewall Bouncer
๐ Documentation๐ Hub๐ฌ Discourse
CrowdSec bouncer written in golang for firewalls.
crowdsec-firewall-bouncer will fetch new and old decisions from a CrowdSec API to add them in a blocklist used by supported firewalls.
Supported firewalls:
- iptables (IPv4 โ๏ธ / IPv6 โ๏ธ )
- nftables (IPv4 โ๏ธ / IPv6 โ๏ธ )
- ipset only (IPv4 โ๏ธ / IPv6 โ๏ธ )
- pf (IPV4 โ๏ธ / IPV6 โ๏ธ )
Installation#
Packages for crowdsec-firewall-bouncer are available on our repositories. You need to pick the package accord to your firewall system :
IPTables#
- Debian/Ubuntu
- RHEL/Centos/Fedora
sudo apt install crowdsec-firewall-bouncer-iptablessudo yum install crowdsec-firewall-bouncer-iptablessudo pkg install crowdsec-firewall-bouncerNFTables#
- Debian/Ubuntu
- RHEL/Centos/Fedora
sudo apt install crowdsec-firewall-bouncer-nftablessudo yum install crowdsec-firewall-bouncer-nftablessudo pkg install crowdsec-firewall-bouncerpf#
- FreeBSD
sudo pkg install crowdsec-firewall-bouncerSee as well Manual Installation documentation below
Configuration#
There are two main usage case around the firewall bouncer :
- managed (default) : cs-firewall-bouncer will create ispet/nft sets, insert the associated firewall rules and manage set's content
- set only : you already have a (complex) firewall setup, cs-firewall-bouncer will only manage the content of existing specified sets
Managed mode : Iptables/ipset or Nftables#
This is the default behaviour
In "managed" mode (mode nftables or iptables), bouncer creates all the needed elements (rules, sets) and insert the appropriate rules in nftables or iptables.
warning
IPSet (when using iptables mode) does not support a timeout greater than 2147483 seconds (about 596 hours). If crowdsec is configured to take decisions longer than that, the bouncer will cap the duration to 2147482 seconds.
Set Only : Iptables/Ipset table#
In iptable set only mode (mode ispet), bouncer only manages the contents of sets designed by blacklists_ipv4 and blacklists_ipv6.
Those sets must exist prior to the bouncer startup, and it is the user's responsability to create the associate iptables rules.
warning
IPSet does not support a timeout greater than 2147483 seconds (about 596 hours). If crowdsec is configured to take decisions longer than that, the bouncer will cap the duration to 2147482 seconds.
Set Only : nftables#
In nftables set only mode (mode nftables with nftables.{ipv4,ipv6}.set-only set to true), bouncer only manages the contents of the sets.
It's the user's responsability to create the associated chains and sets :
table ip crowdsec { set crowdsec-blacklists { type ipv4_addr flags timeout }
chain crowdsec-chain { type filter hook input priority filter; policy accept; ip saddr @crowdsec-blacklists drop }}table ip6 crowdsec6 { set crowdsec6-blacklists { type ipv6_addr flags timeout }
chain crowdsec6-chain { type filter hook input priority filter; policy accept; ip6 saddr @crowdsec6-blacklists drop }}Configuration directives#
mode: can be set toiptables,nftables,ipsetorpfpid_dir: directory to drop pid fileupdate_frequencycontrols how often the bouncer is going to query the local APIdaemonize: for systemd unitlog_mode: can befileorstdoutlog_dir: log directorylog_level: can betrace,debug,info, orerrorlog_compression: compress logs on rotation,trueorfalselog_max_size: maximum file size before rotationlog_max_backups: how many backup log files to keeplog_max_age: oldest backup log file before deletionapi_urlandapi_keycontrol local API parameters.insecure_skip_verify: allow self-signed certificates for LAPI,falseortruedisable_ipv6: disable ipv6 support, defaults tofalsedeny_action: firewall action to apply, defaults toDROP, but can beREJECTdeny_log: if set totrue, enables logging of dropped packets (ie.-j LOG)deny_log_prefix: if logging is true, this sets the log prefix, defaults to "crowdsec: "
Iptables/Ipset specific directives#
iptables_chains: specify a list of chains to insert rules (only relevant iniptablesmode) :blacklists_ipv4andblacklists_ipv6: names of ipv4 and ipv6 sets
iptables_chains: - INPUT# - FORWARD# - DOCKER-USERNftables specific directives#
Nftables mode has its own nftables section, with sub-section of ipv4 and ipv6 :
## nftablesnftables: ipv4: enabled: true set-only: false table: crowdsec chain: crowdsec-chain ipv6: enabled: true set-only: false table: crowdsec6 chain: crowdsec6-chainif set-only is set to true, the bouncer will only manage the set contents.
Manual installation#
Assisted#
First, download the latest crowdsec-firewall-bouncer release.
$ tar xzvf crowdsec-firewall-bouncer.tgz$ sudo ./install.shFrom source#
Run the following commands:
git clone https://github.com/crowdsecurity/cs-firewall-bouncer.gitcd cs-firewall-bouncer/make releasetar xzvf crowdsec-firewall-bouncer.tgzcd crowdsec-firewall-bouncer-v*/sudo ./install.shUpgrade#
If you already have crowdsec-firewall-bouncer installed, please download the latest release and run the following commands:
tar xzvf crowdsec-firewall-bouncer.tgzcd crowdsec-firewall-bouncer-v*/sudo ./upgrade.shConfiguration for manual installation#
To be functional, the crowdsec-firewall-bouncer service must be able to authenticate with the local API.
The install.sh script will take care of it (it will call cscli bouncers add on your behalf).
If it was not the case, the default configuration file is located under : /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
You can then start the service:
sudo systemctl start crowdsec-firewall-bouncerlogs#
logs can be found in /var/log/crowdsec-firewall-bouncer.log
modes#
- mode
nftablesrelies on github.com/google/nftables to create table, chain and set. - mode
iptablesrelies oniptablesandipsetcommands to insertmatch-setdirectives and maintain associated ipsets - mode
ipsetrelies onipsetand only manage contents of the sets (they need to exist at startup and will be flushed rather than created) - mode
pfrelies onpfctlcommand to alter the tables. You are required to create the following tables on yourpf.confconfiguration:
# create crowdsec ipv4 tabletable <crowdsec-blacklists> persist
# create crowdsec ipv6 tabletable <crowdsec6-blacklists> persistYou can refer to step by step instructions of the user tutorial on FreeBSD to setup crowdsec-firewall-bouncer with pf.
ipset#
ipset lists have to exist before crowdsec-firewall-bouncer starts you could create them and add them to your iptables like this:
ipset create crowdsec-blacklists hash:ip timeout 0 maxelem 150000ipset create crowdsec6-blacklists hash:ip timeout 0 family inet6 maxelem 150000iptables -I INPUT 1 -m set --match-set crowdsec-blacklists src -j DROPip6tables -I INPUT 1 -m set --match-set crowdsec6-blacklists src -j DROP