add scap_policy and scap_policy_info modules - #1988
Open
expeditioneer wants to merge 1 commit into
Open
Conversation
Closes theforeman#748. Supersedes the abandoned WIP in theforeman#752; the module name follows evgeni's suggestion there, minus the foreman_ prefix that has since been dropped collection-wide. The apidoc resource is "policies", not the name derived from the module, so entity_name is set explicitly. Profile lookup resolves an XCCDF profile title to scap_content_profile_id / tailoring_file_profile_id against the parent entity and falls back to the profile id, since customized tailoring files often carry an empty title. Resolving via the scap_content_profiles resource instead is not viable: it cannot be filtered by scap_content_id and profile titles are not unique, not even within a single SCAP content. Changes: - plugins/modules/scap_policy.py: new CRUD module; takes scap_content, tailoring_file and hostgroups by name/title and resolves the ids - plugins/modules/scap_policy_info.py: matching info module; only name, location and organization are searchable on this resource - tests/test_playbooks/scap_policy.yml: create/idempotency/tailoring/rename/ delete against the ssg-firefox-ds fixtures - tests/test_playbooks/scap_policy_info.yml: info test after the domain_info pattern - tests/test_playbooks/tasks/scap_policy.yml: reusable task file - tests/test_playbooks/fixtures/scap_policy*-*.yml: recorded against Foreman 3.17.2 with foreman_openscap 12.0.1 - tests/fixtures/apidoc/openscap.json: apidoc of that install; foreman.json lacks the openscap resources and luna.json serves organizations under /katello/api, which does not match the recording - meta/runtime.yml: register both modules in action_groups.foreman - changelogs/fragments/add-scap-policy-module.yml: changelog Signed-off-by: Dennis Lamm <dennis.lamm@pm.me>
expeditioneer
force-pushed
the
add-scap-policy-module
branch
from
August 3, 2026 10:44
f88d6ad to
801126b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #748.
Supersedes #752, which was left as WIP in 2020. The module name follows @evgeni's suggestion there (
foreman_scap_policy), minus theforeman_prefix that has since been dropped collection-wide — soscap_policy, alongsidescap_contentandscap_tailoring_file.What
scap_policy— CRUD for OpenSCAP compliance policiesscap_policy_info— matching info moduleWhy
Without a module, playbooks have to fall back to
uriagainst/api/compliance/policies. The awkward part is not the CRUD but the profile lookup: the API wantsscap_content_profile_idandtailoring_file_profile_id, which are only obtainable from the parent entity.scap_policytakesscap_content,scap_content_profile,tailoring_file,tailoring_file_profileandhostgroupsby name/title and resolves the ids.Notes for reviewers
entity_name='policy'— the apidoc resource ispolicies, so the name derived from the class does not exist. Same asinstallation_medium.py.scap_content_profilesresource with spec hints, as suggested in Add foreman_policy module #752: that resource cannot be filtered byscap_content_id(Field 'scap_content_id' not recognized for searching!), and titles are not unique. On a real instance with 45 profiles, one title occurred twice within the same SCAP content, and tailoring profiles had empty titles. Atype='entity'lookup by title would fail with "too many results" and could not address the empty ones at all. Hence the parent-scoped lookup with a fallback to the XCCDF profile id.lookup_entity()+set_entity()are used for that, per @mdellweg's note in Add foreman_policy module #752, so the parents are resolved once and the auto lookup inrun()does not fetch them again.deploy_byis inrequired_ifforstate=present— the apidoc marks itrequired: trueon create.tests/fixtures/apidoc/openscap.jsoninstead of a symlink to an existing one:foreman.jsonhas no openscap resources, andluna.jsonserves organizations under/katello/api/organizations, which does not match a plain Foreman + openscap recording. Perdocs/testing.mdthe apidoc of the actual install is placed in the fixtures folder; both test names symlink to it.name,locationandorganizationare searchable on this resource —deploy_by,periodanddescriptionreturnScopedSearch::QueryNotSupported. The info module examples reflect that.host_idsis deliberately not exposed. The API supports it, but I had no instance with directly assigned hosts to verify the response shape of thehostskey. Happy to add it if someone can confirm.Testing
Fixtures recorded against Foreman 3.17.2 with foreman_openscap 12.0.1.
test_crudandtest_check_modepass for both modules in replay modeansible-test sanity --venvclean for both modules (24 tests)yamllint,flake8,ansible-playbook --syntax-checkcleangenerate_action_groups.pyproduces no diff against the committedmeta/runtime.yml