From 86213d88acdc31451b8bd1676eababe0c994ca10 Mon Sep 17 00:00:00 2001 From: Miha Purg Date: Sat, 20 Apr 2024 20:22:23 +0200 Subject: [PATCH] Fix dirs in sysctl template for Ubuntu 20.04/22.04 On Ubuntu /lib is symlinked to /usr/lib, thus /lib/sysctl.d contains package-managed configs, which should not be modified and can be incorrect if overriden elsewhere (see #10637). --- shared/templates/sysctl/ansible.template | 2 +- shared/templates/sysctl/asd.xml | 272 +++++++++++++++++++++++ shared/templates/sysctl/bash.template | 2 +- shared/templates/sysctl/oval.template | 4 +- 4 files changed, 276 insertions(+), 4 deletions(-) create mode 100644 shared/templates/sysctl/asd.xml diff --git a/shared/templates/sysctl/ansible.template b/shared/templates/sysctl/ansible.template index b7aa24401524..b6d23494c6b0 100644 --- a/shared/templates/sysctl/ansible.template +++ b/shared/templates/sysctl/ansible.template @@ -19,7 +19,7 @@ - "/run/sysctl.d/" - "/usr/local/lib/sysctl.d/" {{% endif %}} -{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9", "sle12", "sle15"] %}} +{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9", "sle12", "sle15", "ubuntu2004", "ubuntu2204"] %}} - "/usr/lib/sysctl.d/" {{% endif %}} contains: '^[\s]*{{{ SYSCTLVAR }}}.*$' diff --git a/shared/templates/sysctl/asd.xml b/shared/templates/sysctl/asd.xml new file mode 100644 index 000000000000..880708719086 --- /dev/null +++ b/shared/templates/sysctl/asd.xml @@ -0,0 +1,272 @@ +{{%- if SYSCTLVAL == "" %}} +{{%- set COMMENT_VALUE="the appropriate value" %}} +{{%- elif SYSCTLVAL is string %}} +{{%- set COMMENT_VALUE=SYSCTLVAL %}} +{{%- else %}} +{{%- set COMMENT_VALUE = SYSCTLVAL | join(" or " ) %}} +{{%- endif %}} + +{{% macro state_static_sysctld(prefix) -%}} + +{{% if SYSCTLVAL is string %}} + +{{% elif SYSCTLVAL is sequence %}} +{{% for x in SYSCTLVAL %}} + +{{% endfor %}} +{{% endif %}} +{{%- endmacro -%}} +{{%- macro sysctl_match() -%}} + ^[\s]*{{{ SYSCTLVAR }}}[\s]*=[\s]*(.*)[\s]*$ + 1 +{{%- endmacro -%}} +{{%- if "P" in FLAGS -%}} + + + + {{{ oval_metadata("The '" + SYSCTLVAR + "' kernel parameter should be set to the appropriate value in system configuration" + (" and system runtime." if CHECK_RUNTIME == "true" else ".")) }}} + + +{{% if CHECK_RUNTIME == "true" %}} + +{{%- endif %}} + + + + +{{%- elif "I" in FLAGS -%}} + + + + {{{ oval_metadata("The kernel '" + SYSCTLVAR + "' parameter should be set to the appropriate value in system configuration" + (" and system runtime." if CHECK_RUNTIME == "true" else ".")) }}} + +{{% if product in ["ubuntu1604", "ubuntu1804"] %}} + +{{% else %}} + +{{% endif %}} + + +{{% if CHECK_RUNTIME == "true" %}} + +{{%- endif %}} + + + + + +{{%- endif %}} +{{%- if "R" in FLAGS -%}} + +{{% if CHECK_RUNTIME == "true" %}} + + + {{{ oval_metadata("The kernel '" + SYSCTLVAR + "' parameter should be set to " + COMMENT_VALUE + " in the system runtime.") }}} + + + + + + + +{{% if SYSCTLVAL is string %}} + +{{% elif SYSCTLVAL is sequence %}} +{{% for x in SYSCTLVAL %}} + +{{% endfor %}} +{{% endif %}} + + + + {{{ SYSCTLVAR }}} + +{{% if SYSCTLVAL is string %}} +{{% if SYSCTLVAL == "" %}} + + + + + +{{%- else %}} + +{{% if OPERATION == "pattern match" %}} + {{{ SYSCTLVAL_REGEX }}} +{{% else %}} + {{{ SYSCTLVAL }}} +{{% endif %}} + +{{%- endif %}} +{{% elif SYSCTLVAL is sequence %}} +{{% for x in SYSCTLVAL %}} + + {{{ x }}} + +{{% endfor %}} +{{% endif %}} + +{{% endif %}} + +{{%- endif -%}} +{{%- if "S" in FLAGS -%}} + + + + {{{ oval_metadata("The kernel '" + SYSCTLVAR + "' parameter should be set to " + COMMENT_VALUE + " in the system configuration.") }}} + + + + + + + {{% if MISSING_PARAMETER_PASS == "true" %}} + + {{% else %}} + + {{% endif %}} + + + + + + + + + + {{{ state_static_sysctld("user") }}} + + + {{% if MISSING_PARAMETER_PASS == "true" %}} + + {{{ state_static_sysctld("usr_lib_sysctld") }}} + + {{% else %}} + + {{{ state_static_sysctld("usr_lib_sysctld") }}} + + {{% endif %}} + + + + + object_static_etc_lib_sysctls_{{{ rule_id }}} + object_static_run_usr_local_sysctls_{{{ rule_id }}} + + + + + + object_static_etc_sysctls_{{{ rule_id }}} +{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9"] %}} + object_static_lib_sysctld_{{{ rule_id }}} +{{% endif %}} + + + + + + object_static_sysctl_{{{ rule_id }}} + object_static_etc_sysctld_{{{ rule_id }}} + + + + + + object_static_usr_local_lib_sysctld_{{{ rule_id }}} + object_static_run_sysctld_{{{ rule_id }}} + + + + /etc/sysctl.conf + {{{ sysctl_match() }}} + + + + /etc/sysctl.d + ^.*\.conf$ + {{{ sysctl_match() }}} + + + + /run/sysctl.d + ^.*\.conf$ + {{{ sysctl_match() }}} + + + + /usr/local/lib/sysctl.d + ^.*\.conf$ + {{{ sysctl_match() }}} + + + + /usr/lib/sysctl.d + ^.*\.conf$ + {{{ sysctl_match() }}} + +{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9"] %}} + + /lib/sysctl.d + ^.*\.conf$ + {{{ sysctl_match() }}} + +{{% endif %}} +{{% if SYSCTLVAL is string %}} +{{% if SYSCTLVAL == "" %}} + + + + + + +{{% else %}} + +{{% if OPERATION == "pattern match" %}} + {{{ SYSCTLVAL_REGEX }}} +{{% else %}} + {{{ SYSCTLVAL }}} +{{% endif %}} + +{{% endif %}} +{{% elif SYSCTLVAL is sequence %}} +{{% for x in SYSCTLVAL %}} + + {{{ x }}} + +{{% endfor %}} +{{% endif %}} + +{{%- endif -%}} diff --git a/shared/templates/sysctl/bash.template b/shared/templates/sysctl/bash.template index 166788260932..0130f6d80b5e 100644 --- a/shared/templates/sysctl/bash.template +++ b/shared/templates/sysctl/bash.template @@ -7,7 +7,7 @@ # Comment out any occurrences of {{{ SYSCTLVAR }}} from /etc/sysctl.d/*.conf files {{% if product in [ "sle12", "sle15"] %}} for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /lib/sysctl.d/*.conf; do -{{% elif product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9"] %}} +{{% elif product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9", "ubuntu2004", "ubuntu2204"] %}} for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf; do {{% else %}} for f in /etc/sysctl.d/*.conf /run/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf; do diff --git a/shared/templates/sysctl/oval.template b/shared/templates/sysctl/oval.template index 880708719086..557aea4b49c6 100644 --- a/shared/templates/sysctl/oval.template +++ b/shared/templates/sysctl/oval.template @@ -188,7 +188,7 @@ object_static_etc_sysctls_{{{ rule_id }}} -{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9"] %}} +{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9", "ubuntu2004", "ubuntu2204"] %}} object_static_lib_sysctld_{{{ rule_id }}} {{% endif %}} @@ -235,7 +235,7 @@ ^.*\.conf$ {{{ sysctl_match() }}} -{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9"] %}} +{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel7", "rhel8", "rhel9", "ubuntu2004", "ubuntu2204"] %}} /lib/sysctl.d ^.*\.conf$