sosreport / sos

A unified tool for collecting system logs and other debug information
http://sos.rtfd.org
GNU General Public License v2.0
508 stars 542 forks source link

[firewall_tables] fails to collect iptables raw/filter/mangle/nat atble if 'nft' is not installed #2978

Open lathiat opened 2 years ago

lathiat commented 2 years ago

Based on #2724 it started to use nft to determine which tables (raw/filter/mangle/nat) exist and should be exported to avoid loading the relevant kernel module if it's not in use. However if the 'nft' tool is not installed, it fails to collect any of the tables even if they are in use.

The "iptables-save" command seems to successfully avoid loading any kernel module not in use, seems like we would be better off using it and avoiding all the complicated logic? This command is already used in the network namespace plugin also.

pmoravec commented 2 years ago

I guess deleting the

nft_list['status'] == 0 and

in https://github.com/sosreport/sos/blob/main/sos/report/plugins/firewall_tables.py#L80 will resolve this use case, am I right? We need to carefully review the change for possible negative consequences (all the if-then-else clauses is like a minefield walk).

TurboTurtle commented 2 years ago

The "iptables-save" command seems to successfully avoid loading any kernel module not in use, seems like we would be better off using it and avoiding all the complicated logic? This command is already used in the network namespace plugin also.

Actually, if nft is present, then iptables-save will load that kernel module - https://github.com/sosreport/sos/pull/2703, and is why we made some changes to the networking plugin logic around it.

So, we're probably going to unfortunately end up with yet another conditional fork based on the presence of nft.

npinaeva commented 1 year ago

I was affected by this bug too :) I guess updating the condition to if nft_list['status'] != 0 or table in nft_ip_tables['ip']: should do the trick, wdyt @pmoravec ?

pmoravec commented 1 year ago

It is tricky to eval and I am unsure in one situation. Since nft_list['status'] != 0 can have three reasons:

If my "iptables-save would load kmods" understanding is right, then the condition should be if not nft_list['status'] or table in nft_ip_tables['ip']:.

If my understanding is wrong, then Nadia's suggestion seems right to me.

npinaeva commented 1 year ago

We don't even necessarily need to use iptables-save, we can leave the existing collect_iptable usage, but we need to make sure it is called if nft is not installed, or some error happened and nft_ip_tables was not properly filled. My suggestion was more python-based than linux-based, so I definitely trust your opinion more here :)