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

Add oval-graph support for the test suite #7750

Merged
merged 2 commits into from
Jan 3, 2022

Conversation

matejak
Copy link
Member

@matejak matejak commented Oct 15, 2021

This PR flips the result format to ARF, and uses oval-graph to generate HTML graphs locally.

If oval-graph is available on the system that runs the tests, the test suite generates the interactive HTML visualization of the OVAL check based on the ARF. Generated HTML graphs are small, so they are currently not cleaned from the folder (in contrast to reports).

It looks like that the ARF that oscap produces when called with --remediate refers to the state before the fix, so those graphs aren't useful.

@matejak matejak added this to the 0.1.59 milestone Oct 15, 2021
Copy link
Collaborator

@jan-cerny jan-cerny left a comment

Choose a reason for hiding this comment

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

My biggest problem is that when I run some rule like selinux_state which has 3 scenarios I can see graph file only for one of the scenarios.

[jcerny@thinkpad scap-security-guide{pr/7750}]$ python3 tests/test_suite.py rule --libvirt qemu:///system ssgts_rhel8 selinux_state
Setting console output to log level INFO
INFO - The base image option has not been specified, choosing libvirt-based test environment.
INFO - Logging into /home/jcerny/work/git/scap-security-guide/logs/rule-custom-2021-10-18-0954/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_selinux_state
INFO - Script selinux_enforcing.pass.sh using profile xccdf_org.ssgproject.content_profile_ospp OK
INFO - Script selinux_missing.fail.sh using profile xccdf_org.ssgproject.content_profile_ospp OK
INFO - Script selinux_permissive.fail.sh using profile xccdf_org.ssgproject.content_profile_ospp OK
[jcerny@thinkpad scap-security-guide{pr/7750}]$ ls /home/jcerny/work/git/scap-security-guide/logs/rule-custom-2021-10-18-0954
env-preparation.log  selinux_state.prescripts.log                                test_suite.log
results.json         selinux_state-selinux_enforcing.pass.sh-initial-graph.html
[jcerny@thinkpad scap-security-guide{pr/7750}]$ 

@@ -427,7 +428,7 @@ def _get_formatting_dict_for_remediation(self):

class ProfileRunner(GenericRunner):
def _get_arf_file(self):
return '{0}-initial-arf.xml'.format(self.profile)
return '{0}-{self.stage}-arf.xml'.format(self.profile, self.stage)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return '{0}-{self.stage}-arf.xml'.format(self.profile, self.stage)
return '{0}-{1}-arf.xml'.format(self.profile, self.stage)

html_filename = re.sub(r"\barf\b", "graph", arf_filename)
html_filename = re.sub(r".xml", ".html", html_filename)

cmd = ['arf-to-graph', '--all-in-one', '--output', html_filename, arf_filename, '.']
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please document that the graph is used in the test suite readme.

@jan-cerny
Copy link
Collaborator

@matejak @Honny1 I have discovered that it's because arf-to-graph refuses to consume the ARF.

arf-to-graph --all-in-one --output /home/jcerny/work/git/scap-security-guide/logs/rule-custom-2021-11-15-1124/selinux_state-selinux_permissive.fail.sh-initial-graph.html /home/jcerny/work/git/scap-security-guide/logs/rule-custom-2021-11-15-1124/selinux_state-selinux_permissive.fail.sh-initial-arf.xml .
Error: This file "/home/jcerny/work/git/scap-security-guide/logs/rule-custom-2021-11-15-1124/selinux_state-selinux_permissive.fail.sh-initial-arf.xml" is not arf report file or there are no results
[jcerny@thinkpad scap-security-guide{pr/7750}]$ rpm -q oval-graph
oval-graph-1.3.1-1.fc33.noarch

@matejak It would be better to consume the stderr/stdout of the arf-to-graph command in the TestEnv.arf_to_html method.

@Honny1 What do you think?

arf.zip

@yuumasato yuumasato modified the milestones: 0.1.59, 0.1.60 Nov 15, 2021
@Honny1
Copy link
Collaborator

Honny1 commented Nov 16, 2021

@jan-cerny It seems you have replicated the issue in the oval-graph. I'll find out where the problem is.

@Honny1
Copy link
Collaborator

Honny1 commented Nov 30, 2021

@jan-cerny The issue with oval-graph is fixed in PR.

jan-cerny added a commit to jan-cerny/scap-security-guide that referenced this pull request Dec 1, 2021
During review of ComplianceAsCode#7750 we have discovered that for this test scenario
the rule fails not because the `SELINUX=permissive` but because
no `SELINUX=` entry exists. The missing `SELINUX=` entry was caused
by a typo in the sed expression which effectively replaced
`SELINUX=enforcing` by just `permissive`. As a result, oscap didn't
find the OVAL object `oval:ssg-object_etc_selinux_config:obj:1`.
@jan-cerny
Copy link
Collaborator

@Honny1 Thanks for finding the root cause which was that the ARF didn't contain any system_data because no OVAL object has been collected.

Thanks to that, I found it suspicous that oscap didn't collect any object and I have discovered that there is a problem in the test scenario linux_os/guide/system/selinux/selinux_state/tests/selinux_permissive.fail.sh which will be fixed by #7943.

@jan-cerny jan-cerny self-assigned this Dec 1, 2021
@jan-cerny
Copy link
Collaborator

@matejak As the problem is not in this PR but in oval-graph I think we can happily merge this unless you know about something that would prevent that. Just please rebase it on master so that we have the F34 gating job.

@jan-cerny
Copy link
Collaborator

@matejak bump

This PR flips the result format to ARF, and uses
oval-graph to generate HTML graphs locally.

HTML graphs are not cleaned from the folder.
@Honny1
Copy link
Collaborator

Honny1 commented Dec 14, 2021

The new version of oval-graph is in testing.

@jan-cerny jan-cerny merged commit bcc24a8 into ComplianceAsCode:master Jan 3, 2022
matejak added a commit to matejak/scap-security-guide that referenced this pull request Jan 4, 2022
In the past, ARFs were used exclusively as a source of Bash/Ansible
remediations. However, it is more practical to have them available as
test artifacts, as they contain more information. In order to finish
what ComplianceAsCode#7750 just started, following needed to be done:

- Rename ..._file to ..._basename, so it is clear what the variable
  represents.
- Always generate ARFs during initial stage of tests even if reports are
  not requested - those files are still needed to act as sources of remediations.
- Keep those ARFs that could be used in remediations around for the next
  stage of tests.
- Make test runners a context manager, which allows them to clean
  remaining files after the test run finishes.
Connect2naga pushed a commit to Connect2naga/content that referenced this pull request Jan 24, 2022
In the past, ARFs were used exclusively as a source of Bash/Ansible
remediations. However, it is more practical to have them available as
test artifacts, as they contain more information. In order to finish
what ComplianceAsCode#7750 just started, following needed to be done:

- Rename ..._file to ..._basename, so it is clear what the variable
  represents.
- Always generate ARFs during initial stage of tests even if reports are
  not requested - those files are still needed to act as sources of remediations.
- Keep those ARFs that could be used in remediations around for the next
  stage of tests.
- Make test runners a context manager, which allows them to clean
  remaining files after the test run finishes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants