Blame SOURCES/scap-security-guide-0.1.64-add_platform_for_partition_existence-PR_9204.patch

792d3d
From b4291642f301c18b33ad9b722f0f26490bb55047 Mon Sep 17 00:00:00 2001
792d3d
From: Matej Tyc <matyc@redhat.com>
792d3d
Date: Thu, 21 Jul 2022 16:42:41 +0200
792d3d
Subject: [PATCH 1/3] Add platforms for partition existence
792d3d
792d3d
---
792d3d
 shared/applicability/general.yml              | 14 +++++++++++++
792d3d
 .../checks/oval/installed_env_mounts_tmp.xml  | 10 +++++++++
792d3d
 .../oval/installed_env_mounts_var_tmp.xml     | 10 +++++++++
792d3d
 shared/macros/10-ansible.jinja                |  5 +++++
792d3d
 shared/macros/10-bash.jinja                   |  5 +++++
792d3d
 shared/macros/10-oval.jinja                   | 21 +++++++++++++++++++
792d3d
 6 files changed, 65 insertions(+)
792d3d
 create mode 100644 shared/checks/oval/installed_env_mounts_tmp.xml
792d3d
 create mode 100644 shared/checks/oval/installed_env_mounts_var_tmp.xml
792d3d
792d3d
diff --git a/shared/applicability/general.yml b/shared/applicability/general.yml
792d3d
index 2d23d753148..e2f5d04ce00 100644
792d3d
--- a/shared/applicability/general.yml
792d3d
+++ b/shared/applicability/general.yml
792d3d
@@ -77,6 +77,20 @@ cpes:
792d3d
       bash_conditional: {{{ bash_pkg_conditional("pam") }}}
792d3d
       ansible_conditional: {{{ ansible_pkg_conditional("pam") }}}
792d3d
 
792d3d
+  - partition-var-tmp:
792d3d
+      name: "cpe:/a:partition-var-tmp"
792d3d
+      title: "There is a /var/tmp partition"
792d3d
+      check_id: installed_env_mounts_var_tmp
792d3d
+      bash_conditional: {{{ bash_partition_conditional("/var/tmp") }}}
792d3d
+      ansible_conditional: {{{ ansible_partition_conditional("/var/tmp") }}}
792d3d
+
792d3d
+  - partition-tmp:
792d3d
+      name: "cpe:/a:partition-tmp"
792d3d
+      title: "There is a /tmp partition"
792d3d
+      check_id: installed_env_mounts_tmp
792d3d
+      bash_conditional: {{{ bash_partition_conditional("/tmp") }}}
792d3d
+      ansible_conditional: {{{ ansible_partition_conditional("/tmp") }}}
792d3d
+
792d3d
   - polkit:
792d3d
       name: "cpe:/a:polkit"
792d3d
       title: "Package polkit is installed"
792d3d
diff --git a/shared/checks/oval/installed_env_mounts_tmp.xml b/shared/checks/oval/installed_env_mounts_tmp.xml
792d3d
new file mode 100644
792d3d
index 00000000000..c1bcd6b2431
792d3d
--- /dev/null
792d3d
+++ b/shared/checks/oval/installed_env_mounts_tmp.xml
792d3d
@@ -0,0 +1,10 @@
792d3d
+<def-group>
792d3d
+  <definition class="inventory" id="installed_env_mounts_tmp" version="1">
792d3d
+    {{{ oval_metadata("", title="Partition /tmp exists", affected_platforms=[full_name]) }}}
792d3d
+    <criteria>
792d3d
+       {{{ partition_exists_criterion("/tmp") }}}
792d3d
+    </criteria>
792d3d
+  </definition>
792d3d
+
792d3d
+  {{{ partition_exists_tos("/tmp") }}}
792d3d
+</def-group>
792d3d
diff --git a/shared/checks/oval/installed_env_mounts_var_tmp.xml b/shared/checks/oval/installed_env_mounts_var_tmp.xml
792d3d
new file mode 100644
792d3d
index 00000000000..a72f49c8a8f
792d3d
--- /dev/null
792d3d
+++ b/shared/checks/oval/installed_env_mounts_var_tmp.xml
792d3d
@@ -0,0 +1,10 @@
792d3d
+<def-group>
792d3d
+  <definition class="inventory" id="installed_env_mounts_var_tmp" version="1">
792d3d
+    {{{ oval_metadata("", title="Partition /var/tmp exists", affected_platforms=[full_name]) }}}
792d3d
+    <criteria>
792d3d
+       {{{ partition_exists_criterion("/var/tmp") }}}
792d3d
+    </criteria>
792d3d
+  </definition>
792d3d
+
792d3d
+  {{{ partition_exists_tos("/var/tmp") }}}
792d3d
+</def-group>
792d3d
diff --git a/shared/macros/10-ansible.jinja b/shared/macros/10-ansible.jinja
792d3d
index 2d24f730d3f..478f0072bc7 100644
792d3d
--- a/shared/macros/10-ansible.jinja
792d3d
+++ b/shared/macros/10-ansible.jinja
792d3d
@@ -1439,3 +1439,8 @@ Part of the grub2_bootloader_argument_absent template.
792d3d
   when:
