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

Produce an understanable error when remediation collections goes wrong #10027

Merged

Conversation

matejak
Copy link
Member

@matejak matejak commented Jan 6, 2023

At least name the rule and the remediation type.

Review Hints:

If you run the build of e.g. sle15 product on a Python2 system, you will get an encoding error that will point you out to the file that contains a non-ASCII character. Generally, you can introduce any fatal error to the remediation s.a. non-matching Jinja control characters, and you will see the improved error handling in action. (although in case of Jinja errors, there would already be a pointer given by Jinja, but there are other things that can go wrong that crash without telling details).

when a collection of remediation goes wrong -
at least name the rule and the remediation type.
@matejak matejak added this to the 0.1.66 milestone Jan 6, 2023
@github-actions
Copy link

github-actions bot commented Jan 6, 2023

Start a new ephemeral environment with changes proposed in this pull request:

Fedora Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

@codeclimate
Copy link

codeclimate bot commented Jan 6, 2023

Code Climate has analyzed commit a0543e6 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 2

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 49.9% (0.0% change).

View more on Code Climate.

@jan-cerny jan-cerny self-assigned this Jan 12, 2023
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.

I have broken a remediation for a rule by breaking the platform and it has failed completely:

[5/11] [rhel9-content] collecting all fixes
FAILED: rhel9/collect-remediations-rhel9 /home/jcerny/work/git/scap-security-guide/build/rhel9/collect-remediations-rhel9 
cd /home/jcerny/work/git/scap-security-guide/build/rhel9 && env PYTHONPATH=/home/jcerny/work/git/scap-security-guide /usr/bin/python3 /home/jcerny/work/git/scap-security-guide/build-scripts/collect_remediations.py --resolved-rules-dir /home/jcerny/work/git/scap-security-guide/build/rhel9/rules --build-config-yaml /home/jcerny/work/git/scap-security-guide/build/build_config.yml --product-yaml /home/jcerny/work/git/scap-security-guide/products/rhel9/product.yml --remediation-type bash --remediation-type ansible --remediation-type puppet --remediation-type anaconda --remediation-type ignition --remediation-type kubernetes --remediation-type blueprint --output-dir /home/jcerny/work/git/scap-security-guide/build/rhel9/fixes --fixes-from-templates-dir /home/jcerny/work/git/scap-security-guide/build/rhel9/fixes_from_templates --platforms-dir /home/jcerny/work/git/scap-security-guide/build/rhel9/platforms --cpe-items-dir /home/jcerny/work/git/scap-security-guide/build/rhel9/cpe_items && /usr/bin/cmake -E touch /home/jcerny/work/git/scap-security-guide/build/rhel9/collect-remediations-rhel9
Traceback (most recent call last):
  File "/home/jcerny/work/git/scap-security-guide/build-scripts/collect_remediations.py", line 115, in collect_remediations
    process_remediation(
  File "/home/jcerny/work/git/scap-security-guide/build-scripts/collect_remediations.py", line 95, in process_remediation
    fix = remediation.process(remediation_obj, env_yaml, cpe_platforms)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jcerny/work/git/scap-security-guide/ssg/build_remediations.py", line 186, in process
    raise RuntimeError(
RuntimeError: The '/home/jcerny/work/git/scap-security-guide/linux_os/guide/system/selinux/selinux_state/bash/shared.sh' remediation script does not contain the platform identifier!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jcerny/work/git/scap-security-guide/build-scripts/collect_remediations.py", line 160, in <module>
    main()
  File "/home/jcerny/work/git/scap-security-guide/build-scripts/collect_remediations.py", line 153, in main
    collect_remediations(
  File "/home/jcerny/work/git/scap-security-guide/build-scripts/collect_remediations.py", line 121, in collect_remediations
    raise RuntimeError(msg)
RuntimeError: Failed to dispatch bash remediation for selinux_state: The '/home/jcerny/work/git/scap-security-guide/linux_os/guide/system/selinux/selinux_state/bash/shared.sh' remediation script does not contain the platform identifier!
ninja: build stopped: subcommand failed.

@jan-cerny jan-cerny merged commit 8d60389 into ComplianceAsCode:master Jan 12, 2023
@jan-cerny jan-cerny added the Infrastructure Our content build system label Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Infrastructure Our content build system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants