Skip to content
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
21 changes: 8 additions & 13 deletions shared/templates/file_groupowner/oval.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,12 @@
{{% endif %}}
</criteria>
</definition>
{{%- if MISSING_FILE_PASS -%}}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This OVAL template now doesn't contain this parameter at all. How does it work now?

The docs says:

 -   **missing_file_pass** - If set to `"true"` the OVAL check will 
     pass when file is absent. Default value is `"false"`.

I have an impression that it now doesn't work when this is set to false. When it's set to false and the given file doesn't exist the rule should fail. But with this PR change if the given file doesn't exist, the check_existence="none_exists" is satisfied, therefore the rule will pass. Is my understanding correct?

Now the question is how to solve this change. I assume that the missing_file_pass set to false makes sense only when looking for specific files and not for recursive search. For the recursive search (i.e. rules with recursive: true) we usually don't care if something exists. But, our problem is mainly for recursively searching rules because in these rules we have the problem of collecting large amounts of item. We don't need this optimization for rules that match a single file or a couple of file in the same directory. Therefore we could have 2 versions of the OVAL code: one for recursive searching with the filter optimization and one for the other cases. We will document that the missing_file_pass = false is mutually exclusive with recursive = true. WDYT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We should remove this parameter. I didn't propose to remove from documentation because it should also be removed from many rule.yml files and I don't think this is mandatory for now since a behavior change is not expected. We can gradually deprecate this parameter for these affected templates.

These templates intend to assess the permissions and ownership (uid and gid) of files. Doesn't make any sense to me this assessment for files which are not present. If a file actually doesn't exist, it is quite logical that it won't have problems with permissions and ownership. The idea of the parameter missing_file_pass only makes sense for templates and rules which actually want to asses file existence and not their properties, like file_existence template or the banner_etc_motd rule, for example.

Also, seems that this parameter was introduced in these templates due to the design of the old OVAL logic where an empty file_object would affect the results based on the check_existence= parameter. In other words, this parameter is useless for these templates if we used check_existence=none_exist for the file_test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with Jan here, the rule passing when a specific file is absent is a behaviour changes we do not want.
We have a specific parameter that allows this behaviour, and I think we should keep it, (if we want to remove it, it should be done in master).

Doesn't make any sense to me this assessment for files which are not present.

I think it depends on the expectation of the rule. There may be rules that don't care if it is missing, while others may care if the file is missing.
From my PoV, this is a flexibility of the template that we want to keep.

