Blame SOURCES/scap-security-guide-0.1.61-grub2_template_fix-PR_8180.patch

5fd106
From 1bd88bbdc7ce8b6e2265f323cd3a777ef2240e6b Mon Sep 17 00:00:00 2001
5fd106
From: Matej Tyc <matyc@redhat.com>
5fd106
Date: Fri, 28 Jan 2022 17:11:56 +0100
5fd106
Subject: [PATCH 1/5] Change the grub2 bootloader argument template
5fd106
5fd106
- Introduce the concept of product-specific bootloader config
5fd106
  properties that determine the check/remediation form.
5fd106
- Expand the RHEL8 remediation with a check for update of
5fd106
  /etc/default/grub contents.
5fd106
- Add a RHEL8 check that looks for kernelopts references in loader entries.
5fd106
- Update tests.
5fd106
---
5fd106
 .../grub2_entries_reference_kernelopts.xml    | 25 +++++
5fd106
 .../ansible.template                          | 35 ++++++-
5fd106
 .../grub2_bootloader_argument/bash.template   | 48 +++++++--
5fd106
 .../grub2_bootloader_argument/oval.template   | 97 +++++++++++++------
5fd106
 .../arg_not_there_etcdefaultgrub.fail.sh      |  2 +-
5fd106
 ....fail.sh => arg_not_there_grubenv.fail.sh} |  0
5fd106
 6 files changed, 164 insertions(+), 43 deletions(-)
5fd106
 create mode 100644 shared/checks/oval/grub2_entries_reference_kernelopts.xml
5fd106
 rename shared/templates/grub2_bootloader_argument/tests/{arg_not_there.fail.sh => arg_not_there_grubenv.fail.sh} (100%)
5fd106
5fd106
diff --git a/shared/checks/oval/grub2_entries_reference_kernelopts.xml b/shared/checks/oval/grub2_entries_reference_kernelopts.xml
5fd106
new file mode 100644
5fd106
index 00000000000..1aec9fe64d2
5fd106
--- /dev/null
5fd106
+++ b/shared/checks/oval/grub2_entries_reference_kernelopts.xml
5fd106
@@ -0,0 +1,25 @@
5fd106
+<def-group>
5fd106
+  <definition class="compliance" id="grub2_entries_reference_kernelopts" version="2">
5fd106
+  {{{ oval_metadata(
5fd106
+	  "Ensure that grubenv-defined kernel options are referenced in individual boot loader entries",
5fd106
+	  title="Use $kernelopts in /boot/loader/entries/*.conf",
5fd106
+	  affected_platforms=["multi_platform_all"]) }}}
5fd106
+    <criteria operator="AND">
5fd106
+        
5fd106
+        comment="check kernel command line parameters for referenced boot entries reference the $kernelopts variable." />
5fd106
+    </criteria>
5fd106
+  </definition>
5fd106
+
5fd106
+    
5fd106
+                                comment="check kernel command line parameters for referenced boot entries reference the $kernelopts variable."
5fd106
+                                check="all" check_existence="all_exist" version="1">
5fd106
+      <ind:object object_ref="object_grub2_entries_reference_kernelopts" />
5fd106
+    </ind:textfilecontent54_test>
5fd106
+
5fd106
+  <ind:textfilecontent54_object id="object_grub2_entries_reference_kernelopts" version="1">
5fd106
+    <ind:path>/boot/loader/entries/</ind:path>
5fd106
+    <ind:filename operation="pattern match">^.*\.conf$</ind:filename>
5fd106
+    <ind:pattern operation="pattern match">^options .*\b\$kernelopts\b.*$</ind:pattern>
5fd106
+    <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>                                                                             
5fd106
+  </ind:textfilecontent54_object>
5fd106
+</def-group>
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/ansible.template b/shared/templates/grub2_bootloader_argument/ansible.template
5fd106
index 58d4fab69fa..de970879c8f 100644
5fd106
--- a/shared/templates/grub2_bootloader_argument/ansible.template
5fd106
+++ b/shared/templates/grub2_bootloader_argument/ansible.template
5fd106
@@ -4,7 +4,34 @@
5fd106
 # complexity = medium
5fd106
 # disruption = low
5fd106
 
