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

Build, find, and test Ansible per-rule playbooks #221

Merged
merged 3 commits into from
Jul 8, 2024

Conversation

mildas
Copy link
Contributor

@mildas mildas commented Jul 4, 2024

Per-rule playbooks, used by console dot are in different package and located in different path than profile playbooks shipped by scap-security-guide.
For built content:
Profile playbooks

$ ls build/ansible
all-profile-playbooks-rhel9                 rhel9-playbook-ccn_intermediate.yml    rhel9-playbook-hipaa.yml
rhel9-playbook-anssi_bp28_enhanced.yml      rhel9-playbook-cis_server_l1.yml       rhel9-playbook-ism_o.yml
rhel9-playbook-anssi_bp28_high.yml          rhel9-playbook-cis_workstation_l1.yml  rhel9-playbook-ospp.yml
rhel9-playbook-anssi_bp28_intermediary.yml  rhel9-playbook-cis_workstation_l2.yml  rhel9-playbook-pci-dss.yml
rhel9-playbook-anssi_bp28_minimal.yml       rhel9-playbook-cis.yml                 rhel9-playbook-stig_gui.yml
rhel9-playbook-ccn_advanced.yml             rhel9-playbook-cui.yml                 rhel9-playbook-stig.yml
rhel9-playbook-ccn_basic.yml                rhel9-playbook-e8.yml

Rule playbooks (there are profile directories, but all should contain all rules from datastream):

$ ls build/rhel9/playbooks/all/ | tail -n5
zipl_page_alloc_shuffle_argument.yml
zipl_page_poison_argument.yml
zipl_slub_debug_argument.yml
zipl_systemd_debug-shell_argument_absent.yml
zipl_vsyscall_argument.yml

RPM:
scap-security-guide

# rpm -ql scap-security-guide | grep .yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-anssi_bp28_enhanced.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-anssi_bp28_high.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-anssi_bp28_intermediary.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-anssi_bp28_minimal.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-ccn_advanced.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-ccn_basic.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-ccn_intermediate.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-cis.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-cis_server_l1.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-cis_workstation_l1.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-cis_workstation_l2.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-cui.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-e8.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-hipaa.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-ism_o.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-ospp.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-pci-dss.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-stig.yml
/usr/share/scap-security-guide/ansible/rhel9-playbook-stig_gui.yml

scap-security-guide-rule-playbooks

# rpm -ql scap-security-guide-rule-playbooks | grep /all/ | tail -n5
/usr/share/scap-security-guide/ansible/rule_playbooks/rhel9/all/zipl_page_alloc_shuffle_argument.yml
/usr/share/scap-security-guide/ansible/rule_playbooks/rhel9/all/zipl_page_poison_argument.yml
/usr/share/scap-security-guide/ansible/rule_playbooks/rhel9/all/zipl_slub_debug_argument.yml
/usr/share/scap-security-guide/ansible/rule_playbooks/rhel9/all/zipl_systemd_debug-shell_argument_absent.yml
/usr/share/scap-security-guide/ansible/rule_playbooks/rhel9/all/zipl_vsyscall_argument.yml

Previous approach _find_playbooks(root).rglob('*') worked for RPM - it traversed all /usr/share/scap-security-guide/ansible/ directories and searched for .yml. However, it was not efficient as it checked syntax for same playbook multiple times (for each profile directory where a playbook was).
It didn't work for built content thus even if we would have built it in productization, the playbooks would not be yield by iter_playbooks.
Newly implemented option --playbook-per-rule builds per-rule playbooks via ./build_product and no need for cmake - ComplianceAsCode/content#12105

Copy link
Contributor

@comps comps left a comment

Choose a reason for hiding this comment

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

  1. Will this build regular playbooks in addition to per-rule ones? ... Is there some build time penalty?
  2. Does this change work with tests that use "fat" playbooks (ie. /hardening/*/ansible) when used with CONTEST_CONTENT ? .. Notice that once content is built (as detected by content_is_built(), it is not rebuilt, not even for a different test.

lib/util/content.py Outdated Show resolved Hide resolved
lib/util/content.py Outdated Show resolved Hide resolved
@mildas
Copy link
Contributor Author

mildas commented Jul 4, 2024

Will this build regular playbooks in addition to per-rule ones? ... Is there some build time penalty?

Yes, regular profile playbooks are still there. They are built by default.
Regarding build time penalty, there is some. During my testing it was few seconds (~10s). Not a big deal.

Does this change work with tests that use "fat" playbooks (ie. /hardening/*/ansible) when used with CONTEST_CONTENT ? .. Notice that once content is built (as detected by content_is_built(), it is not rebuilt, not even for a different test.

No. All profile playbooks are still the same on the same place with or without --playbook-per-rule option.
Only changes are in iter_playbooks(). But the function is used only in /static-checks/ansible/syntax-check, so /hardening/s are fine.

@comps
Copy link
Contributor

comps commented Jul 8, 2024

Testing passed, with the exception of /hardening/image-builder, which I had to re-run manually after 4 errored runs, but it passed on a 5th run, so presumably not a regression caused by this PR.

@comps comps merged commit 7909fdf into RHSecurityCompliance:main Jul 8, 2024
3 checks passed
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.

2 participants