{{# Any number of files can exist, from zero to any #}}
{{% set FILE_EXISTENCE = "any_exist" %}}
{{%- else -%}}
{{# All defined files must exist. When using regex, at least one file must match #}}
{{% set FILE_EXISTENCE = "all_exist" %}}
{{%- endif -%}}


{{% for filepath in FILEPATH %}}
<unix:file_test check="all" check_existence="{{{ FILE_EXISTENCE }}}" comment="Testing group ownership of {{{ filepath }}}" id="test_file_groupowner{{{ FILEID }}}_{{{ loop.index0 }}}" version="1">
Comment thread
yuumasato marked this conversation as resolved.
<unix:file_test check="all" check_existence="none_exist" comment="Testing group ownership of {{{ filepath }}}" id="test_file_groupowner{{{ FILEID }}}_{{{ loop.index0 }}}" version="1">
<unix:object object_ref="object_file_groupowner{{{ FILEID }}}_{{{ loop.index0 }}}" />
<unix:state state_ref="state_file_groupowner{{{ FILEID }}}_gid_{{{ FILEGID }}}_{{{ loop.index0 }}}" />
</unix:file_test>
<unix:file_state id="state_file_groupowner{{{ FILEID }}}_gid_{{{ FILEGID }}}_{{{ loop.index0 }}}" version="1">
<unix:group_id datatype="int">{{{ FILEGID }}}</unix:group_id>
</unix:file_state>

<unix:file_object comment="{{{ filepath }}}" id="object_file_groupowner{{{ FILEID }}}_{{{ loop.index0 }}}" version="1">
{{%- if IS_DIRECTORY -%}}
{{%- if RECURSIVE %}}
Expand All @@ -46,8 +35,14 @@
<unix:filepath{{% if FILEPATH_IS_REGEX %}} operation="pattern match"{{% endif %}}>{{{ filepath }}}</unix:filepath>
{{%- endif %}}
<filter action="exclude">symlink_file_groupowner{{{ FILEID }}}_uid_{{{ FILEGID }}}</filter>
<filter action="exclude">state_file_groupowner{{{ FILEID }}}_gid_{{{ FILEGID }}}_{{{ loop.index0 }}}</filter>
</unix:file_object>

<unix:file_state id="state_file_groupowner{{{ FILEID }}}_gid_{{{ FILEGID }}}_{{{ loop.index0 }}}" version="1">
<unix:group_id datatype="int">{{{ FILEGID }}}</unix:group_id>
</unix:file_state>
{{% endfor %}}

<unix:file_state id="symlink_file_groupowner{{{ FILEID }}}_uid_{{{ FILEGID }}}" version="1">
<unix:type operation="equals">symbolic link</unix:type>
</unix:file_state>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
#

{{% for path in FILEPATH %}}
{{% if IS_DIRECTORY and FILE_REGEX %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
#

groupadd group_test

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
#

{{% for path in FILEPATH %}}
{{% if MISSING_FILE_PASS %}}
Expand Down
20 changes: 8 additions & 12 deletions shared/templates/file_owner/oval.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,12 @@
{{% endif %}}
</criteria>
</definition>
{{%- if MISSING_FILE_PASS -%}}
{{# Any number of files can exist, from zero to any #}}
{{% set FILE_EXISTENCE = "any_exist" %}}
{{%- else -%}}
{{# All defined files must exist. When using regex, at least one file must match #}}
{{% set FILE_EXISTENCE = "all_exist" %}}
{{%- endif -%}}

{{% for filepath in FILEPATH %}}
<unix:file_test check="all" check_existence="{{{ FILE_EXISTENCE }}}" comment="Testing user ownership of {{{ filepath }}}" id="test_file_owner{{{ FILEID }}}_{{{ loop.index0 }}}" version="1">
<unix:file_test check="all" check_existence="none_exist" comment="Testing user ownership of {{{ filepath }}}" id="test_file_owner{{{ FILEID }}}_{{{ loop.index0 }}}" version="1">
<unix:object object_ref="object_file_owner{{{ FILEID }}}_{{{ loop.index0 }}}" />
<unix:state state_ref="state_file_owner{{{ FILEID }}}_uid_{{{ FILEUID }}}_{{{ loop.index0 }}}" />
</unix:file_test>
<unix:file_state id="state_file_owner{{{ FILEID }}}_uid_{{{ FILEUID }}}_{{{ loop.index0 }}}" version="1">
<unix:user_id datatype="int">{{{ FILEUID }}}</unix:user_id>
</unix:file_state>

<unix:file_object comment="{{{ filepath }}}" id="object_file_owner{{{ FILEID }}}_{{{ loop.index0 }}}" version="1">
{{%- if IS_DIRECTORY -%}}
{{%- if RECURSIVE %}}
Expand All @@ -45,8 +35,14 @@
<unix:filepath{{% if FILEPATH_IS_REGEX %}} operation="pattern match"{{% endif %}}>{{{ filepath }}}</unix:filepath>
{{%- endif %}}
<filter action="exclude">symlink_file_owner{{{ FILEID }}}_uid_{{{ FILEUID }}}</filter>
<filter action="exclude">state_file_owner{{{ FILEID }}}_uid_{{{ FILEUID }}}_{{{ loop.index0 }}}</filter>
</unix:file_object>

<unix:file_state id="state_file_owner{{{ FILEID }}}_uid_{{{ FILEUID }}}_{{{ loop.index0 }}}" version="1">
<unix:user_id datatype="int">{{{ FILEUID }}}</unix:user_id>
</unix:file_state>
{{% endfor %}}

<unix:file_state id="symlink_file_owner{{{ FILEID }}}_uid_{{{ FILEUID }}}" version="1">
<unix:type operation="equals">symbolic link</unix:type>
</unix:file_state>
Expand Down
1 change: 0 additions & 1 deletion shared/templates/file_owner/tests/correct_owner.pass.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
#

{{% for path in FILEPATH %}}
{{% if IS_DIRECTORY and FILE_REGEX %}}
Expand Down
1 change: 0 additions & 1 deletion shared/templates/file_owner/tests/incorrect_owner.fail.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
#

useradd testuser_123

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
#

{{% for path in FILEPATH %}}
{{% if MISSING_FILE_PASS %}}
Expand Down
42 changes: 9 additions & 33 deletions shared/templates/file_permissions/oval.template
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
{{%- if ALLOW_STRICTER_PERMISSIONS %}}
{{#
When allowing stricter permissions, the check looks for files/directories
that have any extra permission bit set. The permissions mode (STATEMODE)
is negated (inverted) and becomes a mask for permissions that should not be set.
#}}
{{% set FILE_EXISTENCE = "at_least_one_exists" %}}
{{%- else -%}}
{{%- if MISSING_FILE_PASS -%}}
{{# Any number of files can exist, from zero to any #}}
{{% set FILE_EXISTENCE = "any_exist" %}}
{{%- else -%}}
{{# All defined files must exist. When using regex, at least one file must match #}}
{{% set FILE_EXISTENCE = "all_exist" %}}
{{%- endif -%}}
{{%- endif -%}}
Comment thread
yuumasato marked this conversation as resolved.
<def-group>
<definition class="compliance" id="{{{ _RULE_ID }}}" version="1">
{{% if FILEPATH is not string %}}
Expand All @@ -22,28 +6,24 @@
") }}}
<criteria>
{{% for filepath in FILEPATH %}}
<criterion comment="Check file mode of {{{ filepath }}}" test_ref="test_file_permissions{{{ FILEID }}}_{{{ loop.index0 }}}"{{{ ' negate="true"' if ALLOW_STRICTER_PERMISSIONS }}}/>
<criterion comment="Check file mode of {{{ filepath }}}" test_ref="test_file_permissions{{{ FILEID }}}_{{{ loop.index0 }}}"/>
{{% endfor %}}
{{% else %}}
{{{ oval_metadata("This test makes sure that " + FILEPATH + " has mode " + FILEMODE + ".
If the target file or directory has an extended ACL, then it will fail the mode check.
") }}}
<criteria>
<criterion comment="Check file mode of {{{ FILEPATH }}}" test_ref="test_file_permissions{{{ FILEID }}}"{{{ ' negate="true"' if ALLOW_STRICTER_PERMISSIONS }}}/>
<criterion comment="Check file mode of {{{ FILEPATH }}}" test_ref="test_file_permissions{{{ FILEID }}}"/>
{{% endif %}}
</criteria>
</definition>

{{% for filepath in FILEPATH %}}
<unix:file_test check="all" check_existence="{{{ FILE_EXISTENCE }}}" comment="Testing mode of {{{ filepath }}}" id="test_file_permissions{{{ FILEID }}}_{{{ loop.index0 }}}" version="2">
<unix:file_test check="all" check_existence="none_exist" comment="Testing mode of {{{ filepath }}}" id="test_file_permissions{{{ FILEID }}}_{{{ loop.index0 }}}" version="3">
<unix:object object_ref="object_file_permissions{{{ FILEID }}}_{{{ loop.index0 }}}" />
<unix:state state_ref="state_file_permissions{{{ FILEID }}}_{{{ loop.index0 }}}_mode_{{{ 'not_' if ALLOW_STRICTER_PERMISSIONS }}}{{{ FILEMODE }}}" />
</unix:file_test>
<unix:file_state id="state_file_permissions{{{ FILEID }}}_{{{ loop.index0 }}}_mode_{{{ 'not_' if ALLOW_STRICTER_PERMISSIONS }}}{{{ FILEMODE }}}"{{{ ' operator="OR"' if ALLOW_STRICTER_PERMISSIONS }}} version="2">
{{{ STATEMODE | indent(6) }}}
</unix:file_state>
<unix:file_object comment="{{{ filepath }}}" id="object_file_permissions{{{ FILEID }}}_{{{ loop.index0 }}}" version="1">

<unix:file_object comment="{{{ filepath }}}" id="object_file_permissions{{{ FILEID }}}_{{{ loop.index0 }}}" version="1">
{{%- if IS_DIRECTORY %}}
{{%- if RECURSIVE %}}
<unix:path operation="pattern match">^{{{ filepath[:-1] }}}</unix:path>
Expand All @@ -58,17 +38,13 @@
{{%- else %}}
<unix:filepath{{% if FILEPATH_IS_REGEX %}} operation="pattern match"{{% endif %}}>{{{ filepath }}}</unix:filepath>
{{%- endif %}}

{{%- if ALLOW_STRICTER_PERMISSIONS %}}
{{#
This filter is required because of an issue in OpenSCAP. The issue has been fixed in:
https://github.com/OpenSCAP/openscap/pull/1709 but this line should be kept until the
fix is widely available. The fix is expected to be part of OpenSCAP >= 1.3.5.
#}}
<filter action="include">state_file_permissions{{{ FILEID }}}_{{{ loop.index0 }}}_mode_not_{{{ FILEMODE }}}</filter>
{{%- endif %}}
<filter action="exclude">exclude_symlinks_{{{ FILEID }}}</filter>
<filter action="exclude">state_file_permissions{{{ FILEID }}}_{{{ loop.index0 }}}_mode_{{{ FILEMODE }}}{{{ 'or_stricter_' if ALLOW_STRICTER_PERMISSIONS }}}</filter>
</unix:file_object>

<unix:file_state id="state_file_permissions{{{ FILEID }}}_{{{ loop.index0 }}}_mode_{{{ FILEMODE }}}{{{ 'or_stricter_' if ALLOW_STRICTER_PERMISSIONS }}}" operator="AND" version="3">
{{{ STATEMODE | indent(6) }}}
</unix:file_state>
{{% endfor %}}

<unix:file_state id="exclude_symlinks_{{{ FILEID }}}" version="1">
Expand Down
5 changes: 1 addition & 4 deletions shared/templates/file_permissions/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ def preprocess(data, lang):
"<unix:" + field + " datatype=\"boolean\">true</unix:"
+ field + ">\n" + mode_str)
else:
value = "false"
if data['allow_stricter_permissions']:
value = "true"
mode_str = (
"<unix:" + field + " datatype=\"boolean\">{}</unix:".format(value)
"<unix:" + field + " datatype=\"boolean\">false</unix:"
+ field + ">\n" + mode_str)
mode_int = mode_int >> 1
data["statemode"] = mode_str.rstrip("\n")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
#

{{% for path in FILEPATH %}}
{{% if IS_DIRECTORY and FILE_REGEX %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/bin/bash
#

{{% for path in FILEPATH %}}
{{% if IS_DIRECTORY and FILE_REGEX %}}
echo "Create specific tests for this rule because of regex"
{{% elif IS_DIRECTORY and RECURSIVE %}}
find -L {{{ path }}} -type d -exec chmod 777 {} \;
find -L {{{ path }}} -type d -maxdepth 1 -exec chmod 777 {} \;
{{% else %}}
if [ ! -f {{{ path }}} ]; then
mkdir -p "$(dirname '{{{ path }}}')"
Expand Down