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

test: run oscap checks on images with oscap customizations (HMS-3710) #502

Merged
merged 9 commits into from
Mar 26, 2024

Conversation

achilleas-k
Copy link
Member

@achilleas-k achilleas-k commented Mar 5, 2024

Add oscap test configs for RHEL 8 and RHEL 9 with the appropriate datastream option enabled.
These replicate the test configs from the oscap test in osbuild-composer [1].

To fully replace the test in osbuild-composer, this PR also adds support for running the boot test script with the config file as argument. When an oscap config is detected, it runs some extra checks on the score of the system.

NOTE: This is a bit quick and dirty but should soon be replaced with a more comprehensive test of all customizations on images during boot

[1] https://github.com/osbuild/osbuild-composer/blob/073e304978acade8bfa059f00a005402aa037c99/test/cases/oscap.sh

@achilleas-k achilleas-k changed the title test: run oscap checks on images with oscap customizations test: run oscap checks on images with oscap customizations (HMS-3696) Mar 6, 2024
@achilleas-k achilleas-k changed the title test: run oscap checks on images with oscap customizations (HMS-3696) test: run oscap checks on images with oscap customizations (HMS-3710) Mar 6, 2024
achilleas-k added a commit to achilleas-k/osbuild-composer that referenced this pull request Mar 6, 2024
The test is being migrated to osbuild/images.
See osbuild/images#502

Signed-off-by: Achilleas Koutsou <[email protected]>
achilleas-k added a commit to achilleas-k/osbuild-composer that referenced this pull request Mar 7, 2024
The test is being migrated to osbuild/images.
See osbuild/images#502

Signed-off-by: Achilleas Koutsou <[email protected]>
@achilleas-k achilleas-k force-pushed the test/oscap-scores branch 3 times, most recently from 3df20c8 to 7901956 Compare March 22, 2024 20:34
@achilleas-k
Copy link
Member Author

achilleas-k commented Mar 25, 2024

RHEL 8.10 boot test failing with:

systemd-remount-fs[563]: mount: /dev/shm: mount point not mounted or bad option.

which makes the systemd-remount-fs.service fail.
Looking into it.

@achilleas-k
Copy link
Member Author

Comparing the oscap version of the image with the base one, /etc/fstab gets an extra line:

tmpfs /dev/shm tmpfs defaults,nosuid,relatime,mode=755,inode64,nodev,noexec 0 0

which I assume is what causes the issue. Is this a bug in the oscap profile, adding an fstab option that the OS doesn't support, or did I configure it wrong?
I copied the blueprint from the test in osbuild-composer, but we don't check for the system status there so this might have always been happening.

@kingsleyzissou do you know anything about this (from your oscap experience)?

@kingsleyzissou
Copy link
Contributor

kingsleyzissou commented Mar 25, 2024

which I assume is what causes the issue. Is this a bug in the oscap profile, adding an fstab option that the OS doesn't support, or did I configure it wrong?

So this is technically a required mountpoint in the rhel-8 datastream for the cis profile. So maybe it's adding this as a remediation and breaking the build. It might be an outdated datastream, because I think they may have removed this. I'm double checking

@kingsleyzissou
Copy link
Contributor

I have a strong suspicion that we are using an outdated datastream file from an older scap-security-guides package.

@achilleas-k
Copy link
Member Author

I have a strong suspicion that we are using an outdated datastream file from an older scap-security-guides package.

Interesting. Could it be an 8.10 issue since it's not released yet? I'm playing with the fstab on a live system and trying to get it to work but even with no options (just defaults) systemd-remount-fs.service fails.
Manually mounting it works only if I remove the inode64 option.

Not sure if any of this helps.

@kingsleyzissou
Copy link
Contributor

kingsleyzissou commented Mar 25, 2024

Interesting. Could it be an 8.10 issue since it's not released yet?

It's just a hunch. But up until last year the blueprints generated by the oscap tool were also trying to configure filesystem options for /dev/shm which was causing builds to fail. I think they revised the datastream since then and that has been removed.

But I haven't seen an entry being added to the /etc/fstab before. That's interesting. We can maybe reach out to the openscap team about this @evgenyz.

Edit: another thought is it could also be something from some of the offline improvements that have been made, but Evgeny would have to confirm if they've made any changes to the mountpoint options on their end.

@achilleas-k
Copy link
Member Author

achilleas-k commented Mar 25, 2024

@kingsleyzissou Unselecting content_rule_mount_option_dev_shm_nosuid, content_rule_mount_option_dev_shm_noexec, and content_rule_mount_option_dev_shm_nodev didn't help.

We will be adding distro-specific oscap configs so let's rename this one
to differentiate.
Add oscap test configs for RHEL 8 and RHEL 9 with the appropriate
datastream option enabled.

These replicate the test configs from the oscap test in
osbuild-composer [1].

We enable these on ami to validate the config in the boot tests.

[1] https://github.com/osbuild/osbuild-composer/blob/073e304978acade8bfa059f00a005402aa037c99/test/cases/oscap.sh
Currently does nothing with it, but the intention is to use in the boot
test script.
The run subcommand uploads a local executable and runs it.  Now we also
support passing arguments to the executable.  Any arguments that are
paths to files are also uploaded to the image but only by their
basename.
When booting AMIs in AWS, pass the config file name to the
base-host-check.sh command.
Install necessary packages to run scans and check results.
Read the config if it's passed as an argument and detect if any openscap
customizations are specified.  If they are, run some oscap checks.
The oscap profile adds a /dev/shm mount to /etc/fstab which fails in
RHEL 8.10.  Disable the test for this distro version while we
investigate the failure.
@achilleas-k
Copy link
Member Author

Disabling the test on RHEL 8.10 for now.

Copy link
Contributor

@kingsleyzissou kingsleyzissou left a comment

Choose a reason for hiding this comment

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

🙏

@evgenyz
Copy link
Contributor

evgenyz commented Mar 25, 2024

That's very strange. I don't think we force inode64 anywhere. As to the record itself: it should not be a problem, as /etc/fstab is the recommended way (acc. to systemd docs) for mount units options customization.

@evgenyz
Copy link
Contributor

evgenyz commented Mar 25, 2024

Remediation log could be helpful (it is stored in /root/).

@ondrejbudai ondrejbudai added this pull request to the merge queue Mar 26, 2024
Merged via the queue into osbuild:main with commit f4a601b Mar 26, 2024
14 of 16 checks passed
@kingsleyzissou
Copy link
Contributor

@evgenyz it's really weird, if I disabled partition_for_dev_shm things work and no entry is added into the /etc/fstab.
But when I check the remediation logs:
FIX FOR THIS RULE 'xccdf_org.ssgproject.content_rule_partition_for_dev_shm' IS MISSING!

@achilleas-k achilleas-k deleted the test/oscap-scores branch March 26, 2024 19:24
ochosi pushed a commit to osbuild/osbuild-composer that referenced this pull request Mar 27, 2024
The test is being migrated to osbuild/images.
See osbuild/images#502

Signed-off-by: Achilleas Koutsou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants