Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce and apply the "partition exists" platform #9204

Merged
merged 3 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ references:
stigid@ol8: OL08-00-040132
stigid@rhel8: RHEL-08-040132

platform: machine
platforms:
- machine and partition-var-tmp

template:
name: mount_option
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

. $SHARED/partition.sh

clean_up_partition /var/tmp # Remove the partition from the system, and unmount it
14 changes: 14 additions & 0 deletions shared/applicability/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ cpes:
bash_conditional: {{{ bash_pkg_conditional("pam") }}}
ansible_conditional: {{{ ansible_pkg_conditional("pam") }}}

- partition-var-tmp:
name: "cpe:/a:partition-var-tmp"
title: "There is a /var/tmp partition"
check_id: installed_env_mounts_var_tmp
bash_conditional: {{{ bash_partition_conditional("/var/tmp") }}}
ansible_conditional: {{{ ansible_partition_conditional("/var/tmp") }}}

- partition-tmp:
name: "cpe:/a:partition-tmp"
title: "There is a /tmp partition"
check_id: installed_env_mounts_tmp
bash_conditional: {{{ bash_partition_conditional("/tmp") }}}
ansible_conditional: {{{ ansible_partition_conditional("/tmp") }}}

- polkit:
name: "cpe:/a:polkit"
title: "Package polkit is installed"
Expand Down
10 changes: 10 additions & 0 deletions shared/checks/oval/installed_env_mounts_tmp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<def-group>
<definition class="inventory" id="installed_env_mounts_tmp" version="1">
{{{ oval_metadata("", title="Partition /tmp exists", affected_platforms=[full_name]) }}}
<criteria>
{{{ partition_exists_criterion("/tmp") }}}
</criteria>
</definition>

{{{ partition_exists_test_object("/tmp") }}}
</def-group>
10 changes: 10 additions & 0 deletions shared/checks/oval/installed_env_mounts_var_tmp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<def-group>
<definition class="inventory" id="installed_env_mounts_var_tmp" version="1">
{{{ oval_metadata("", title="Partition /var/tmp exists", affected_platforms=[full_name]) }}}
<criteria>
{{{ partition_exists_criterion("/var/tmp") }}}
</criteria>
</definition>

{{{ partition_exists_test_object("/var/tmp") }}}
</def-group>
5 changes: 5 additions & 0 deletions shared/macros/10-ansible.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -1439,3 +1439,8 @@ Part of the grub2_bootloader_argument_absent template.
when:
- result_pam_file_present.stat.exists
{{%- endmacro -%}}


{{%- macro ansible_partition_conditional(path) -%}}
"ansible_facts.ansible_mounts | json_query(\"[?mount=='{{{ path }}}'].mount\") | length == 1"
{{%- endmacro -%}}
5 changes: 5 additions & 0 deletions shared/macros/10-bash.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2085,3 +2085,8 @@ else
echo "{{{ pam_file }}} was not found" >&2
fi
{{%- endmacro -%}}


{{%- macro bash_partition_conditional(path) -%}}
'findmnt --mountpoint "{{{ path }}}" > /dev/null'
{{%- endmacro -%}}
20 changes: 20 additions & 0 deletions shared/macros/10-oval.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -926,3 +926,23 @@ Generates the :code:`<affected>` tag for OVAL check using correct product platfo
{{%- else %}}
{{%- set user_list="nobody" %}}
{{%- endif %}}


{{%- macro partition_exists_criterion(path) %}}
{{%- set escaped_path = path | escape_id %}}
<criterion comment="The path {{{ path }}} is a partition's mount point" test_ref="test_partition_{{{ escaped_path }}}_exists" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<criterion comment="The path {{{ path }}} is a partition's mount point" test_ref="test_partition_{{{ escaped_path }}}_exists" />
<criterion comment="The path {{{ path }}} is a partition's mount point" test_ref="test_partition_{{{ path|escape_id }}}_exists" />

There is a special Jinja filter that can create XCCDF-compatible IDs from anything.

{{%- endmacro %}}

{{%- macro partition_exists_test_object(path) %}}
{{%- set escaped_path = path | escape_id %}}
<linux:partition_test check="all" check_existence="all_exist"
comment="Partition {{{ path }}} exists"
id="test_partition_{{{ escaped_path }}}_exists"
version="1">
<linux:object object_ref="object_partition_{{{ escaped_path }}}_exists" />
</linux:partition_test>

<linux:partition_object id="object_partition_{{{ escaped_path }}}_exists" version="1">
<linux:mount_point>{{{ path }}}</linux:mount_point>
</linux:partition_object>
{{%- endmacro %}}