Skip to content

Commit 5370ec2

Browse files
feat: add nftables to firewall software allow list (ovh#203)
* feat: add nftables to firewall software allow list fixes ovh#191 * fix: enhance 3.5.4.1.1_net_fw_default_policy_drop.sh iptables output check, disable associated test
1 parent 9d3fb18 commit 5370ec2

4 files changed

+37
-20
lines changed

Diff for: bin/hardening/3.5.1.1_enable_firewall.sh

+24-14
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,42 @@ set -u # One variable unset, it's over
1515
# shellcheck disable=2034
1616
HARDENING_LEVEL=2
1717
# shellcheck disable=2034
18-
DESCRIPTION="Ensure firewall is active (iptables is installed, does not check for its configuration)."
18+
DESCRIPTION="Ensure firewall is active (either nftables or iptables is installed, does not check for its configuration)."
1919

2020
# Note: CIS recommends your iptables rules to be persistent.
2121
# Do as you want, but this script does not handle this
22-
# At OVH, we use iptables
2322

24-
PACKAGE='iptables'
23+
PACKAGES='iptables nftables'
2524

2625
# This function will be called if the script status is on enabled / audit mode
2726
audit() {
28-
is_pkg_installed "$PACKAGE"
29-
if [ "$FNRET" != 0 ]; then
30-
crit "$PACKAGE is not installed!"
31-
else
32-
ok "$PACKAGE is installed"
27+
FOUND=false
28+
for PACKAGE in $PACKAGES; do
29+
is_pkg_installed "$PACKAGE"
30+
if [ "$FNRET" = 0 ]; then
31+
ok "$PACKAGE provides firewalling feature"
32+
FOUND=true
33+
fi
34+
done
35+
if [ "$FOUND" = false ]; then
36+
crit "None of the following firewall packages are installed: $PACKAGES"
3337
fi
3438
}
3539

3640
# This function will be called if the script status is on enabled mode
3741
apply() {
38-
is_pkg_installed "$PACKAGE"
39-
if [ "$FNRET" = 0 ]; then
40-
ok "$PACKAGE is installed"
41-
else
42-
crit "$PACKAGE is absent, installing it"
43-
apt_install "$PACKAGE"
42+
for PACKAGE in $PACKAGES; do
43+
is_pkg_installed "$PACKAGE"
44+
if [ "$FNRET" = 0 ]; then
45+
ok "$PACKAGE provides firewalling feature"
46+
FOUND=true
47+
fi
48+
done
49+
if [ "$FOUND" = false ]; then
50+
crit "None of the following firewall packages are installed: $PACKAGES, installing them"
51+
# FIXME : iptables is hardcoded, we will have to change this in the future
52+
# This will install nftables and iptables
53+
apt_install "iptables"
4454
fi
4555
}
4656

Diff for: bin/hardening/3.5.4.1.1_net_fw_default_policy_drop.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ audit() {
4545
crit "Policy set to $actual_policy for chain $chain, should be ${FW_POLICY}."
4646
fi
4747
else
48-
echo "cant find chain $chain"
48+
crit "Unable to find chain $chain"
4949
fi
5050
done
5151
fi

Diff for: tests/hardening/3.5.1.1_enable_firewall.sh

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
# run-shellcheck
33
test_audit() {
44
describe Running on blank host
5-
register_test retvalshouldbe 0
5+
register_test retvalshouldbe 1
66
dismiss_count_for_test
77
# shellcheck disable=2154
88
run blank /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
99

10-
# TODO fill comprehensive tests
10+
describe Correcting situation
11+
apt-get update
12+
apt-get install -y iptables
13+
14+
describe Checking resolved state
15+
register_test retvalshouldbe 0
16+
register_test contain "provides firewalling feature"
17+
run resolved /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
18+
1119
}

Diff for: tests/hardening/3.5.4.1.1_net_fw_default_policy_drop.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ test_audit() {
44
describe Running on blank host
55
register_test retvalshouldbe 0
66
dismiss_count_for_test
7-
# shellcheck disable=2154
8-
run blank /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
9-
7+
# Do not run any check, iptables do not work in a docker
8+
#run blank /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
109
# TODO fill comprehensive tests
1110
}

0 commit comments

Comments
 (0)