Skip to content

Always use /var/lib/rpm as rpm dbpath - #1956

Merged
jan-cerny merged 2 commits into
OpenSCAP:maint-1.3from
candrews:rpm-dbpath
Mar 24, 2023
Merged

Always use /var/lib/rpm as rpm dbpath#1956
jan-cerny merged 2 commits into
OpenSCAP:maint-1.3from
candrews:rpm-dbpath

Conversation

@candrews

@candrews candrews commented Mar 12, 2023

Copy link
Copy Markdown
Contributor

Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36) openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work. In implementing this change, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm so /var/lib/rpm still works. So /var/lib/rpm is a dbpath that will work on all systems. Therefore, set the dbpath to be /var/lib/rpm, allow openscap running on any system to scan any system.

See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
Fixes: #1942

cd build && cmake ../ && make -j4 && ctest shows all tests as passing on my Fedora 37 system.

@candrews

candrews commented Mar 12, 2023

Copy link
Copy Markdown
Contributor Author

This issue was initially identified and attempted to be fixed in b0d013a by @matusmarhefka

@jan-cerny

Copy link
Copy Markdown
Member

Thanks for the PR! It looks great, but unfortunately, the tests are failing. I'm trying to investigate the fails and I will let you know once I will have any results.

@jan-cerny

Copy link
Copy Markdown
Member

@candrews I have found it. You need to put the same rpmPushMacro(NULL, "_dbpath", NULL, "/var/lib/rpm", RMIL_CMDLINE); also to src/OVAL/probes/unix/linux/rpmverify_probe.c to rpmverify_probe_init to a similar location as you have done in other files.

@candrews

Copy link
Copy Markdown
Contributor Author

Phenomenal! I've updated this MR with that change; I'm eagerly awaiting the "all tests pass" result 👍

@candrews

Copy link
Copy Markdown
Contributor Author

@jan-cerny everything looks good now - shall this be merged? 🤞

@jan-cerny jan-cerny self-assigned this Mar 22, 2023
@jan-cerny

Copy link
Copy Markdown
Member

@candrews Thank you! We are almost there! The last failing CI job is the Ubuntu job where unfortunately we use some RPM related content for testing the generic data stream processing and the changes in this PR uncovered this. Ideally, we should make the failing tests distribution-agnostic. For this moment we can simply skip these tests on systems where RPM isn't installed. I was able to skip them and make it green on Ubuntu by this change:

diff --git a/tests/DS/test_ds_misc.sh b/tests/DS/test_ds_misc.sh
index 4d3b1ec55..8f2b6cb96 100755
--- a/tests/DS/test_ds_misc.sh
+++ b/tests/DS/test_ds_misc.sh
@@ -77,6 +77,7 @@ sds_add_multiple_twice(){
 
 function test_eval {
     probecheck "rpminfo" || return 255
+    [ -e "/var/lib/rpm" ] || return 255
     local stderr=$(mktemp -t ${name}.out.XXXXXX)
     $OSCAP xccdf eval "${srcdir}/$1" 2> $stderr
     diff /dev/null $stderr; rm $stderr
diff --git a/tests/DS/test_sds_eval.sh b/tests/DS/test_sds_eval.sh
index fc9da3cc5..606bb9150 100755
--- a/tests/DS/test_sds_eval.sh
+++ b/tests/DS/test_sds_eval.sh
@@ -12,6 +12,7 @@ set -e -o pipefail
 
 function test_eval {
     probecheck "rpminfo" || return 255
+    [ -e "/var/lib/rpm" ] || return 255
     local stderr=$(mktemp -t ${name}.out.XXXXXX)
     $OSCAP xccdf eval "${srcdir}/$1" 2> $stderr
     diff /dev/null $stderr; rm $stderr

But I haven't tried if it works on CI.

Ideally, we should make the failing tests distribution-agnostic.
For this moment we can simply skip these tests on systems where RPM isn't installed.

Signed-off-by: Craig Andrews <candrews@integralblue.com>
Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm
Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36)
openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work.
In implementing this change, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm
so /var/lib/rpm still works. So /var/lib/rpm is a dbpath that will work on all systems.
Therefore, set the dbpath to be /var/lib/rpm, allow openscap running on any system to scan any system.

See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
Fixes: OpenSCAP#1942
@candrews

Copy link
Copy Markdown
Contributor Author

But I haven't tried if it works on CI.

I added the change this PR, we'll soon find out!

@candrews

Copy link
Copy Markdown
Contributor Author

we'll soon find out!

All checks have passed 🥳

@jan-cerny jan-cerny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🥳 🍰

@jan-cerny
jan-cerny merged commit 56df23b into OpenSCAP:maint-1.3 Mar 24, 2023
@jan-cerny jan-cerny added this to the 1.3.8 milestone Mar 24, 2023
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.

oscap-podman and oscap-docker evaluate all rules as notapplicable

2 participants