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

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