|
6 | 6 | - Kernel opts can be stored in /etc/default/grub so they are persistent between kernel upgrades |
7 | 7 | -#}} |
8 | 8 | {{% set system_with_expanded_kernel_options_in_loader_entries = false -%}} |
9 | | -{{% set system_with_referenced_kernel_options_in_loader_entries = false -%}} |
10 | 9 | {{% set system_with_kernel_options_in_grubenv = false -%}} |
| 10 | +{{% set system_with_expanded_kernel_options_in_loader_entries_or_with_options_in_grubenv = false -%}} |
11 | 11 | {{% set system_with_kernel_options_in_etc_default_grub = true -%}} |
12 | 12 | {{% set system_with_kernel_options_in_etc_default_grub_d = false -%}} |
13 | 13 | {{% set system_with_expanded_kernel_options_in_grub_cfg = false -%}} |
|
18 | 18 | {{%- endif -%}} |
19 | 19 |
|
20 | 20 | {{% 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 -%}} |
23 | 22 | {{%- endif -%}} |
24 | 23 |
|
25 | 24 | {{% if product in ["ol7"] or 'ubuntu' in product -%}} |
|
34 | 33 | {{% set system_with_bios_and_uefi_support = true %}} |
35 | 34 | {{%- endif -%}} |
36 | 35 |
|
| 36 | + |
37 | 37 | <def-group> |
38 | 38 | <definition class="compliance" id="{{{ _RULE_ID }}}" version="2"> |
39 | 39 | {{{ oval_metadata("Ensure " + ARG_NAME_VALUE + " is configured in the kernel line in /etc/default/grub.") }}} |
40 | 40 | <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" /> |
42 | 61 | {{% if system_with_bios_and_uefi_support -%}} |
43 | 62 | <criteria operator="OR"> |
44 | 63 | {{%- endif %}} |
|
49 | 68 | comment="Check if {{{ ARG_NAME_VALUE }}} is present in the GRUB2 environment variable block in {{{ grub2_uefi_boot_path }}}/grubenv" /> |
50 | 69 | </criteria> |
51 | 70 | {{%- 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 -%}} |
57 | 72 | <criterion test_ref="test_grub2_{{{ SANITIZED_ARG_NAME }}}_entries" |
58 | 73 | comment="Check if {{{ ARG_NAME_VALUE }}} is present in the boot parameters in the /boot/loader/entries/*.conf" /> |
59 | 74 | {{%- endif %}} |
|
96 | 111 | </criteria> |
97 | 112 | </definition> |
98 | 113 |
|
| 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 | + |
99 | 144 | {{%- if system_with_kernel_options_in_etc_default_grub %}} |
100 | 145 | <ind:textfilecontent54_test id="test_grub2_{{{ SANITIZED_ARG_NAME }}}_argument" |
101 | 146 | comment="check for {{{ ARG_NAME_VALUE }}} in /etc/default/grub via GRUB_CMDLINE_LINUX" |
|
154 | 199 | </ind:textfilecontent54_object> |
155 | 200 | {{%- endif %}} |
156 | 201 |
|
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 %}} |
158 | 203 | {{%- macro test_and_object_for_kernel_options_grub_env(base_name, path) %}} |
159 | 204 | <ind:textfilecontent54_test id="test_{{{ base_name }}}" |
160 | 205 | comment="check for kernel command line parameters {{{ ARG_NAME_VALUE }}} in {{{ path }}} for all kernels" |
|
225 | 270 | {{%- endif %}} |
226 | 271 | {{%- endif %}} |
227 | 272 |
|
| 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 | + |
228 | 280 | {{% if ARG_VALUE %}} |
229 | 281 | <ind:textfilecontent54_state id="state_grub2_{{{ SANITIZED_ARG_NAME }}}_argument" |
230 | 282 | version="1"> |
|
0 commit comments