NethServer / dev

NethServer issue tracker
https://github.com/NethServer/dev/issues
63 stars 20 forks source link

Crowdsec ipset rules do not survive a firewalld reload #6900

Closed stephdl closed 2 months ago

stephdl commented 3 months ago

Steps to reproduce

Chain FORWARD (policy ACCEPT) target prot opt source destination

Chain OUTPUT (policy ACCEPT) target prot opt source destination

[root@R1-pve ~]# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination
DROP all -- anywhere anywhere match-set crowdsec-blacklists src

Chain FORWARD (policy ACCEPT) target prot opt source destination

Chain OUTPUT (policy ACCEPT) target prot opt source destination


reload the firewall like agent.add_public_service after it has added opened services 

firewall-cmd --reload

**Expected behavior**

I expect that my sets are loaded

**Actual behavior**

The sets are not loaded anymore and obviously crwdsec can ban, the drop is not honored 

[root@R1-pve ~]# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination

Chain FORWARD (policy ACCEPT) target prot opt source destination

Chain OUTPUT (policy ACCEPT) target prot opt source destination

[root@R1-pve ~]# ip6tables -L Chain INPUT (policy ACCEPT) target prot opt source destination

Chain FORWARD (policy ACCEPT) target prot opt source destination

Chain OUTPUT (policy ACCEPT) target prot opt source destination



however if I restart  crowdsec-firewall-bouncer.service the sets are back

`systemctl restart  crowdsec-firewall-bouncer.service`

I tried to make permanent the set to the drop zone of firewalld or with also a rich-rule of the public zone but we face to a strange behavior with two kinds of sets, crowdset wants to use the set that you can see with `ipset -L -n` and since I want to make `permanent` the set to firewalld, it looks like there is a conflict

**Components**

crowdsec 1.0.6
stephdl commented 3 months ago

QA

Install crowdsec ghcr.io/nethserver/crowdsec:1.0.7-dev.3

Now the test is really fun, we run the bouncer inside a container, however the test must be done on debian and rocky9

As a side note we do not remove permanent rules of firewalld nor remove deb and rpm of crowdsec-firewall-bouncer-iptables, we just stop and disable it

test case 1

test case 2

mrmarkuz commented 3 months ago

Test case 1: OK

Test case 2: NOK

On a single Rocky node it works. On a Debian cluster node after a firewall-cmd --reload the rules aren't there anymore:

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
DavidePrincipi commented 3 months ago

QA note

In some Debian installations (i.e. Digital Ocean hosting) the nft command is not installed.

apt install nftables
DavidePrincipi commented 2 months ago

In testing crowdsec 1.0.7-dev.4

DavidePrincipi commented 2 months ago

Test case

Repeat test cases 1 and 2. Notice that

  1. new testing version 1.0.7-dev.4

  2. the cscli command was moved into the module environment. Invocation becomes for instance:

    runagent -m crowdsec1 cscli ...

  3. the bouncer service name is now crowdsec1-firewall-bouncer.service (notice the MODULE_ID is used as service name prefix)

    Image

nrauso commented 2 months ago

on Rocky Linux:

On Debian:

Note for Debian: used DO VPS so I needed to install nftables tool.

DavidePrincipi commented 2 months ago

VERIFIED

Verified additional fix, and test case https://community.nethserver.org/t/ns8-crowdsec-limited-domain-levels-in-allow-list/23301/7

DavidePrincipi commented 2 months ago

Released in https://github.com/NethServer/ns8-crowdsec/releases/tag/1.0.7