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 /hardening/kickstart tests for oscap-generated kickstarts #239

Merged
merged 8 commits into from
Aug 16, 2024

Conversation

comps
Copy link
Contributor

@comps comps commented Jul 24, 2024

(Probably best to go commit-by-commit - the early ones are about cleanup.)

The image-builder (osbuild) rework is mainly to unify the API with /hardening/kickstart. I would have done the same for /hardening/anaconda, but (IIRC) openscap %addon cannot read file:// URLs or point to local files on the installed OS, it can only reliably use remote HTTP URLs.

@comps comps force-pushed the hardening_kickstart branch 3 times, most recently from 78fd9b0 to cd27bd1 Compare July 26, 2024 11:31
@comps comps force-pushed the hardening_kickstart branch 2 times, most recently from e44646e to 19e7181 Compare August 6, 2024 13:05
@comps comps marked this pull request as ready for review August 6, 2024 13:05
@comps
Copy link
Contributor Author

comps commented Aug 6, 2024

Added a condition to exclude RHEL-8 after a brief message with Evgeny - we probably want to support/test RHEL-9 in addition to RHEL-10.

One last step is to add waivers.

@comps comps force-pushed the hardening_kickstart branch from 19e7181 to a568e2a Compare August 7, 2024 02:03
@comps
Copy link
Contributor Author

comps commented Aug 8, 2024

I didn't join the /hardening/anaconda waivers with /hardening/kickstart because

  • most of the kickstart waivers have one common CaC/content issue files
  • they have a chance of being fixed, rather than abandoned as with OAA
  • they (as a group) probably share a common problem, and I didn't want to fragment that over multiple sections like with /hardening/anaconda

@comps comps force-pushed the hardening_kickstart branch from 72a4f7a to 3525b81 Compare August 8, 2024 14:33
comps added 7 commits August 8, 2024 21:21
These specify the defaults and are no longer needed post-RHEL-7.

Signed-off-by: Jiri Jaburek <comps@nomail.dom>
This is to avoid confusion with oscap-generated kickstarts.

Signed-off-by: Jiri Jaburek <comps@nomail.dom>
Signed-off-by: Jiri Jaburek <comps@nomail.dom>
This makes it a bit more explicit as to where the kickstart comes from,
making the test algorithm more obvious, without copying large chunks
of code.

Signed-off-by: Jiri Jaburek <comps@nomail.dom>
This adds translate_oscap_blueprint() and calls 'oscap' similarly to
/hardening/kickstart, showing the base test algorithm directly in
the test.

Coincidentally, this also cleans up the lib.osbuild logic a lot,
as we no longer have to pass 'profile' around and account for special
oscap cases and blueprint paths.
All oscap-specific stuff is now either in the translate function,
or directly in the test.

The TEMPLATE and other pieces of code were inspired by lib.virt.

translate_oscap_blueprint() weirdly takes lines instead of a full
block of text (the first thing it does is 'join()'), but that's
intentional, to keep the API similar to lib.virt translate functions.

Signed-off-by: Jiri Jaburek <comps@nomail.dom>
Signed-off-by: Jiri Jaburek <comps@nomail.dom>
Also re-organize a bit /hardening/anaconda waivers in a similar way.

Signed-off-by: Jiri Jaburek <comps@nomail.dom>
@comps comps force-pushed the hardening_kickstart branch from 3525b81 to ec0afee Compare August 8, 2024 19:22
Copy link
Contributor

@mildas mildas left a comment

Choose a reason for hiding this comment

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

kickstart part is fine.
For image-builder move, why not to move also rule unselect to test code? Unselect rules in contest-ds.xml and add that modified datastream to rpmpack. No need for oscap tailoring blueprint section. That will unify unselect part with OAA/kickstart where unselect is done directly in datastream without providing tailoring file.

This makes it more consistent with /hardening/kickstart
and others.

Signed-off-by: Jiri Jaburek <comps@nomail.dom>
@comps
Copy link
Contributor Author

comps commented Aug 15, 2024

Changed /hardening/image-builder to be more like the kickstart test,

--- hardening/kickstart/test.py 2024-08-08 21:21:32.803772075 +0200
+++ hardening/image-builder/test.py     2024-08-15 13:38:57.474565165 +0200
@@ -3,3 +3 @@
-import os
-
-from lib import util, results, virt, oscap
+from lib import results, oscap, osbuild, util
@@ -9 +7 @@
-virt.Host.setup()
+osbuild.Host.setup()
@@ -11 +9 @@
-g = virt.Guest()
+g = osbuild.Guest()
@@ -18 +16 @@
-# tell the 'oscap xccdf eval --remediate' in %post to use it
+# tell the 'oscap xccdf eval --remediate' called by osbuild-composer to use it
@@ -24 +22 @@
-    'fix', '--fix-type', 'kickstart',
+    'fix', '--fix-type', 'blueprint',
@@ -28,4 +26 @@
-ks = virt.translate_oscap_kickstart(lines, '/root/remediation-ds.xml')
-
-if os.environ.get('USE_SERVER_WITH_GUI'):
-    ks.packages.append('@Server with GUI')
+blueprint = osbuild.translate_oscap_blueprint(lines, '/root/remediation-ds.xml')
@@ -33 +28 @@
-g.install(kickstart=ks, rpmpack=rpmpack)
+g.create(blueprint=blueprint, rpmpack=rpmpack)
@@ -52 +47 @@
-results.report_and_exit(logs=['report.html', 'results-arf.xml.gz'])
+results.report_and_exit(logs=['report.html', 'results-arf.xml.gz', g.osbuild_log])

@mildas mildas merged commit 5d51475 into main Aug 16, 2024
3 checks passed
@mildas mildas deleted the hardening_kickstart branch August 16, 2024 09:37
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