Improve RPM database path in RPM probes #2156
Merged
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.
Description
The assumption that /var/lib/rpm is always a symlink to /usr/lib/sysimage/rpm was wrong. In bootc images, it isn't the case. As a result, all rules were evaluated as notapplicable when scanning a bootc image or container.
We will fix it the following way: We will first try if the "new" location /usr/lib/sysimage/rpm exists, and use it only if it exists. If it doesn't exist, we will fall back to the "old" location /var/lib/rpm.
Fixes: https://issues.redhat.com/browse/RHEL-55251
Fixes: #2151
Rationale
This would be a first step to get OpenSCAP ready for bootc experience.
Review hints
First, reproduce the problem and verify that we fixed it.
sudo podman pull quay.io/centos-bootc/centos-bootc:stream9
sudo oscap-podman quay.io/centos-bootc/centos-bootc:stream9 oval eval --results /tmp/results.xml oval.xml
sudo oscap-podman --oscap=/home/jcerny/work/git/openscap/build/oscap_wrapper quay.io/centos-bootc/centos-bootc:stream9 oval eval --results /tmp/results.xml oval.xml
Then, verify we haven't broken scanning old systems on example of the ubi8 image.
sudo podman pull ubi8
sudo oscap-podman ubi8 oval eval --results /tmp/results.xml oval.xml
sudo oscap-podman --oscap=/home/jcerny/work/git/openscap/build/oscap_wrapper ubi8 oval eval --results /tmp/results.xml oval.xml
Also, verify that the probes still work locally.
./oscap_wrapper oval eval --results /tmp/local.xml oval.xml
In each command examine the produced OVAL result carefully and check if there is an item matching every test and check if the collected data comes from the scanned target and not form the host or from elsewhere.