792d3d
     - result_pam_file_present.stat.exists
792d3d
 {{%- endmacro -%}}
792d3d
+
792d3d
+
792d3d
+{{%- macro ansible_partition_conditional(path) -%}}
792d3d
+"ansible_facts.ansible_mounts | json_query(\"[?mount=='{{{ path }}}'].mount\") | length == 1"
792d3d
+{{%- endmacro -%}}
792d3d
diff --git a/shared/macros/10-bash.jinja b/shared/macros/10-bash.jinja
792d3d
index 94c3c6f9570..6a7fb165fd2 100644
792d3d
--- a/shared/macros/10-bash.jinja
792d3d
+++ b/shared/macros/10-bash.jinja
792d3d
@@ -2085,3 +2085,8 @@ else
792d3d
     echo "{{{ pam_file }}} was not found" >&2
792d3d
 fi
792d3d
 {{%- endmacro -%}}
792d3d
+
792d3d
+
792d3d
+{{%- macro bash_partition_conditional(path) -%}}
792d3d
+'findmnt --mountpoint "{{{ path }}}" > /dev/null'
792d3d
+{{%- endmacro -%}}
792d3d
diff --git a/shared/macros/10-oval.jinja b/shared/macros/10-oval.jinja
792d3d
index c8d7bbeffb7..1ec93b6ef7d 100644
792d3d
--- a/shared/macros/10-oval.jinja
792d3d
+++ b/shared/macros/10-oval.jinja
792d3d
@@ -926,3 +926,24 @@ Generates the :code:`<affected>` tag for OVAL check using correct product platfo
792d3d
 {{%- else %}}
792d3d
   {{%- set user_list="nobody" %}}
792d3d
 {{%- endif %}}
