Bug 1876828

Summary: dnf list emits a "[Errno 13] Permission denied: '/var/log/rhsm/rhsm.log" message
Product: Red Hat Enterprise Linux 8 Reporter: Greg Kurz <gkurz>
Component: subscription-managerAssignee: mhorky
Status: CLOSED ERRATA QA Contact: Red Hat subscription-manager QE Team <rhsm-qe>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.3CC: cdonnell, csnyder, james.antill, jsefler, mhorky, petersen, redakkan
Target Milestone: rcKeywords: Triaged
Target Release: 8.0Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: subscription-manager-1.28.20-1.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-09 19:37:33 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 Greg Kurz 2020-09-08 09:47:44 UTC
Description of problem:

The 'dnf list' command complains it cannot log to '/var/log/rhsm/rhsm.log'. This seems a little awkward for a supposedly read-only command.

Version-Release number of selected component (if applicable):

dnf-4.2.23-4.el8.noarch

How reproducible:

100%

Steps to Reproduce:
1. dnf list
2.
3.

Actual results:

2020-09-08 05:44:55,232 [ERROR] dnf:8135:MainThread @logutil.py:194 - [Errno 13] Permission denied: '/var/log/rhsm/rhsm.log' - Further logging output will be written to stderr
Not root, Subscription Management repositories not updated

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Last metadata expiration check: 0:36:02 ago on Tue 08 Sep 2020 05:08:53 AM EDT.
Installed Packages
...

Expected results:

Not root, Subscription Management repositories not updated

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Last metadata expiration check: 0:36:02 ago on Tue 08 Sep 2020 05:08:53 AM EDT.
Installed Packages
...


Additional info:

Same happens with other read-only sub-commands, eg. 'info', 'search' or 'module list'.

Comment 1 Daniel Mach 2020-09-08 11:01:56 UTC
I believe this is caused by calling the subscription-manager plugin. Reassigning to that component.

Comment 3 Rehana 2021-07-29 12:25:19 UTC
Reproducing the issue :
====================

# subscription-manager version
server type: This system is currently not registered.
subscription management server: 3.2.19-1
subscription management rules: 5.41
subscription-manager: 1.28.19-1.el8

# su test

$ yum repolist

2021-07-28 17:46:04,252 [ERROR] yum:16336:MainThread @logutil.py:221 - [Errno 13] Permission denied: '/var/log/rhsm/rhsm.log' - Further logging output will be written to stderr
Not root, Subscription Management repositories not updated

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

No repositories available

$ dnf module list
2021-07-28 17:46:17,121 [ERROR] dnf:16342:MainThread @logutil.py:221 - [Errno 13] Permission denied: '/var/log/rhsm/rhsm.log' - Further logging output will be written to stderr
Not root, Subscription Management repositories not updated

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

@modulefailsafe
Name                                      Stream                                       Profiles                                     Summary                                                  
virt                                      rhel [e]                                     common                                       Virtualization module                                    

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

$ dnf info zsh
2021-07-28 17:46:20,357 [ERROR] dnf:16346:MainThread @logutil.py:221 - [Errno 13] Permission denied: '/var/log/rhsm/rhsm.log' - Further logging output will be written to stderr
Not root, Subscription Management repositories not updated

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

Error: No matching Packages to list

Pre-verifying with the fix:
==========================
# subscription-manager version
server type: Red Hat Subscription Management
subscription management server: 3.2.19-1
subscription management rules: 5.41
subscription-manager: 1.28.19-1.git.6.c1dd7c3.el8

switch to a non-root user 
=========================
with the fix when a non-root operates the dnf commands , the error logs will be added to $XDG_CACHE_HOME/rhsm/rhsm.log

$ ll -lh ~/.cache/rhsm/rhsm.log
-rw-rw-r--. 1 test test 0 Jul 29 15:18 /home/test/.cache/rhsm/rhsm.log

$ tail ~/.cache/rhsm/rhsm.log
1) module list 

$ dnf module list
Not root, Subscription Management repositories not updated
Red Hat Enterprise Linux 8 for x86_64 - BaseOS Beta (RPMs)                                                                                                                        406  B/s | 361  B     00:00    
Errors during downloading metadata for repository 'rhel-8-for-x86_64-baseos-beta-rpms':
  - Status code: 403 for https://cdn.redhat.com/content/beta/rhel8/8/x86_64/baseos/os/repodata/repomd.xml (IP: 2.16.212.251)
Error: Failed to download metadata for repo 'rhel-8-for-x86_64-baseos-beta-rpms': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

$ tail ~/.cache/rhsm/rhsm.log
2021-07-29 15:19:09,704 [ERROR] dnf:51036:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'

^NOTICE the error log is added to ~/.cache/rhsm/rhsm.log

2) Yum repolist 

$ yum repolist
Not root, Subscription Management repositories not updated
repo id                                                                                      repo name
rhel-8-for-x86_64-appstream-beta-rpms                                                        Red Hat Enterprise Linux 8 for x86_64 - AppStream Beta (RPMs)
rhel-8-for-x86_64-baseos-beta-rpms                                                           Red Hat Enterprise Linux 8 for x86_64 - BaseOS Beta (RPMs)

