Skip to content

Commit 4a8073c

Browse files
authored
Merge pull request #12375 from vojtapolasek/fix_grub2_argument_locations
enhance the grub2_argument template to cover more use cases
2 parents da1fa23 + c3b668f commit 4a8073c

26 files changed

+346
-144
lines changed

linux_os/guide/auditing/grub2_audit_argument/tests/arg_not_there_etcdefaultgrub_recovery_disabled.fail.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

linux_os/guide/auditing/grub2_audit_argument/tests/arg_not_there_rhel7.fail.sh renamed to linux_os/guide/auditing/grub2_audit_argument/tests/arg_not_there_grub_cfg.fail.sh

File renamed without changes.

linux_os/guide/auditing/grub2_audit_argument/tests/blank_grubenv_rhel8.fail.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

linux_os/guide/auditing/grub2_audit_argument/tests/correct_recovery_disabled.pass.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

linux_os/guide/auditing/grub2_audit_argument/tests/double_value_rhel7.fail.sh renamed to linux_os/guide/auditing/grub2_audit_argument/tests/double_value_ol7.fail.sh

File renamed without changes.

linux_os/guide/auditing/grub2_audit_argument/tests/wrong_value_etcdefaultgrub.fail.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

linux_os/guide/auditing/grub2_audit_argument/tests/wrong_value_etcdefaultgrub_recovery_disabled.fail.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

linux_os/guide/auditing/grub2_audit_argument/tests/wrong_value_rhel7.fail.sh renamed to linux_os/guide/auditing/grub2_audit_argument/tests/wrong_value_ol7.fail.sh

File renamed without changes.

linux_os/guide/auditing/grub2_audit_argument/tests/wrong_value_rhel8.fail.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

shared/templates/grub2_bootloader_argument/oval.template

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
- Kernel opts can be stored in /etc/default/grub so they are persistent between kernel upgrades
77
-#}}
88
{{% set system_with_expanded_kernel_options_in_loader_entries = false -%}}
9-
{{% set system_with_referenced_kernel_options_in_loader_entries = false -%}}
109
{{% set system_with_kernel_options_in_grubenv = false -%}}
10+
{{% set system_with_expanded_kernel_options_in_loader_entries_or_with_options_in_grubenv = false -%}}
1111
{{% set system_with_kernel_options_in_etc_default_grub = true -%}}
1212
{{% set system_with_kernel_options_in_etc_default_grub_d = false -%}}
1313
{{% set system_with_expanded_kernel_options_in_grub_cfg = false -%}}
@@ -18,8 +18,7 @@
1818
{{%- endif -%}}
1919

2020
{{% if product in ["ol8", "rhel8"] -%}}
21-
{{% set system_with_referenced_kernel_options_in_loader_entries = true %}}
22-
{{% set system_with_kernel_options_in_grubenv = true %}}
21+
{{% set system_with_expanded_kernel_options_in_loader_entries_or_with_options_in_grubenv = true -%}}
2322
{{%- endif -%}}
2423

2524
{{% if product in ["ol7"] or 'ubuntu' in product -%}}
@@ -34,11 +33,31 @@
3433
{{% set system_with_bios_and_uefi_support = true %}}
3534
{{%- endif -%}}
3635

36+
3737
<def-group>
3838
<definition class="compliance" id="{{{ _RULE_ID }}}" version="2">
3939
{{{ oval_metadata("Ensure " + ARG_NAME_VALUE + " is configured in the kernel line in /etc/default/grub.") }}}
4040
<criteria operator="AND">
41-
{{% if system_with_kernel_options_in_grubenv -%}}
41+
{{% if system_with_expanded_kernel_options_in_loader_entries_or_with_options_in_grubenv %}}
42+
<criterion test_ref="test_grub2_{{{ SANITIZED_ARG_NAME }}}_entries_expanded_or_referenced"
43+
comment="Check /boot/loader/entries/*.conf files if they contain direct reference to {{{ ARG_NAME_VALUE }}} or if they contain $kernelopts" />
44+
<criteria operator="OR"
45+
comment="Expressing implication">
46+
<criterion test_ref="test_grub2_{{{ SANITIZED_ARG_NAME }}}_at_least_one_entry_referenced" negate="true"
47+
comment="Negate the result of the test if there exists at least one $kernelopts in /boot/loader/entries" />
48+
{{% if system_with_bios_and_uefi_support -%}}
49+
<criteria operator="OR">
50+
{{%- endif %}}
51+
<criterion test_ref="test_grub2_{{{ SANITIZED_ARG_NAME }}}_argument_grub_env"
52+
comment="Check if {{{ ARG_NAME_VALUE }}} is present in the GRUB2 environment variable block in {{{ grub2_boot_path }}}/grubenv" />
53+
{{% if system_with_bios_and_uefi_support -%}}
54+
<criterion test_ref="test_grub2_{{{ SANITIZED_ARG_NAME }}}_argument_grub_env_uefi"
55+
comment="Check if {{{ ARG_NAME_VALUE }}} is present in the GRUB2 environment variable block in {{{ grub2_uefi_boot_path }}}/grubenv" />
56+
</criteria>
57+
{{%- endif %}}
58+
</criteria>
59+
{{% elif system_with_kernel_options_in_grubenv -%}}
60+
<extend_definition comment="check kernel command line parameters for referenced boot entries reference the $kernelopts variable" definition_ref="grub2_entries_reference_kernelopts" />
4261
{{% if system_with_bios_and_uefi_support -%}}
4362
<criteria operator="OR">
4463
{{%- endif %}}
@@ -49,11 +68,7 @@
4968
comment="Check if {{{ ARG_NAME_VALUE }}} is present in the GRUB2 environment variable block in {{{ grub2_uefi_boot_path }}}/grubenv" />
5069
</criteria>
5170
{{%- endif %}}
52-
{{%- endif %}}
53-
{{% if system_with_referenced_kernel_options_in_loader_entries -%}}
54-
<extend_definition comment="check kernel command line parameters for referenced boot entries reference the $kernelopts variable" definition_ref="grub2_entries_reference_kernelopts" />
55-
{{%- endif %}}
56-
{{% if system_with_expanded_kernel_options_in_loader_entries -%}}
71+
{{% elif system_with_expanded_kernel_options_in_loader_entries -%}}
5772
<criterion test_ref="test_grub2_{{{ SANITIZED_ARG_NAME }}}_entries"
5873
comment="Check if {{{ ARG_NAME_VALUE }}} is present in the boot parameters in the /boot/loader/entries/*.conf" />
5974
{{%- endif %}}
@@ -96,6 +111,36 @@
96111
</criteria>
97112
</definition>
98113