792d3d
+
792d3d
+
792d3d
+{{%- macro partition_exists_criterion(path) %}}
792d3d
+{{%- set escaped_path = path | replace("/", "_") %}}
792d3d
+      <criterion comment="The path {{{ path }}} is a partition's mount point" test_ref="test_partition_{{{ escaped_path  }}}_exists" />
792d3d
+{{%- endmacro %}}
792d3d
+
792d3d
+{{%- macro partition_exists_tos(path) %}}
792d3d
+{{%- set escaped_path = path | replace("/", "_") %}}
792d3d
+  
792d3d
+      comment="Partition {{{ path }}} exists"
792d3d
+      id="test_partition_{{{ escaped_path }}}_exists"
792d3d
+  version="1">
792d3d
+    <linux:object object_ref="object_partition_{{{ escaped_path }}}_exists" />
792d3d
+    {{#- <linux:partition_state state_ref="" /> #}}
792d3d
+  </linux:partition_test>
792d3d
+
792d3d
+  <linux:partition_object id="object_partition_{{{ escaped_path }}}_exists" version="1">
792d3d
+    <linux:mount_point>{{{ path }}}</linux:mount_point>
792d3d
+  </linux:partition_object>
792d3d
+{{%- endmacro %}}
792d3d
792d3d
From 704da46c44f50c93acbfe172212f1687763013b0 Mon Sep 17 00:00:00 2001
792d3d
From: Matej Tyc <matyc@redhat.com>
792d3d
Date: Thu, 21 Jul 2022 16:43:21 +0200
792d3d
Subject: [PATCH 2/3] Use partition exist platforms on a real rule
792d3d
792d3d
---
792d3d
 .../partitions/mount_option_var_tmp_nodev/rule.yml           | 3 ++-
792d3d
 .../mount_option_var_tmp_nodev/tests/notapplicable.pass.sh   | 5 +++++
792d3d
 2 files changed, 7 insertions(+), 1 deletion(-)
792d3d
 create mode 100644 linux_os/guide/system/permissions/partitions/mount_option_var_tmp_nodev/tests/notapplicable.pass.sh
792d3d
792d3d
diff --git a/linux_os/guide/system/permissions/partitions/mount_option_var_tmp_nodev/rule.yml b/linux_os/guide/system/permissions/partitions/mount_option_var_tmp_nodev/rule.yml
792d3d
index 8ee8c8b12e0..741d0973283 100644
792d3d
--- a/linux_os/guide/system/permissions/partitions/mount_option_var_tmp_nodev/rule.yml
792d3d
+++ b/linux_os/guide/system/permissions/partitions/mount_option_var_tmp_nodev/rule.yml
792d3d
@@ -38,7 +38,8 @@ references:
792d3d
     stigid@ol8: OL08-00-040132
792d3d
     stigid@rhel8: RHEL-08-040132
792d3d
 
792d3d
-platform: machine
792d3d
+platforms:
792d3d
+  - machine and partition-var-tmp
792d3d
 
792d3d
 template:
792d3d
     name: mount_option
792d3d
diff --git a/linux_os/guide/system/permissions/partitions/mount_option_var_tmp_nodev/tests/notapplicable.pass.sh b/linux_os/guide/system/permissions/partitions/mount_option_var_tmp_nodev/tests/notapplicable.pass.sh
792d3d
new file mode 100644
792d3d
index 00000000000..241c0103d82
792d3d
--- /dev/null
792d3d
+++ b/linux_os/guide/system/permissions/partitions/mount_option_var_tmp_nodev/tests/notapplicable.pass.sh
792d3d
@@ -0,0 +1,5 @@
792d3d
+#!/bin/bash
792d3d
+
792d3d
+. $SHARED/partition.sh
792d3d
+
792d3d
+clean_up_partition /var/tmp  # Remove the partition from the system, and unmount it
792d3d
792d3d
From 7b3c9eb40d362ffcfda542cc2b267bce13e25d5a Mon Sep 17 00:00:00 2001
792d3d
From: Matej Tyc <matyc@redhat.com>
792d3d
Date: Wed, 10 Aug 2022 11:32:38 +0200
792d3d
Subject: [PATCH 3/3] Improve code style
792d3d
792d3d
- Improve description of OVAL macro
792d3d
- Use the escape_id filter to produce IDs
792d3d
---
792d3d
 shared/checks/oval/installed_env_mounts_tmp.xml     | 2 +-
792d3d
 shared/checks/oval/installed_env_mounts_var_tmp.xml | 2 +-
792d3d
 shared/macros/10-oval.jinja                         | 7 +++----
792d3d
 3 files changed, 5 insertions(+), 6 deletions(-)
792d3d
792d3d
diff --git a/shared/checks/oval/installed_env_mounts_tmp.xml b/shared/checks/oval/installed_env_mounts_tmp.xml
792d3d
index c1bcd6b2431..edd8ad050f5 100644
792d3d
--- a/shared/checks/oval/installed_env_mounts_tmp.xml
792d3d
+++ b/shared/checks/oval/installed_env_mounts_tmp.xml
792d3d
@@ -6,5 +6,5 @@
792d3d
     </criteria>
792d3d
   </definition>
792d3d
 
792d3d
-  {{{ partition_exists_tos("/tmp") }}}
792d3d
+  {{{ partition_exists_test_object("/tmp") }}}
792d3d
 </def-group>
792d3d
diff --git a/shared/checks/oval/installed_env_mounts_var_tmp.xml b/shared/checks/oval/installed_env_mounts_var_tmp.xml
792d3d
index a72f49c8a8f..cf9aafbdb04 100644
792d3d
--- a/shared/checks/oval/installed_env_mounts_var_tmp.xml
792d3d
+++ b/shared/checks/oval/installed_env_mounts_var_tmp.xml
792d3d
@@ -6,5 +6,5 @@
792d3d
     </criteria>
792d3d
   </definition>
792d3d
 
792d3d
-  {{{ partition_exists_tos("/var/tmp") }}}
792d3d
+  {{{ partition_exists_test_object("/var/tmp") }}}
792d3d
 </def-group>
792d3d
diff --git a/shared/macros/10-oval.jinja b/shared/macros/10-oval.jinja
792d3d
index 1ec93b6ef7d..f302091f7df 100644
792d3d
--- a/shared/macros/10-oval.jinja
792d3d
+++ b/shared/macros/10-oval.jinja
792d3d
@@ -929,18 +929,17 @@ Generates the :code:`<affected>` tag for OVAL check using correct product platfo
792d3d
 
792d3d
 
792d3d
 {{%- macro partition_exists_criterion(path) %}}
792d3d
-{{%- set escaped_path = path | replace("/", "_") %}}
792d3d
+{{%- set escaped_path = path | escape_id %}}
792d3d
       <criterion comment="The path {{{ path }}} is a partition's mount point" test_ref="test_partition_{{{ escaped_path  }}}_exists" />
792d3d
 {{%- endmacro %}}
792d3d
 
792d3d
-{{%- macro partition_exists_tos(path) %}}
792d3d
-{{%- set escaped_path = path | replace("/", "_") %}}
792d3d
+{{%- macro partition_exists_test_object(path) %}}
792d3d
+{{%- set escaped_path = path | escape_id %}}
792d3d
   
792d3d
       comment="Partition {{{ path }}} exists"
792d3d
       id="test_partition_{{{ escaped_path }}}_exists"
792d3d
   version="1">
792d3d
     <linux:object object_ref="object_partition_{{{ escaped_path }}}_exists" />
792d3d
-    {{#- <linux:partition_state state_ref="" /> #}}
792d3d
   </linux:partition_test>
792d3d
 
792d3d
   <linux:partition_object id="object_partition_{{{ escaped_path }}}_exists" version="1">