rpm-software-management / dnf

Package manager based on libdnf and libsolv. Replaces YUM.
GNU General Public License v2.0
1.22k stars 405 forks source link

check-update --cache-only does not work with repo_gpgcheck=1 #2079

Open creshal opened 3 months ago

creshal commented 3 months ago

If I run dnf makecache to create an up to date system cache (no errors, no warnings, all GPG keys imported into the system cache), and then run dnf check-update --cacheonly, it fails for various external repositories that have repo_gpgcheck enabled:

$ sudo -u foobar dnf check-update --cacheonly --assumeno
Importing GPG key [keyid]:
  [ . . . key details . . . ]
Error: Cache-only enabled but no cache for 'foo-rpm_release'

It does not matter whether the key is a local key under /etc/pki or via https, the error is the same; in any case, the root user has these keys successfully imported already.

It should be obvious that simply disabling gpg checking is not a proper solution.

ppisar commented 3 months ago

I'm sorry, I cannot reproduce it with the latest code from git repository. What dnf, libdnf, librepo, rpm versions do you use? Is your librepo built with gpgme or rpm (cmake -DUSE_GPGME=OFF) as a cryptographic backend?

"dnf makecache" does not import the key into RPM database. It copies it into dnf cache in /var/cache/dnf/REPO_ID-HASH/pubring directory and import it from there into RPM database later when an package with an unknown key is to be installed. If you librepo built with gpgme backend, then it's more complicated.

It looks like your DNF run under your non-root user does not have an access to the cached key.

creshal commented 3 months ago

Oracle Linux 8.9 and 9.3, so dnf 4.7.0 and 4.14.0, and librepo 1.14.2 to 1.14.5. As far as I can tell, they don't set any particular backend, and librepo links against gpgme on both.

It looks like your DNF run under your non-root user does not have an access to the cached key.

Indeed, but I have no idea why: Some GPG keys import just fine (bareos e.g., using its default script), some just don't work at all (prometheus-rpm works neither with its default https://… entry nor a locally downloaded file://… entry, and -v doesn't show any warnings/debug info. Makecache as root user imports the key just fine in all cases. (And the unprivileged users can read the key files just fine, there are no permission problems as far as I can see.)

Reproducing this with a fresh Rocky 9.3 VM:

So I'm not sure why some keys are accessibly, but some not. I'll see if I can update dnf to the repository version on a test VM and if that fixes it.