Bug 2039261

Summary: dnf --installroot ignores gpg keys in installroot path and requires them to be present in the default path
Product: Red Hat Enterprise Linux 8 Reporter: Marcin Skarbek <redhat>
Component: dnfAssignee: Jaroslav Mracek <jmracek>
Status: CLOSED CANTFIX QA Contact: swm-qe
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.5CC: james.antill, mblaha
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-02-16 15:04:45 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Marcin Skarbek 2022-01-11 11:40:40 UTC
Description of problem:
DNF fails to acknowledge existence of the GPG keys inside `installroot` path and looks for them in default path (/etc/pki/rpm-gpg) on the host. This forces copying key files onto host if we want to maintain `gpgcheck` enabled. 


Version-Release number of selected component (if applicable):
dnf-4.7.0-4.el8.noarch


How reproducible:
Every time.


Steps to Reproduce:
'''bash
# TEMP_ROOT=$(mktemp -d)
# dnf -y install --installroot=${TEMP_ROOT} --releasever=8 https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
(...)
Installed:
  pgdg-redhat-repo-42.0-23.noarch                       redhat-release-8.5-0.8.el8.x86_64                       redhat-release-eula-8.5-0.8.el8.x86_64

Complete!
# ls ${TEMP_ROOT}/etc/pki/rpm-gpg
ISV-Container-signing-key  RPM-GPG-KEY-PGDG  RPM-GPG-KEY-redhat-beta  RPM-GPG-KEY-redhat-release
# dnf install --installroot=${TEMP_ROOT} --releasever=8 postgresql14-server postgresql14-contrib
'''

Actual results:
'''bash
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

PostgreSQL common RPMs for RHEL/CentOS 8 - x86_64                                                                                             385  B/s | 195  B     00:00    
PostgreSQL common RPMs for RHEL/CentOS 8 - x86_64                                                                                             0.0  B/s |   0  B     00:00    
Errors during downloading metadata for repository 'pgdg-common':
  - Curl error (37): Couldn't read a file:// file for file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG [Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG]
Error: Failed to retrieve GPG key for repo 'pgdg-common': Curl error (37): Couldn't read a file:// file for file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG [Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG]
'''

Expected results:
DNF correctly detects GPG keys in `installroot` path and installs packages without error.


Additional info:
Currently, I need to copy GPG keys from ${TEMP_ROOT}/etc/pki/rpm-gpg to /etc/pki/rpm-gpg for DNF to work or use `--nogpgcheck`.

Basically, DNF needs to extend `file://` path of GPG key from repo file by prefixing it with `installroot` path when `installroot` is present.

Comment 1 Jaroslav Mracek 2022-02-16 15:04:45 UTC
I am really sorry, I understand your issue but the change will brake other user cases. The issue can be resolved not only by copy of files but also by manual import of required keys into rpm in installroot. Then dnf will not try to import keys from the location. Additionally you can modify the path to gpg keys directly from command line using --setopt.

dnf install --installroot=${TEMP_ROOT} --releasever=8 postgresql14-server postgresql14-contrib --setopt=pgdg-common.gpgkey=${TEMP_ROOT}/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG

I am really sorry but we cannot do much more.

Comment 2 Marcin Skarbek 2023-05-03 13:39:29 UTC
Can this be resolved properly in RHEL 10?