$ tail ~/.cache/rhsm/rhsm.log
2021-07-29 15:19:09,704 [ERROR] dnf:51036:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'
2021-07-29 15:19:29,793 [ERROR] yum:51048:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'

^NOTICE the error log is added to ~/.cache/rhsm/rhsm.log

3) package info

$ dnf info zsh
Not root, Subscription Management repositories not updated
Red Hat Enterprise Linux 8 for x86_64 - BaseOS Beta (RPMs)                                                                                                                        115  B/s | 361  B     00:03    
Errors during downloading metadata for repository 'rhel-8-for-x86_64-baseos-beta-rpms':
  - Status code: 403 for https://cdn.redhat.com/content/beta/rhel8/8/x86_64/baseos/os/repodata/repomd.xml (IP: 2.16.212.251)
Error: Failed to download metadata for repo 'rhel-8-for-x86_64-baseos-beta-rpms': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

$ tail ~/.cache/rhsm/rhsm.log
2021-07-29 15:19:09,704 [ERROR] dnf:51036:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'
2021-07-29 15:19:29,793 [ERROR] yum:51048:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'
2021-07-29 15:19:39,117 [ERROR] dnf:51055:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'

^NOTICE the error log is added to ~/.cache/rhsm/rhsm.log

4) Install pacakges

$ yum install zsh
Not root, Subscription Management repositories not updated
Error: This command has to be run with superuser privileges (under the root user on most systems).

$ tail ~/.cache/rhsm/rhsm.log
2021-07-29 15:19:09,704 [ERROR] dnf:51036:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'
2021-07-29 15:19:29,793 [ERROR] yum:51048:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'
2021-07-29 15:19:39,117 [ERROR] dnf:51055:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'
2021-07-29 15:19:47,672 [ERROR] yum:51061:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'


^NOTICE the error log is added to ~/.cache/rhsm/rhsm.log


Based on the above observation preverifying the bug .

Comment 6 Rehana 2021-08-09 14:28:37 UTC
Verifying on :

# rpm -qa subscription-manager --changelog | grep 1876828
- 1876828: Try to suppress errors in stderr when not run as root

# subscription-manager version
server type: Red Hat Subscription Management
subscription management server: 3.2.19-1
subscription management rules: 5.41
subscription-manager: 1.28.20-1.el8

# subscription-manager register --auto-attach --username=**** --password=*****
Registering to: subscription.rhsm.stage.redhat.com:443/subscription
The system has been registered with ID: *********
The registered system name is: *********
Installed Product Current Status:
Product Name: Red Hat Enterprise Linux for x86_64 Beta
Status:       Subscribed

# su - test
Last login: Mon Aug  9 10:23:46 EDT 2021 on pts/0

$ yum repolist
Not root, Subscription Management repositories not updated
repo id                                repo name
rhel-8-for-x86_64-appstream-beta-rpms  Red Hat Enterprise Linux 8 for x86_64 - AppStream Beta (RPMs)
rhel-8-for-x86_64-baseos-beta-rpms     Red Hat Enterprise Linux 8 for x86_64 - BaseOS Beta (RPMs)

$ ll -lh ~/.cache/rhsm/rhsm.log
-rw-rw-r--. 1 test test 220 Aug  9 10:23 /home/test/.cache/rhsm/rhsm.log

$ dnf module list
Not root, Subscription Management repositories not updated
Red Hat Enterprise Linux 8 for x86_64 - AppStream Beta (RPMs)        621  B/s | 512  B     00:00    
Red Hat Enterprise Linux 8 for x86_64 - BaseOS Beta (RPMs)           571  B/s | 512  B     00:00    
@modulefailsafe
Name                Stream                 Profiles               Summary                            
virt                rhel [e]               common                 Virtualization module              

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

$ dnf info zsh
Not root, Subscription Management repositories not updated
Last metadata expiration check: 0:00:15 ago on Mon 09 Aug 2021 10:26:08 AM EDT.
Error: No matching Packages to list

$ yum install zsh
Not root, Subscription Management repositories not updated
Error: This command has to be run with superuser privileges (under the root user on most systems)

$ tail ~/.cache/rhsm/rhsm.log
2021-08-09 10:23:56,035 [ERROR] yum:16613:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'
2021-08-09 10:26:06,561 [ERROR] dnf:16669:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'
2021-08-09 10:26:23,064 [ERROR] dnf:16686:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'
2021-08-09 10:26:47,414 [ERROR] yum:16698:MainThread @identity.py:156 - Reload of consumer identity cert /etc/pki/consumer/cert.pem raised an exception with msg: [Errno 13] Permission denied: '/etc/pki/consumer/key.pem'

^^ Notice now the error logs are added to ~/.cache/rhsm/rhsm.log location . Based on the above observation, moving the bug to Verified!!

Comment 9 errata-xmlrpc 2021-11-09 19:37:33 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (subscription-manager bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:4390