From 49ea644c88772fa1b5b7926c7cf2e9a2f3217657 Mon Sep 17 00:00:00 2001 From: Edgar Aguilar Date: Mon, 22 May 2023 16:14:15 -0600 Subject: [PATCH 1/4] Update sysctl template OVAL There are configurations set by packages in /usr/lib, so it is possible to find there the expected configuration, but it is not recommended to modify those files in case of a non compliant configuration. So modified OVAL to check those files in a way that not touching them would fix any non compliant scenario. This means that the rule can pass if the expected conf is included in a file in /usr/lib. But also if there is a non compliant value there, and it is overwritten by a configuration in a different file. Signed-off-by: Edgar Aguilar --- shared/templates/sysctl/oval.template | 89 ++++++++------------------- 1 file changed, 26 insertions(+), 63 deletions(-) diff --git a/shared/templates/sysctl/oval.template b/shared/templates/sysctl/oval.template index 3fe6de1c185..39bd45ebfab 100644 --- a/shared/templates/sysctl/oval.template +++ b/shared/templates/sysctl/oval.template @@ -122,81 +122,54 @@ {{{ oval_metadata("The kernel '" + SYSCTLVAR + "' parameter should be set to " + COMMENT_VALUE + " in the system configuration.") }}} -{{% if MISSING_PARAMETER_PASS == "true" %}} -{{% endif %}} + + - - - - - -{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9"] %}} - -{{% endif %}} - - - + + {{% if MISSING_PARAMETER_PASS == "true" %}} + + {{% else %}} + + {{% endif %}} -{{% if MISSING_PARAMETER_PASS == "true" %}} - -{{% endif %}} - - + - - {{{ state_static_sysctld("sysctl") }}} + {{{ state_static_sysctld("user") }}} - - {{{ state_static_sysctld("etc_sysctld") }}} + {{{ state_static_sysctld("usr_lib_sysctld") }}} - - {{{ state_static_sysctld("run_sysctld") }}} - - -{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9"] %}} - {{{ state_static_sysctld("usr_lib_sysctld") }}} -{{% endif %}} - - - {{{ state_static_sysctld("usr_local_lib_sysctld") }}} - - - - - - + object_static_etc_sysctls_{{{ rule_id }}} object_static_run_usr_local_sysctls_{{{ rule_id }}} @@ -213,16 +186,7 @@ object_static_usr_local_lib_sysctld_{{{ rule_id }}} - object_static_run_usr_sysctls_{{{ rule_id }}} - - - - - object_static_run_sysctld_{{{ rule_id }}} -{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9"] %}} - object_static_usr_lib_sysctld_{{{ rule_id }}} -{{% endif %}} @@ -249,13 +213,12 @@ {{{ sysctl_match() }}} -{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9"] %}} /usr/lib/sysctl.d ^.*\.conf$ {{{ sysctl_match() }}} -{{% endif %}} + {{% if SYSCTLVAL is string %}} {{% if SYSCTLVAL == "" %}} From 584583e910693375aee7bc248cc236ce088a8985 Mon Sep 17 00:00:00 2001 From: Edgar Aguilar Date: Tue, 23 May 2023 11:59:57 -0600 Subject: [PATCH 2/4] Add two tests to sysctl template Signed-off-by: Edgar Aguilar --- .../sysctl/tests/correct_value_usr_lib.pass.sh | 14 ++++++++++++++ .../sysctl/tests/wrong_usr_lib_correct_etc.pass.sh | 14 ++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 shared/templates/sysctl/tests/correct_value_usr_lib.pass.sh create mode 100644 shared/templates/sysctl/tests/wrong_usr_lib_correct_etc.pass.sh diff --git a/shared/templates/sysctl/tests/correct_value_usr_lib.pass.sh b/shared/templates/sysctl/tests/correct_value_usr_lib.pass.sh new file mode 100644 index 00000000000..cf34728f96c --- /dev/null +++ b/shared/templates/sysctl/tests/correct_value_usr_lib.pass.sh @@ -0,0 +1,14 @@ +#!/bin/bash +{{% if SYSCTLVAL == "" %}} +# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}} +{{% endif %}} + +# Clean sysctl config directories +rm -rf /usr/lib/sysctl.d/* /usr/local/lib/sysctl.d/* /run/sysctl.d/* /etc/sysctl.d/* + +sed -i "/{{{ SYSCTLVAR }}}/d" /etc/sysctl.conf +mkdir -p /usr/lib/sysctl.d +echo "{{{ SYSCTLVAR }}} = {{{ SYSCTL_CORRECT_VALUE }}}" >> /usr/lib/sysctl.d/correct.conf + +# set correct runtime value to check if the filesystem configuration is evaluated properly +sysctl -w {{{ SYSCTLVAR }}}="{{{ SYSCTL_CORRECT_VALUE }}}" diff --git a/shared/templates/sysctl/tests/wrong_usr_lib_correct_etc.pass.sh b/shared/templates/sysctl/tests/wrong_usr_lib_correct_etc.pass.sh new file mode 100644 index 00000000000..69d60ed5ab7 --- /dev/null +++ b/shared/templates/sysctl/tests/wrong_usr_lib_correct_etc.pass.sh @@ -0,0 +1,14 @@ +#!/bin/bash +{{% if SYSCTLVAL == "" %}} +# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}} +{{% endif %}} + +# Clean sysctl config directories +rm -rf /usr/lib/sysctl.d/* /run/sysctl.d/* /etc/sysctl.d/* + +sed -i "/{{{ SYSCTLVAR }}}/d" /etc/sysctl.conf + +echo "{{{ SYSCTLVAR }}} = {{{ SYSCTL_WRONG_VALUE }}}" >> /usr/lib/sysctl.d/01-first.conf +echo "{{{ SYSCTLVAR }}} = {{{ SYSCTL_CORRECT_VALUE }}}" >> /etc/sysctl.d/50-second.conf + +sysctl -w {{{ SYSCTLVAR }}}="{{{ SYSCTL_CORRECT_VALUE }}}" From 13f96f5bcfc06c7418cacaa87ae97704c061739b Mon Sep 17 00:00:00 2001 From: Edgar Aguilar Date: Mon, 12 Jun 2023 10:39:48 -0600 Subject: [PATCH 3/4] Add fail test to sysctl template Adding test wrong_usr_lib_wrong_etc.fail.sh, to complement wrong_usr_lib_correct_etc.pass.sh Signed-off-by: Edgar Aguilar --- .../sysctl/tests/wrong_usr_lib_wrong_etc.fail.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 shared/templates/sysctl/tests/wrong_usr_lib_wrong_etc.fail.sh diff --git a/shared/templates/sysctl/tests/wrong_usr_lib_wrong_etc.fail.sh b/shared/templates/sysctl/tests/wrong_usr_lib_wrong_etc.fail.sh new file mode 100644 index 00000000000..3412c726376 --- /dev/null +++ b/shared/templates/sysctl/tests/wrong_usr_lib_wrong_etc.fail.sh @@ -0,0 +1,13 @@ +{{% if SYSCTLVAL == "" %}} +# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}} +{{% endif %}} + +# Clean sysctl config directories +rm -rf /usr/lib/sysctl.d/* /run/sysctl.d/* /etc/sysctl.d/* + +sed -i "/{{{ SYSCTLVAR }}}/d" /etc/sysctl.conf + +echo "{{{ SYSCTLVAR }}} = {{{ SYSCTL_WRONG_VALUE }}}" >> /usr/lib/sysctl.d/01-first.conf +echo "{{{ SYSCTLVAR }}} = {{{ SYSCTL_WRONG_VALUE }}}" >> /etc/sysctl.d/50-second.conf + +sysctl -w {{{ SYSCTLVAR }}}="{{{ SYSCTL_CORRECT_VALUE }}}" From b39c0079012d14ac95e8e3061adedb3959aadcb1 Mon Sep 17 00:00:00 2001 From: Edgar Aguilar Date: Mon, 12 Jun 2023 10:50:57 -0600 Subject: [PATCH 4/4] Polish OVAL in sysctl template - Fix comments in OVAL tests - Remove OVAL test whith jinja when the criterion is also removed Signed-off-by: Edgar Aguilar --- shared/templates/sysctl/oval.template | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/shared/templates/sysctl/oval.template b/shared/templates/sysctl/oval.template index 39bd45ebfab..988aee9f59c 100644 --- a/shared/templates/sysctl/oval.template +++ b/shared/templates/sysctl/oval.template @@ -155,17 +155,21 @@ {{{ state_static_sysctld("user") }}} + {{% if MISSING_PARAMETER_PASS == "true" %}} + comment="{{{ SYSCTLVAR }}} static configuration in /usr/lib/sysctl.d/*.conf" state_operator="OR"> {{{ state_static_sysctld("usr_lib_sysctld") }}} - + {{% else %}} + comment="{{{ SYSCTLVAR }}} static configuration in /usr/lib/sysctl.d/*.conf" + state_operator="OR"> {{{ state_static_sysctld("usr_lib_sysctld") }}} + {{% endif %}} +