114+
{{% if system_with_expanded_kernel_options_in_loader_entries_or_with_options_in_grubenv %}}
115+
<ind:textfilecontent54_test id="test_grub2_{{{ SANITIZED_ARG_NAME }}}_entries_expanded_or_referenced"
116+
comment="check all /boot/loader/entries/*.conf for expanded entries of {{{ ARG_NAME_VALUE }}}. Leave out rescue boot entries. Accept also references to $kernelopts."
117+
state_operator="OR" check="all" check_existence="all_exist" version="1">
118+
<ind:object object_ref="obj_grub2_{{{ SANITIZED_ARG_NAME }}}_entries_expanded_or_referenced" />
119+
<ind:state state_ref="state_grub2_{{{ SANITIZED_ARG_NAME }}}_argument" />
120+
<ind:state state_ref="state_grub2_{{{ SANITIZED_ARG_NAME }}}_argument_is_kernelopts" />
121+
</ind:textfilecontent54_test>
122+
123+
<ind:textfilecontent54_object id="obj_grub2_{{{ SANITIZED_ARG_NAME }}}_entries_expanded_or_referenced" version="1">
124+
<ind:path>/boot/loader/entries/</ind:path>
125+
<ind:filename operation="pattern match">^.*\.conf$</ind:filename>
126+
<ind:pattern operation="pattern match">^options (.*)$</ind:pattern>
127+
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
128+
<filter action="exclude">state_grub2_rescue_entry_for_{{{ _RULE_ID }}}</filter>
129+
</ind:textfilecontent54_object>
130+
131+
<ind:textfilecontent54_state id="state_grub2_rescue_entry_for_{{{ _RULE_ID }}}" version="1">
132+
<ind:filename operation="pattern match">.*rescue\.conf$</ind:filename>
133+
</ind:textfilecontent54_state>
134+
135+
<ind:textfilecontent54_test id="test_grub2_{{{ SANITIZED_ARG_NAME }}}_at_least_one_entry_referenced"
136+
comment="check all /boot/loader/entries/*.conf files if there is at least one entry referencing $kernelopts. Leave out rescue entries."
137+
check="all" check_existence="at_least_one_exists" version="1">
138+
<ind:object object_ref="obj_grub2_{{{ SANITIZED_ARG_NAME }}}_entries_expanded_or_referenced" />
139+
<ind:state state_ref="state_grub2_{{{ SANITIZED_ARG_NAME }}}_argument_is_kernelopts" />
140+
</ind:textfilecontent54_test>
141+
{{% endif %}}
142+
143+
99144
{{%- if system_with_kernel_options_in_etc_default_grub %}}
100145
<ind:textfilecontent54_test id="test_grub2_{{{ SANITIZED_ARG_NAME }}}_argument"
101146
comment="check for {{{ ARG_NAME_VALUE }}} in /etc/default/grub via GRUB_CMDLINE_LINUX"
@@ -154,7 +199,7 @@
154199
</ind:textfilecontent54_object>
155200
{{%- endif %}}
156201

157-
{{%- if system_with_kernel_options_in_grubenv %}}
202+
{{%- if system_with_kernel_options_in_grubenv or system_with_expanded_kernel_options_in_loader_entries_or_with_options_in_grubenv %}}
158203
{{%- macro test_and_object_for_kernel_options_grub_env(base_name, path) %}}
159204
<ind:textfilecontent54_test id="test_{{{ base_name }}}"
160205
comment="check for kernel command line parameters {{{ ARG_NAME_VALUE }}} in {{{ path }}} for all kernels"
@@ -225,6 +270,13 @@
225270
{{%- endif %}}
226271
{{%- endif %}}
227272

273+
{{% if system_with_expanded_kernel_options_in_loader_entries_or_with_options_in_grubenv %}}
274+
<ind:textfilecontent54_state id="state_grub2_{{{ SANITIZED_ARG_NAME }}}_argument_is_kernelopts"
275+
version="1">
276+
<ind:subexpression datatype="string" operation="pattern match">^(?:.*\s)?\$kernelopts(?:\s.*)?$</ind:subexpression>
277+
</ind:textfilecontent54_state>
278+
{{% endif %}}
279+
228280
{{% if ARG_VALUE %}}
229281
<ind:textfilecontent54_state id="state_grub2_{{{ SANITIZED_ARG_NAME }}}_argument"
230282
version="1">

0 commit comments

Comments
 (0)