5fd106
-{{% if product in ["rhel7", "ol7", "rhel9"] or 'ubuntu' in product %}}
5fd106
+{{#
5fd106
+   See the OVAL template for more comments.
5fd106
+   Product-specific categorization should be synced across all template content types
5fd106
+-#}}
5fd106
+{{% set system_with_expanded_kernel_options_in_loader_entries = false -%}}
5fd106
+{{% set system_with_referenced_kernel_options_in_loader_entries = false -%}}
5fd106
+{{% set system_with_kernel_options_in_grubenv = false -%}}
5fd106
+{{% set system_with_kernel_options_in_etc_default_grub = false -%}}
5fd106
+{{% set system_with_expanded_kernel_options_in_grub_cfg = false -%}}
5fd106
+
5fd106
+{{% if product in ["rhel9"] %}}
5fd106
+{{% set system_with_expanded_kernel_options_in_loader_entries = true %}}
5fd106
+{{% endif -%}}
5fd106
+
5fd106
+{{% if product in ["rhel8"] %}}
5fd106
+{{% set system_with_referenced_kernel_options_in_loader_entries = true %}}
5fd106
+{{% set system_with_kernel_options_in_grubenv = true %}}
5fd106
+{{% endif -%}}
5fd106
+
5fd106
+{{% if product in ["rhel7", "ol7"] or 'ubuntu' in product %}}
5fd106
+{{% set system_with_expanded_kernel_options_in_grub_cfg = true %}}
5fd106
+{{% endif -%}}
5fd106
+
5fd106
+{{% if product in ["rhel7", "ol7", "rhel8", "ol8", "rhel9"] or 'ubuntu' in product %}}
5fd106
+{{% set system_with_kernel_options_in_etc_default_grub = true %}}
5fd106
+{{% endif -%}}
5fd106
+
5fd106
+{{% if system_with_kernel_options_in_etc_default_grub -%}}
5fd106
 - name: Check {{{ ARG_NAME }}} argument exists
5fd106
   command: grep 'GRUB_CMDLINE_LINUX.*{{{ ARG_NAME }}}=' /etc/default/grub
5fd106
   failed_when: False
5fd106
@@ -27,7 +54,9 @@
5fd106
 - name: Update bootloader menu
5fd106
   command: /sbin/grubby --update-kernel=ALL --args="{{{ ARG_NAME_VALUE }}}"
5fd106
 
5fd106
-{{% else %}}
5fd106
+{{%- endif %}}
5fd106
+
5fd106
+{{% if system_with_kernel_options_in_grubenv -%}}
5fd106
 
5fd106
 - name: Get current kernel parameters
5fd106
   ansible.builtin.shell:
5fd106
@@ -50,4 +79,4 @@
5fd106
   when:
5fd106
     - kernelopts.rc != 0
5fd106
 
5fd106
-{{% endif %}}
5fd106
+{{%- endif %}}
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/bash.template b/shared/templates/grub2_bootloader_argument/bash.template
5fd106
index 631e686897e..817fd1fde23 100644
5fd106
--- a/shared/templates/grub2_bootloader_argument/bash.template
5fd106
+++ b/shared/templates/grub2_bootloader_argument/bash.template
5fd106
@@ -1,6 +1,41 @@
5fd106
 # platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol,multi_platform_rhv,multi_platform_ubuntu,multi_platform_sle
5fd106
+{{#
5fd106
+   See the OVAL template for more comments.
5fd106
+   Product-specific categorization should be synced across all template content types
5fd106
+-#}}
5fd106
 
5fd106
-{{% if product in ["rhel7", "ol7", "rhel9"] or 'ubuntu' in product %}}
5fd106
+{{% set system_with_expanded_kernel_options_in_loader_entries = false -%}}
5fd106
+{{% set system_with_referenced_kernel_options_in_loader_entries = false -%}}
5fd106
+{{% set system_with_kernel_options_in_grubenv = false -%}}
5fd106
+{{% set system_with_kernel_options_in_etc_default_grub = false -%}}
5fd106
+{{% set system_with_expanded_kernel_options_in_grub_cfg = false -%}}
5fd106
+
5fd106
+{{% if product in ["rhel9"] %}}
5fd106
+{{% set system_with_expanded_kernel_options_in_loader_entries = true %}}
5fd106
+{{% endif -%}}
5fd106
+
5fd106
+{{% if product in ["rhel8"] %}}
5fd106
+{{% set system_with_referenced_kernel_options_in_loader_entries = true %}}
5fd106
+{{% set system_with_kernel_options_in_grubenv = true %}}
5fd106
+{{% endif -%}}
5fd106
+
5fd106
+{{% if product in ["rhel7", "ol7"] or 'ubuntu' in product %}}
5fd106
+{{% set system_with_expanded_kernel_options_in_grub_cfg = true %}}
5fd106
+{{% endif -%}}
5fd106
+
5fd106
+{{% if product in ["rhel7", "ol7", "rhel8", "ol8", "rhel9"] or 'ubuntu' in product %}}
5fd106
+{{% set system_with_kernel_options_in_etc_default_grub = true %}}
5fd106
+{{% endif -%}}
5fd106
+
5fd106
+{{% macro update_etc_default_grub(arg_name_value) %}}
5fd106
+{{% if 'ubuntu' in product %}}
5fd106
+update-grub
5fd106
+{{% else %}}
5fd106
+grubby --update-kernel=ALL --args="{{{ arg_name_value }}}"
5fd106
+{{% endif %}}
5fd106
+{{% endmacro -%}}
5fd106
+
5fd106
+{{% if system_with_kernel_options_in_etc_default_grub %}}
5fd106
 {{% if '/' in ARG_NAME %}}
5fd106
 {{{ raise("ARG_NAME (" + ARG_NAME + ") uses sed path separator (/) in " + rule_id) }}}
5fd106
 {{% elif '/' in ARG_NAME_VALUE %}}
5fd106
@@ -14,14 +49,11 @@ else
5fd106
 	# no {{{ ARG_NAME }}}=arg is present, append it
5fd106
 	sed -i 's/\(^GRUB_CMDLINE_LINUX=".*\)"/\1 {{{ ARG_NAME_VALUE }}}"/'  '/etc/default/grub'
5fd106
 fi
5fd106
-
5fd106
-{{% if 'ubuntu' in product %}}
5fd106
-update-grub
5fd106
-{{% else %}}
5fd106
-# Correct the form of kernel command line for each installed kernel in the bootloader
5fd106
-grubby --update-kernel=ALL --args="{{{ ARG_NAME_VALUE }}}"
5fd106
 {{% endif %}}
5fd106
-{{% else %}}
5fd106
+
5fd106
+{{{ update_etc_default_grub(ARG_NAME_VALUE) }}}
5fd106
+
5fd106
+{{% if system_with_kernel_options_in_grubenv -%}}
5fd106
 # Correct grub2 kernelopts value using grub2-editenv
5fd106
 existing_kernelopts="$(grub2-editenv - list | grep kernelopts)"
5fd106
 if ! printf '%s' "$existing_kernelopts" | grep -qE '^kernelopts=(.*\s)?{{{ ARG_NAME_VALUE }}}(\s.*)?$'; then
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/oval.template b/shared/templates/grub2_bootloader_argument/oval.template
5fd106
index 3ea8acb2910..24258a3bcbd 100644
5fd106
--- a/shared/templates/grub2_bootloader_argument/oval.template
5fd106
+++ b/shared/templates/grub2_bootloader_argument/oval.template
5fd106
@@ -1,15 +1,53 @@
5fd106
+{{#-
5fd106
+  We set defaults to "off", and products should enable relevant ones depending on how the product configures grub.
5fd106
+   - /boot/loader/entries/* may not exist don't exist
5fd106
+   - If they exist, they can reference variables defined in grubenv, or they can contain literal args
5fd106
+   - The grub cfg may either use those loader entries, or it can contain literal values as well
5fd106
+   - Kernel opts can be stored in /etc/default/grub so they are persistent between kernel upgrades
5fd106
+-#}}
5fd106
+{{% set system_with_expanded_kernel_options_in_loader_entries = false -%}}
5fd106
+{{% set system_with_referenced_kernel_options_in_loader_entries = false -%}}
5fd106
+{{% set system_with_kernel_options_in_grubenv = false -%}}
5fd106
+{{% set system_with_kernel_options_in_etc_default_grub = false -%}}
5fd106
+{{% set system_with_expanded_kernel_options_in_grub_cfg = false -%}}
5fd106
+
5fd106
+{{% if product in ["rhel9"] -%}}
5fd106
+{{% set system_with_expanded_kernel_options_in_loader_entries = true %}}
5fd106
+{{%- endif -%}}
5fd106
+
5fd106
+{{% if product in ["rhel8"] -%}}
5fd106
+{{% set system_with_referenced_kernel_options_in_loader_entries = true %}}
5fd106
+{{% set system_with_kernel_options_in_grubenv = true %}}
5fd106
+{{%- endif -%}}
5fd106
+
5fd106
+{{% if product in ["rhel7", "ol7"] or 'ubuntu' in product -%}}
5fd106
+{{% set system_with_expanded_kernel_options_in_grub_cfg = true %}}
5fd106
+{{%- endif -%}}
5fd106
+
5fd106
+{{%- if product in ["rhel7", "ol7", "rhel8", "ol8", "rhel9"] or 'ubuntu' in product %}}
5fd106
+{{% set system_with_kernel_options_in_etc_default_grub = true %}}
5fd106
+{{%- endif -%}}
5fd106
+
5fd106
 <def-group>
5fd106
   <definition class="compliance" id="{{{ _RULE_ID }}}" version="2">
5fd106
     {{{ oval_metadata("Ensure " + ARG_NAME_VALUE + " is configured in the kernel line in /etc/default/grub.") }}}
5fd106
     <criteria operator="AND">
5fd106
-      {{% if product in ["rhel7", "ol7", "rhel9"] or 'ubuntu' in product %}}
5fd106
-        {{% if product in ['rhel9'] %}}
5fd106
+      {{% if system_with_kernel_options_in_grubenv -%}}
5fd106
+        
5fd106
+        comment="Check if {{{ ARG_NAME_VALUE }}} is present in the GRUB2 environment variable block in {{{ grub2_boot_path }}}/grubenv" />
5fd106
+      {{%- endif %}}
5fd106
+      {{% if system_with_referenced_kernel_options_in_loader_entries -%}}
5fd106
+        <extend_definition comment="check kernel command line parameters for referenced boot entries reference the $kernelopts variable" definition_ref="grub2_entries_reference_kernelopts" />
5fd106
+      {{%- endif %}}
5fd106
+      {{% if system_with_expanded_kernel_options_in_loader_entries -%}}
5fd106
           
5fd106
                      comment="Check if {{{ ARG_NAME_VALUE }}} is present in the boot parameters in the /boot/loader/entries/*.conf" />
5fd106
-        {{% else %}}
5fd106
+      {{%- endif %}}
5fd106
+      {{% if system_with_expanded_kernel_options_in_grub_cfg -%}}
5fd106
           
5fd106
           comment="Check if {{{ ARG_NAME_VALUE }}} is present in the boot parameters in the {{{ grub2_boot_path }}}/grub.cfg for all kernels" />
5fd106
-        {{% endif %}}
5fd106
+      {{%- endif %}}
5fd106
+      {{% if system_with_kernel_options_in_etc_default_grub -%}}
5fd106
         <criteria operator="OR">
5fd106
           
5fd106
           comment="check for {{{ ARG_NAME_VALUE }}} in /etc/default/grub via GRUB_CMDLINE_LINUX" />
5fd106
@@ -20,14 +58,11 @@
5fd106
             comment="Check GRUB_DISABLE_RECOVERY=true in /etc/default/grub" />
5fd106
           </criteria>
5fd106
         </criteria>
5fd106
-      {{% else %}}
5fd106
-        
5fd106
-        comment="Check if {{{ ARG_NAME_VALUE }}} is present in the GRUB2 environment variable block in {{{ grub2_boot_path }}}/grubenv" />
5fd106
-      {{% endif %}}
5fd106
+      {{%- endif %}}
5fd106
     </criteria>
5fd106
   </definition>
5fd106
 
5fd106
-{{% if product in ["rhel7", "ol7", "rhel9"] or 'ubuntu' in product %}}
5fd106
+{{%- if system_with_kernel_options_in_etc_default_grub %}}
5fd106
   
5fd106
   comment="check for {{{ ARG_NAME_VALUE }}} in /etc/default/grub via GRUB_CMDLINE_LINUX"
5fd106
   check="all" check_existence="all_exist" version="1">
5fd106
@@ -54,8 +89,25 @@
5fd106
     <ind:pattern operation="pattern match">^\s*GRUB_CMDLINE_LINUX_DEFAULT="(.*)"$</ind:pattern>
5fd106
     <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
5fd106
   </ind:textfilecontent54_object>
5fd106
+{{%- endif %}}
5fd106
+
5fd106
+{{%- if system_with_kernel_options_in_grubenv %}}
5fd106
+  
5fd106
+  comment="check for kernel command line parameters {{{ ARG_NAME_VALUE }}} in {{{ grub2_boot_path }}}/grubenv for all kernels"
5fd106
+  check="all" check_existence="all_exist" version="1">
5fd106
+    <ind:object object_ref="object_grub2_{{{ SANITIZED_ARG_NAME }}}_argument_grub_env" />
5fd106
+    <ind:state state_ref="state_grub2_{{{ SANITIZED_ARG_NAME }}}_argument" />
5fd106
+  </ind:textfilecontent54_test>
5fd106
 
5fd106
-  {{% if product in ["rhel9"] %}}
5fd106
+  
5fd106
+  version="1">
5fd106
+    <ind:filepath>{{{ grub2_boot_path }}}/grubenv</ind:filepath>
5fd106
+    <ind:pattern operation="pattern match">^kernelopts=(.*)$</ind:pattern>
5fd106
+    <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
5fd106
+  </ind:textfilecontent54_object>
5fd106
+{{%- endif %}}
5fd106
+
5fd106
+{{%- if system_with_expanded_kernel_options_in_loader_entries %}}
5fd106
     
5fd106
                                 comment="check kernel command line parameters for {{{ ARG_NAME_VALUE }}} for all boot entries."
5fd106
                                 check="all" check_existence="all_exist" version="1">
5fd106
@@ -69,7 +121,9 @@
5fd106
     <ind:pattern operation="pattern match">^options (.*)$</ind:pattern>
5fd106
     <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
5fd106
   </ind:textfilecontent54_object>
5fd106
-  {{% else %}}
5fd106
+{{%- endif %}}
5fd106
+
5fd106
+{{%- if system_with_expanded_kernel_options_in_grub_cfg %}}
5fd106
   
5fd106
   comment="check kernel command line parameters for {{{ ARG_NAME_VALUE }}} in {{{ grub2_boot_path }}}/grub.cfg for all kernels"
5fd106
   check="all" check_existence="all_exist" version="1">
5fd106
@@ -87,26 +141,7 @@
5fd106
     {{% endif %}}
5fd106
     <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
5fd106
   </ind:textfilecontent54_object>
5fd106
-
5fd106
-  {{% endif %}}
5fd106
-
5fd106
-{{% else %}}
5fd106
-
5fd106
-  
5fd106
-  comment="check forkernel command line parameters {{{ ARG_NAME_VALUE }}} in {{{ grub2_boot_path }}}/grubenv for all kernels"
5fd106
-  check="all" check_existence="all_exist" version="1">
5fd106
-    <ind:object object_ref="object_grub2_{{{ SANITIZED_ARG_NAME }}}_argument_grub_env" />
5fd106
-    <ind:state state_ref="state_grub2_{{{ SANITIZED_ARG_NAME }}}_argument" />
5fd106
-  </ind:textfilecontent54_test>
5fd106
-
5fd106
-  
5fd106
-  version="1">
5fd106
-    <ind:filepath>{{{ grub2_boot_path }}}/grubenv</ind:filepath>
5fd106
-    <ind:pattern operation="pattern match">^kernelopts=(.*)$</ind:pattern>
5fd106
-    <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
5fd106
-  </ind:textfilecontent54_object>
5fd106
-
5fd106
-{{% endif %}}
5fd106
+{{%- endif %}}
5fd106
 
5fd106
   
5fd106
   version="1">
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/tests/arg_not_there_etcdefaultgrub.fail.sh b/shared/templates/grub2_bootloader_argument/tests/arg_not_there_etcdefaultgrub.fail.sh
5fd106
index a56e6d09235..a270be45952 100644
5fd106
--- a/shared/templates/grub2_bootloader_argument/tests/arg_not_there_etcdefaultgrub.fail.sh
5fd106
+++ b/shared/templates/grub2_bootloader_argument/tests/arg_not_there_etcdefaultgrub.fail.sh
5fd106
@@ -1,6 +1,6 @@
5fd106
 #!/bin/bash
5fd106
 
5fd106
-# platform = Red Hat Enterprise Linux 7,Red Hat Enterprise Linux 9
5fd106
+# platform = Red Hat Enterprise Linux 7,Red Hat Enterprise Linux 8,Red Hat Enterprise Linux 9
5fd106
 
5fd106
 # Removes argument from kernel command line in /etc/default/grub
5fd106
 if grep -q '^GRUB_CMDLINE_LINUX=.*{{{ARG_NAME}}}=.*"'  '/etc/default/grub' ; then
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/tests/arg_not_there.fail.sh b/shared/templates/grub2_bootloader_argument/tests/arg_not_there_grubenv.fail.sh
5fd106
similarity index 100%
5fd106
rename from shared/templates/grub2_bootloader_argument/tests/arg_not_there.fail.sh
5fd106
rename to shared/templates/grub2_bootloader_argument/tests/arg_not_there_grubenv.fail.sh
5fd106
5fd106
From 0d10bf751d5e1d7f024cd7301f8b02b38c0e3b9c Mon Sep 17 00:00:00 2001
5fd106
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
5fd106
Date: Wed, 9 Feb 2022 11:19:06 +0100
5fd106
Subject: [PATCH 2/5] Change the default product setting
5fd106
5fd106
Assume that every product stores kernel opts in the /etc/default/grub
5fd106
---
5fd106
 shared/templates/grub2_bootloader_argument/ansible.template | 6 +-----
5fd106
 shared/templates/grub2_bootloader_argument/bash.template    | 6 +-----
5fd106
 shared/templates/grub2_bootloader_argument/oval.template    | 6 +-----
5fd106
 3 files changed, 3 insertions(+), 15 deletions(-)
5fd106
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/ansible.template b/shared/templates/grub2_bootloader_argument/ansible.template
5fd106
index de970879c8f..46de9b465c2 100644
5fd106
--- a/shared/templates/grub2_bootloader_argument/ansible.template
5fd106
+++ b/shared/templates/grub2_bootloader_argument/ansible.template
5fd106
@@ -11,7 +11,7 @@
5fd106
 {{% set system_with_expanded_kernel_options_in_loader_entries = false -%}}
5fd106
 {{% set system_with_referenced_kernel_options_in_loader_entries = false -%}}
5fd106
 {{% set system_with_kernel_options_in_grubenv = false -%}}
5fd106
-{{% set system_with_kernel_options_in_etc_default_grub = false -%}}
5fd106
+{{% set system_with_kernel_options_in_etc_default_grub = true -%}}
5fd106
 {{% set system_with_expanded_kernel_options_in_grub_cfg = false -%}}
5fd106
 
5fd106
 {{% if product in ["rhel9"] %}}
5fd106
@@ -27,10 +27,6 @@
5fd106
 {{% set system_with_expanded_kernel_options_in_grub_cfg = true %}}
5fd106
 {{% endif -%}}
5fd106
 
5fd106
-{{% if product in ["rhel7", "ol7", "rhel8", "ol8", "rhel9"] or 'ubuntu' in product %}}
5fd106
-{{% set system_with_kernel_options_in_etc_default_grub = true %}}
5fd106
-{{% endif -%}}
5fd106
-
5fd106
 {{% if system_with_kernel_options_in_etc_default_grub -%}}
5fd106
 - name: Check {{{ ARG_NAME }}} argument exists
5fd106
   command: grep 'GRUB_CMDLINE_LINUX.*{{{ ARG_NAME }}}=' /etc/default/grub
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/bash.template b/shared/templates/grub2_bootloader_argument/bash.template
5fd106
index 817fd1fde23..b188d1e3689 100644
5fd106
--- a/shared/templates/grub2_bootloader_argument/bash.template
5fd106
+++ b/shared/templates/grub2_bootloader_argument/bash.template
5fd106
@@ -7,7 +7,7 @@
5fd106
 {{% set system_with_expanded_kernel_options_in_loader_entries = false -%}}
5fd106
 {{% set system_with_referenced_kernel_options_in_loader_entries = false -%}}
5fd106
 {{% set system_with_kernel_options_in_grubenv = false -%}}
5fd106
-{{% set system_with_kernel_options_in_etc_default_grub = false -%}}
5fd106
+{{% set system_with_kernel_options_in_etc_default_grub = true -%}}
5fd106
 {{% set system_with_expanded_kernel_options_in_grub_cfg = false -%}}
5fd106
 
5fd106
 {{% if product in ["rhel9"] %}}
5fd106
@@ -23,10 +23,6 @@
5fd106
 {{% set system_with_expanded_kernel_options_in_grub_cfg = true %}}
5fd106
 {{% endif -%}}
5fd106
 
5fd106
-{{% if product in ["rhel7", "ol7", "rhel8", "ol8", "rhel9"] or 'ubuntu' in product %}}
5fd106
-{{% set system_with_kernel_options_in_etc_default_grub = true %}}
5fd106
-{{% endif -%}}
5fd106
-
5fd106
 {{% macro update_etc_default_grub(arg_name_value) %}}
5fd106
 {{% if 'ubuntu' in product %}}
5fd106
 update-grub
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/oval.template b/shared/templates/grub2_bootloader_argument/oval.template
5fd106
index 24258a3bcbd..88fa7b7a3ee 100644
5fd106
--- a/shared/templates/grub2_bootloader_argument/oval.template
5fd106
+++ b/shared/templates/grub2_bootloader_argument/oval.template
5fd106
@@ -8,7 +8,7 @@
5fd106
 {{% set system_with_expanded_kernel_options_in_loader_entries = false -%}}
5fd106
 {{% set system_with_referenced_kernel_options_in_loader_entries = false -%}}
5fd106
 {{% set system_with_kernel_options_in_grubenv = false -%}}
5fd106
-{{% set system_with_kernel_options_in_etc_default_grub = false -%}}
5fd106
+{{% set system_with_kernel_options_in_etc_default_grub = true -%}}
5fd106
 {{% set system_with_expanded_kernel_options_in_grub_cfg = false -%}}
5fd106
 
5fd106
 {{% if product in ["rhel9"] -%}}
5fd106
@@ -24,10 +24,6 @@
5fd106
 {{% set system_with_expanded_kernel_options_in_grub_cfg = true %}}
5fd106
 {{%- endif -%}}
5fd106
 
5fd106
-{{%- if product in ["rhel7", "ol7", "rhel8", "ol8", "rhel9"] or 'ubuntu' in product %}}
5fd106
-{{% set system_with_kernel_options_in_etc_default_grub = true %}}
5fd106
-{{%- endif -%}}
5fd106
-
5fd106
 <def-group>
5fd106
   <definition class="compliance" id="{{{ _RULE_ID }}}" version="2">
5fd106
     {{{ oval_metadata("Ensure " + ARG_NAME_VALUE + " is configured in the kernel line in /etc/default/grub.") }}}
5fd106
5fd106
From fac0aeb351d7acab1112482d11a0be73df662496 Mon Sep 17 00:00:00 2001
5fd106
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
5fd106
Date: Fri, 11 Feb 2022 14:55:53 +0100
5fd106
Subject: [PATCH 3/5] Improve the template further
5fd106
5fd106
- Fix the $kernelopts regex - $ is not a word char.
5fd106
- Use grubby exclusively on RHEL systems and structure remediations differently than OVAL checks
5fd106
- Exclude the rescue.conf loader entry from checks, as it is not a boot entry for general use.
5fd106
---
5fd106
 .../grub2_entries_reference_kernelopts.xml    |  2 +-
5fd106
 .../ansible.template                          | 72 +------------------
5fd106
 .../grub2_bootloader_argument/bash.template   | 67 +++++------------
5fd106
 .../grub2_bootloader_argument/oval.template   |  7 +-
5fd106
 .../tests/invalid_rescue.pass.sh              |  6 ++
5fd106
 tests/test_rule_in_container.sh               |  2 +-
5fd106
 6 files changed, 33 insertions(+), 123 deletions(-)
5fd106
 create mode 100644 shared/templates/grub2_bootloader_argument/tests/invalid_rescue.pass.sh
5fd106
5fd106
diff --git a/shared/checks/oval/grub2_entries_reference_kernelopts.xml b/shared/checks/oval/grub2_entries_reference_kernelopts.xml
5fd106
index 1aec9fe64d2..30f3965a037 100644
5fd106
--- a/shared/checks/oval/grub2_entries_reference_kernelopts.xml
5fd106
+++ b/shared/checks/oval/grub2_entries_reference_kernelopts.xml
5fd106
@@ -19,7 +19,7 @@
5fd106
   <ind:textfilecontent54_object id="object_grub2_entries_reference_kernelopts" version="1">
5fd106
     <ind:path>/boot/loader/entries/</ind:path>
5fd106
     <ind:filename operation="pattern match">^.*\.conf$</ind:filename>
5fd106
-    <ind:pattern operation="pattern match">^options .*\b\$kernelopts\b.*$</ind:pattern>
5fd106
+    <ind:pattern operation="pattern match">^options(?:\s+.*)?\s+\$kernelopts\b.*$</ind:pattern>
5fd106
     <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>                                                                             
5fd106
   </ind:textfilecontent54_object>
5fd106
 </def-group>
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/ansible.template b/shared/templates/grub2_bootloader_argument/ansible.template
5fd106
index 46de9b465c2..db3b4430d4b 100644
5fd106
--- a/shared/templates/grub2_bootloader_argument/ansible.template
5fd106
+++ b/shared/templates/grub2_bootloader_argument/ansible.template
5fd106
@@ -4,75 +4,5 @@
5fd106
 # complexity = medium
5fd106
 # disruption = low
5fd106
 
5fd106
-{{#
5fd106
-   See the OVAL template for more comments.
5fd106
-   Product-specific categorization should be synced across all template content types
5fd106
--#}}
5fd106
-{{% set system_with_expanded_kernel_options_in_loader_entries = false -%}}
5fd106
-{{% set system_with_referenced_kernel_options_in_loader_entries = false -%}}
5fd106
-{{% set system_with_kernel_options_in_grubenv = false -%}}
5fd106
-{{% set system_with_kernel_options_in_etc_default_grub = true -%}}
5fd106
-{{% set system_with_expanded_kernel_options_in_grub_cfg = false -%}}
5fd106
-
5fd106
-{{% if product in ["rhel9"] %}}
5fd106
-{{% set system_with_expanded_kernel_options_in_loader_entries = true %}}
5fd106
-{{% endif -%}}
5fd106
-
5fd106
-{{% if product in ["rhel8"] %}}
5fd106
-{{% set system_with_referenced_kernel_options_in_loader_entries = true %}}
5fd106
-{{% set system_with_kernel_options_in_grubenv = true %}}
5fd106
-{{% endif -%}}
5fd106
-
5fd106
-{{% if product in ["rhel7", "ol7"] or 'ubuntu' in product %}}
5fd106
-{{% set system_with_expanded_kernel_options_in_grub_cfg = true %}}
5fd106
-{{% endif -%}}
5fd106
-
5fd106
-{{% if system_with_kernel_options_in_etc_default_grub -%}}
5fd106
-- name: Check {{{ ARG_NAME }}} argument exists
5fd106
-  command: grep 'GRUB_CMDLINE_LINUX.*{{{ ARG_NAME }}}=' /etc/default/grub
5fd106
-  failed_when: False
5fd106
-  register: argcheck
5fd106
-
5fd106
-- name: Replace existing {{{ ARG_NAME }}} argument
5fd106
-  replace:
5fd106
-      path: /etc/default/grub
5fd106
-      regexp: '{{{ ARG_NAME }}}=\w+'
5fd106
-      replace: '{{{ ARG_NAME_VALUE }}}'
5fd106
-  when: argcheck.rc == 0
5fd106
-
5fd106
-- name: Add {{{ ARG_NAME }}} argument
5fd106
-  replace:
5fd106
-      path: /etc/default/grub
5fd106
-      regexp: '(GRUB_CMDLINE_LINUX=.*)"'
5fd106
-      replace: '\1 {{{ ARG_NAME_VALUE }}}"'
5fd106
-  when: argcheck.rc != 0
5fd106
-
5fd106
-- name: Update bootloader menu
5fd106
+- name: Update grub defaults and the bootloader menu
5fd106
   command: /sbin/grubby --update-kernel=ALL --args="{{{ ARG_NAME_VALUE }}}"
5fd106
-
5fd106
-{{%- endif %}}
5fd106
-
5fd106
-{{% if system_with_kernel_options_in_grubenv -%}}
5fd106
-
5fd106
-- name: Get current kernel parameters
5fd106
-  ansible.builtin.shell:
5fd106
-    cmd: '/usr/bin/grub2-editenv - list | grep "kernelopts="'
5fd106
-  register: kernelopts
5fd106
-  ignore_errors: yes
5fd106
-  changed_when: False
5fd106
-
5fd106
-- name: Update the bootloader menu
5fd106
-  command: /usr/bin/grub2-editenv - set "{{ item }} {{{ ARG_NAME_VALUE }}}"
5fd106
-  with_items: "{{ kernelopts.stdout_lines | select('match', '^kernelopts.*') | list }}"
5fd106
-  when:
5fd106
-    - kernelopts.rc == 0
5fd106
-    - kernelopts.stdout_lines is defined
5fd106
-    - kernelopts.stdout_lines | length > 0
5fd106
-    - kernelopts.stdout | regex_search('^kernelopts=(?:.*\s)?{{{ ARG_NAME_VALUE }}}(?:\s.*)?$', multiline=True) is none
5fd106
-
5fd106
-- name: Update the bootloader menu when there are no entries previously set
5fd106
-  command: /usr/bin/grub2-editenv - set "kernelopts={{{ ARG_NAME_VALUE }}}"
5fd106
-  when:
5fd106
-    - kernelopts.rc != 0
5fd106
-
5fd106
-{{%- endif %}}
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/bash.template b/shared/templates/grub2_bootloader_argument/bash.template
5fd106
index b188d1e3689..5f97efd498f 100644
5fd106
--- a/shared/templates/grub2_bootloader_argument/bash.template
5fd106
+++ b/shared/templates/grub2_bootloader_argument/bash.template
5fd106
@@ -4,59 +4,28 @@
5fd106
    Product-specific categorization should be synced across all template content types
5fd106
 -#}}
5fd106
 
5fd106
-{{% set system_with_expanded_kernel_options_in_loader_entries = false -%}}
5fd106
-{{% set system_with_referenced_kernel_options_in_loader_entries = false -%}}
5fd106
-{{% set system_with_kernel_options_in_grubenv = false -%}}
5fd106
-{{% set system_with_kernel_options_in_etc_default_grub = true -%}}
5fd106
-{{% set system_with_expanded_kernel_options_in_grub_cfg = false -%}}
5fd106
+{{% set grub_helper_executable = "grubby" -%}}
5fd106
+{{% set grub_helper_args = ["--update-kernel=ALL", "--args=" ~ ARG_NAME_VALUE] -%}}
5fd106
 
5fd106
-{{% if product in ["rhel9"] %}}
5fd106
-{{% set system_with_expanded_kernel_options_in_loader_entries = true %}}
5fd106
-{{% endif -%}}
5fd106
-
5fd106
-{{% if product in ["rhel8"] %}}
5fd106
-{{% set system_with_referenced_kernel_options_in_loader_entries = true %}}
5fd106
-{{% set system_with_kernel_options_in_grubenv = true %}}
5fd106
-{{% endif -%}}
5fd106
-
5fd106
-{{% if product in ["rhel7", "ol7"] or 'ubuntu' in product %}}
5fd106
-{{% set system_with_expanded_kernel_options_in_grub_cfg = true %}}
5fd106
-{{% endif -%}}
5fd106
-
5fd106
-{{% macro update_etc_default_grub(arg_name_value) %}}
5fd106
-{{% if 'ubuntu' in product %}}
5fd106
-update-grub
5fd106
-{{% else %}}
5fd106
-grubby --update-kernel=ALL --args="{{{ arg_name_value }}}"
5fd106
-{{% endif %}}
5fd106
-{{% endmacro -%}}
5fd106
-
5fd106
-{{% if system_with_kernel_options_in_etc_default_grub %}}
5fd106
-{{% if '/' in ARG_NAME %}}
5fd106
-{{{ raise("ARG_NAME (" + ARG_NAME + ") uses sed path separator (/) in " + rule_id) }}}
5fd106
-{{% elif '/' in ARG_NAME_VALUE %}}
5fd106
-{{{ raise("ARG_NAME_VALUE (" + ARG_NAME_VALUE + ") uses sed path separator (/) in " + rule_id) }}}
5fd106
-{{% endif %}}
5fd106
+{{%- macro update_etc_default_grub_manually() -%}}
5fd106
 # Correct the form of default kernel command line in GRUB
5fd106
 if grep -q '^GRUB_CMDLINE_LINUX=.*{{{ ARG_NAME }}}=.*"'  '/etc/default/grub' ; then
5fd106
-	# modify the GRUB command-line if an {{{ ARG_NAME }}}= arg already exists
5fd106
-	sed -i 's/\(^GRUB_CMDLINE_LINUX=".*\){{{ ARG_NAME }}}=[^[:space:]]*\(.*"\)/\1 {{{ ARG_NAME_VALUE }}} \2/'  '/etc/default/grub'
5fd106
+       # modify the GRUB command-line if an {{{ ARG_NAME }}}= arg already exists
5fd106
+       sed -i 's/\(^GRUB_CMDLINE_LINUX=".*\){{{ ARG_NAME }}}=[^[:space:]]*\(.*"\)/\1 {{{ ARG_NAME_VALUE }}} \2/'  '/etc/default/grub'
5fd106
 else
5fd106
-	# no {{{ ARG_NAME }}}=arg is present, append it
5fd106
-	sed -i 's/\(^GRUB_CMDLINE_LINUX=".*\)"/\1 {{{ ARG_NAME_VALUE }}}"/'  '/etc/default/grub'
5fd106
+       # no {{{ ARG_NAME }}}=arg is present, append it
5fd106
+       sed -i 's/\(^GRUB_CMDLINE_LINUX=".*\)"/\1 {{{ ARG_NAME_VALUE }}}"/'  '/etc/default/grub'
5fd106
 fi
5fd106
-{{% endif %}}
5fd106
+{{%- endmacro %}}
5fd106
+
5fd106
+{{% if 'ubuntu' in product %}}
5fd106
+{{{ update_etc_default_grub_manually() }}}
5fd106
+{{% set grub_helper_executable = "update-grub" -%}}
5fd106
+{{% endif -%}}
5fd106
 
5fd106
-{{{ update_etc_default_grub(ARG_NAME_VALUE) }}}
5fd106
+{{% if product in ["rhel8", "ol8"] %}}
5fd106
+{{# Suppress the None output of append -#}}
5fd106
+{{{ grub_helper_args.append("--env=/boot/grub2/grubenv") or "" -}}}
5fd106
+{{% endif -%}}
5fd106
 
5fd106
-{{% if system_with_kernel_options_in_grubenv -%}}
5fd106
-# Correct grub2 kernelopts value using grub2-editenv
5fd106
-existing_kernelopts="$(grub2-editenv - list | grep kernelopts)"
5fd106
-if ! printf '%s' "$existing_kernelopts" | grep -qE '^kernelopts=(.*\s)?{{{ ARG_NAME_VALUE }}}(\s.*)?$'; then
5fd106
-  if test -n "$existing_kernelopts"; then
5fd106
-    grub2-editenv - set "$existing_kernelopts {{{ ARG_NAME_VALUE }}}"
5fd106
-  else
5fd106
-    grub2-editenv - set "kernelopts={{{ ARG_NAME_VALUE }}}"
5fd106
-  fi
5fd106
-fi
5fd106
-{{% endif %}}
5fd106
+{{{ grub_helper_executable }}} {{{ " ".join(grub_helper_args) }}}
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/oval.template b/shared/templates/grub2_bootloader_argument/oval.template
5fd106
index 88fa7b7a3ee..6981cc14045 100644
5fd106
--- a/shared/templates/grub2_bootloader_argument/oval.template
5fd106
+++ b/shared/templates/grub2_bootloader_argument/oval.template
5fd106
@@ -1,6 +1,6 @@
5fd106
 {{#-
5fd106
   We set defaults to "off", and products should enable relevant ones depending on how the product configures grub.
5fd106
-   - /boot/loader/entries/* may not exist don't exist
5fd106
+   - /boot/loader/entries/* may not exist.
5fd106
    - If they exist, they can reference variables defined in grubenv, or they can contain literal args
5fd106
    - The grub cfg may either use those loader entries, or it can contain literal values as well
5fd106
    - Kernel opts can be stored in /etc/default/grub so they are persistent between kernel upgrades
5fd106
@@ -116,7 +116,12 @@
5fd106
     <ind:filename operation="pattern match">^.*\.conf$</ind:filename>
5fd106
     <ind:pattern operation="pattern match">^options (.*)$</ind:pattern>
5fd106
     <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
5fd106
+    <filter action="exclude">state_grub2_rescue_entry_for_{{{ _RULE_ID }}}</filter>
5fd106
   </ind:textfilecontent54_object>
5fd106
+
5fd106
+  <ind:textfilecontent54_state id="state_grub2_rescue_entry_for_{{{ _RULE_ID }}}" version="1">
5fd106
+    <ind:filename>rescue.conf</ind:filename>
5fd106
+  </ind:textfilecontent54_state>
5fd106
 {{%- endif %}}
5fd106
 
5fd106
 {{%- if system_with_expanded_kernel_options_in_grub_cfg %}}
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/tests/invalid_rescue.pass.sh b/shared/templates/grub2_bootloader_argument/tests/invalid_rescue.pass.sh
5fd106
new file mode 100644
5fd106
index 00000000000..ee6e2c67f34
5fd106
--- /dev/null
5fd106
+++ b/shared/templates/grub2_bootloader_argument/tests/invalid_rescue.pass.sh
5fd106
@@ -0,0 +1,6 @@
5fd106
+# platform = Red Hat Enterprise Linux 7,Red Hat Enterprise Linux 9
5fd106
+# packages = grub2,grubby
5fd106
+
5fd106
+{{{ grub2_bootloader_argument_remediation(ARG_NAME, ARG_NAME_VALUE) }}}
5fd106
+
5fd106
+echo "I am an invalid boot entry, but nobody should care, because I am rescue" > /boot/loader/entries/trololol-rescue.conf
5fd106
diff --git a/tests/test_rule_in_container.sh b/tests/test_rule_in_container.sh
5fd106
index 395fc4e856c..a8691ca7463 100755
5fd106
--- a/tests/test_rule_in_container.sh
5fd106
+++ b/tests/test_rule_in_container.sh
5fd106
@@ -221,7 +221,7 @@ additional_args=()
5fd106
 test "$_arg_dontclean" = on && additional_args+=(--dontclean)
5fd106
 
5fd106
 # Don't act on the default value.
5fd106
-test -n "$_arg_scenarios" && additional_args+=(--scenario "'$_arg_scenarios'")
5fd106
+test -n "$_arg_scenarios" && additional_args+=(--scenario "$_arg_scenarios")
5fd106
 
5fd106
 test -n "$_arg_datastream" && additional_args+=(--datastream "$_arg_datastream")
5fd106
 
5fd106
5fd106
From 8dda6030dea885c7c7e7e8f1024f5f2edf5bc36c Mon Sep 17 00:00:00 2001
5fd106
From: Matej Tyc <matyc@redhat.com>
5fd106
Date: Mon, 14 Feb 2022 13:45:09 +0100
5fd106
Subject: [PATCH 4/5] Add support for checks of both BIOS/UEFI systems
5fd106
5fd106
---
5fd106
 .../grub2_bootloader_argument/oval.template   | 57 +++++++++++++++----
5fd106
 1 file changed, 46 insertions(+), 11 deletions(-)
5fd106
5fd106
diff --git a/shared/templates/grub2_bootloader_argument/oval.template b/shared/templates/grub2_bootloader_argument/oval.template
5fd106
index 6981cc14045..71367465663 100644
5fd106
--- a/shared/templates/grub2_bootloader_argument/oval.template
5fd106
+++ b/shared/templates/grub2_bootloader_argument/oval.template
5fd106
@@ -10,6 +10,7 @@
5fd106
 {{% set system_with_kernel_options_in_grubenv = false -%}}
5fd106
 {{% set system_with_kernel_options_in_etc_default_grub = true -%}}
5fd106
 {{% set system_with_expanded_kernel_options_in_grub_cfg = false -%}}
5fd106
+{{% set system_with_bios_and_uefi_support = false -%}}
5fd106
 
5fd106
 {{% if product in ["rhel9"] -%}}
5fd106
 {{% set system_with_expanded_kernel_options_in_loader_entries = true %}}
5fd106
@@ -24,13 +25,25 @@
5fd106
 {{% set system_with_expanded_kernel_options_in_grub_cfg = true %}}
5fd106
 {{%- endif -%}}
5fd106
 
5fd106
+{{% if grub2_uefi_boot_path and grub2_uefi_boot_path != grub2_boot_path -%}}
5fd106
+{{% set system_with_bios_and_uefi_support = true %}}
5fd106
+{{%- endif -%}}
5fd106
+
5fd106
 <def-group>
5fd106
   <definition class="compliance" id="{{{ _RULE_ID }}}" version="2">
5fd106
     {{{ oval_metadata("Ensure " + ARG_NAME_VALUE + " is configured in the kernel line in /etc/default/grub.") }}}
5fd106
     <criteria operator="AND">
5fd106
       {{% if system_with_kernel_options_in_grubenv -%}}
5fd106
+      {{% if system_with_bios_and_uefi_support -%}}
5fd106
+      <criteria operator="OR">
5fd106
+      {{%- endif %}}
5fd106
         
5fd106
         comment="Check if {{{ ARG_NAME_VALUE }}} is present in the GRUB2 environment variable block in {{{ grub2_boot_path }}}/grubenv" />
5fd106
+      {{% if system_with_bios_and_uefi_support -%}}
5fd106
+        
5fd106
+        comment="Check if {{{ ARG_NAME_VALUE }}} is present in the GRUB2 environment variable block in {{{ grub2_uefi_boot_path }}}/grubenv" />
5fd106
+      </criteria>
5fd106
+      {{%- endif %}}
5fd106
       {{%- endif %}}
5fd106
       {{% if system_with_referenced_kernel_options_in_loader_entries -%}}
5fd106
         <extend_definition comment="check kernel command line parameters for referenced boot entries reference the $kernelopts variable" definition_ref="grub2_entries_reference_kernelopts" />
5fd106
@@ -40,8 +53,16 @@
5fd106
                      comment="Check if {{{ ARG_NAME_VALUE }}} is present in the boot parameters in the /boot/loader/entries/*.conf" />
5fd106
       {{%- endif %}}
5fd106
       {{% if system_with_expanded_kernel_options_in_grub_cfg -%}}
5fd106
+          {{% if system_with_bios_and_uefi_support -%}}
5fd106
+          <criteria operator="OR">
5fd106
+          {{%- endif %}}
5fd106
           
5fd106
           comment="Check if {{{ ARG_NAME_VALUE }}} is present in the boot parameters in the {{{ grub2_boot_path }}}/grub.cfg for all kernels" />
5fd106
+          {{% if system_with_bios_and_uefi_support -%}}
5fd106
+          
5fd106
+          comment="Check if {{{ ARG_NAME_VALUE }}} is present in the boot parameters in the {{{ grub2_uefi_boot_path }}}/grub.cfg for all kernels" />
5fd106
+          </criteria>
5fd106
+          {{%- endif %}}
5fd106
       {{%- endif %}}
5fd106
       {{% if system_with_kernel_options_in_etc_default_grub -%}}
5fd106
         <criteria operator="OR">
5fd106
@@ -88,19 +109,26 @@
5fd106
 {{%- endif %}}
5fd106
 
5fd106
 {{%- if system_with_kernel_options_in_grubenv %}}
5fd106
-  
5fd106
-  comment="check for kernel command line parameters {{{ ARG_NAME_VALUE }}} in {{{ grub2_boot_path }}}/grubenv for all kernels"
5fd106
+{{%- macro test_and_object_for_kernel_options_grub_env(base_name, path) %}}
5fd106
+  
5fd106
+  comment="check for kernel command line parameters {{{ ARG_NAME_VALUE }}} in {{{ path }}} for all kernels"
5fd106
   check="all" check_existence="all_exist" version="1">
5fd106
-    <ind:object object_ref="object_grub2_{{{ SANITIZED_ARG_NAME }}}_argument_grub_env" />
5fd106
+    <ind:object object_ref="object_{{{ base_name }}}" />
5fd106
     <ind:state state_ref="state_grub2_{{{ SANITIZED_ARG_NAME }}}_argument" />
5fd106
   </ind:textfilecontent54_test>
5fd106
 
5fd106
-  
5fd106
+  
5fd106
   version="1">
5fd106
-    <ind:filepath>{{{ grub2_boot_path }}}/grubenv</ind:filepath>
5fd106
+    <ind:filepath>{{{ path }}}</ind:filepath>
5fd106
     <ind:pattern operation="pattern match">^kernelopts=(.*)$</ind:pattern>
5fd106
     <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
5fd106
   </ind:textfilecontent54_object>
5fd106
+{{%- endmacro %}}
5fd106
+
5fd106
+{{{ test_and_object_for_kernel_options_grub_env("grub2_" ~ SANITIZED_ARG_NAME ~ "_argument_grub_env", grub2_boot_path ~ "/grubenv") }}}
5fd106
+{{% if system_with_bios_and_uefi_support -%}}
5fd106
+{{{ test_and_object_for_kernel_options_grub_env("grub2_" ~ SANITIZED_ARG_NAME ~ "_argument_grub_env_uefi", grub2_uefi_boot_path ~ "/grubenv") }}}
5fd106
+{{%- endif %}}
5fd106
 {{%- endif %}}
5fd106
 
5fd106
 {{%- if system_with_expanded_kernel_options_in_loader_entries %}}
5fd106
@@ -120,21 +148,22 @@
5fd106
   </ind:textfilecontent54_object>
5fd106
 
5fd106
   <ind:textfilecontent54_state id="state_grub2_rescue_entry_for_{{{ _RULE_ID }}}" version="1">
5fd106
-    <ind:filename>rescue.conf</ind:filename>
5fd106
+    <ind:filename operation="pattern match">.*rescue.conf$</ind:filename>
5fd106
   </ind:textfilecontent54_state>
5fd106
 {{%- endif %}}
5fd106
 
5fd106
 {{%- if system_with_expanded_kernel_options_in_grub_cfg %}}
5fd106
-  
5fd106
-  comment="check kernel command line parameters for {{{ ARG_NAME_VALUE }}} in {{{ grub2_boot_path }}}/grub.cfg for all kernels"
5fd106
+{{%- macro test_and_object_for_kernel_options_grub_cfg(base_name, path) %}}
5fd106
+  
5fd106
+  comment="check kernel command line parameters for {{{ ARG_NAME_VALUE }}} in {{{ path }}} for all kernels"
5fd106
   check="all" check_existence="all_exist" version="1">
5fd106
-    <ind:object object_ref="object_grub2_{{{ SANITIZED_ARG_NAME }}}_argument_grub_cfg" />
5fd106
+    <ind:object object_ref="object_{{{ base_name }}}" />
5fd106
     <ind:state state_ref="state_grub2_{{{ SANITIZED_ARG_NAME }}}_argument" />
5fd106
   </ind:textfilecontent54_test>
5fd106
 
5fd106
-  
5fd106
+  
5fd106
   version="1">
5fd106
-    <ind:filepath>{{{ grub2_boot_path }}}/grub.cfg</ind:filepath>
5fd106
+    <ind:filepath>{{{ path }}}</ind:filepath>
5fd106
     {{% if product in ["rhel7"] or 'ubuntu' in product %}}
5fd106
       <ind:pattern operation="pattern match">^.*/vmlinuz.*(root=.*)$</ind:pattern>
5fd106
     {{% else %}}
5fd106
@@ -142,6 +171,12 @@
5fd106
     {{% endif %}}
5fd106
     <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
5fd106
   </ind:textfilecontent54_object>
5fd106
+{{%- endmacro %}}
5fd106
+
5fd106
+{{{ test_and_object_for_kernel_options_grub_cfg("grub2_" + SANITIZED_ARG_NAME + "_argument_grub_cfg", grub2_boot_path ~ "/grub.cfg") }}}
5fd106
+{{% if system_with_bios_and_uefi_support -%}}
5fd106
+{{{ test_and_object_for_kernel_options_grub_cfg("grub2_" + SANITIZED_ARG_NAME + "_argument_grub_cfg_uefi", grub2_uefi_boot_path ~ "/grub.cfg") }}}
5fd106
+{{%- endif %}}
5fd106
 {{%- endif %}}
5fd106
 
5fd106
   
5fd106
5fd106
From df44b5d7017328d05c0671397edcfed019a2a448 Mon Sep 17 00:00:00 2001
5fd106
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
5fd106
Date: Mon, 14 Feb 2022 14:49:34 +0100
5fd106
Subject: [PATCH 5/5] Correct test scenario metadata
5fd106
5fd106
- Grubenv doesn't relate to anything else than RHEL8
5fd106
- The grubby remediation has different behavior in corner-cases
5fd106
  that are technically unsupported, so the corresponding test scenario has been dropped.
5fd106
---
5fd106
 .../grub2_audit_argument/tests/blank_grubenv_rhel8.fail.sh      | 1 +
5fd106
 .../auditing/grub2_audit_argument/tests/correct_grubenv.pass.sh | 2 +-
5fd106
 2 files changed, 2 insertions(+), 1 deletion(-)
5fd106
5fd106
diff --git a/linux_os/guide/system/auditing/grub2_audit_argument/tests/blank_grubenv_rhel8.fail.sh b/linux_os/guide/system/auditing/grub2_audit_argument/tests/blank_grubenv_rhel8.fail.sh
5fd106
index 5af2acc317e..956c8ac79fd 100644
5fd106
--- a/linux_os/guide/system/auditing/grub2_audit_argument/tests/blank_grubenv_rhel8.fail.sh
5fd106
+++ b/linux_os/guide/system/auditing/grub2_audit_argument/tests/blank_grubenv_rhel8.fail.sh
5fd106
@@ -1,6 +1,7 @@
5fd106
 #!/bin/bash
5fd106
 
5fd106
 # platform = Red Hat Enterprise Linux 8
5fd106
+# remediation = none
5fd106
 
5fd106
 # Removes audit argument from kernel command line in /boot/grub2/grubenv
5fd106
 file="/boot/grub2/grubenv"
5fd106
diff --git a/linux_os/guide/system/auditing/grub2_audit_argument/tests/correct_grubenv.pass.sh b/linux_os/guide/system/auditing/grub2_audit_argument/tests/correct_grubenv.pass.sh
5fd106
index 0ec9a1d6e38..9823b08dff9 100644
5fd106
--- a/linux_os/guide/system/auditing/grub2_audit_argument/tests/correct_grubenv.pass.sh
5fd106
+++ b/linux_os/guide/system/auditing/grub2_audit_argument/tests/correct_grubenv.pass.sh
5fd106
@@ -1,4 +1,4 @@
5fd106
 #!/bin/bash
5fd106
-# platform = Red Hat Enterprise Linux 8,Red Hat Enterprise Linux 9
5fd106
+# platform = Red Hat Enterprise Linux 8
5fd106
 
5fd106
 grub2-editenv - set "$(grub2-editenv - list | grep kernelopts) audit=1"