RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 888724 - sos does not preserve permissions on collected files
Summary: sos does not preserve permissions on collected files
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: sos
Version: 6.4
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Bryn M. Reeves
QA Contact: Filip Holec
URL:
Whiteboard:
: 1003550 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-12-19 10:46 UTC by Bryn M. Reeves
Modified: 2018-12-03 18:04 UTC (History)
11 users (show)

Fixed In Version: sos-2.2-42.el6
Doc Type: Bug Fix
Doc Text:
Cause: Previous versions of sos failed to preserve the permissions of files collected from the host file system. Consequence: Permission information in sosreport archives is inconsistent with permissions on the host system potentially misleading users. Fix: Permissions data is now copied for all files copied from the host file system. Result: Permissions reflected in sosreport archives now match those reported on the host system.
Clone Of:
Environment:
Last Closed: 2013-11-21 22:37:29 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2013:1688 0 normal SHIPPED_LIVE sos bug fix and enhancement update 2013-11-21 00:39:30 UTC

Description Bryn M. Reeves 2012-12-19 10:46:10 UTC
Description of problem:
sos-2.2 does not preserve permissions on files copied into the archive:

# ll /etc/host.conf 
----------. 1 root root 26 Jan 12  2010 /etc/host.conf
# ll rhel6-vm1-2012121910251355912727/etc/host.conf 
-rw-r--r--. 1 root root 26 Dec 19 10:25 rhel6-vm1-2012121910251355912727/etc/host.conf

This is a regression from RHEL5:

# uname -r
2.6.18-308.1.1.el5
# ll /etc/host.conf 
---------- 1 root root 17 Oct 31 15:07 /etc/host.conf
# ll pe1950-2-318659/etc/host.conf 
---------- 1 root root 17 Oct 31 15:07 pe1950-2-318659/etc/host.conf

Appears to be a regression introduced with the switch to shutils from calling out to 'cp' during el6 development.

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

How reproducible:
100%

Steps to Reproduce:
1. Make a file sos collects have an 'odd' mode
2. Run sos
3. Extract archive
4. ls -l $that_file
  
Actual results:
# ll rhel6-vm1-2012121910251355912727/etc/host.conf 
-rw-r--r--. 1 root root 26 Dec 19 10:25 rhel6-vm1-2012121910251355912727/etc/host.conf

Expected results:
# ll rhel6-vm1-2012121910251355912727/etc/host.conf 
----------. 1 root root 26 Dec 19 10:25 rhel6-vm1-2012121910251355912727/etc/host.conf

Additional info:
Preserving permissions is the expected behaviour of all versions of sos. This is needed to support useful analysis-side diagnostics.

Comment 1 Bryn M. Reeves 2012-12-19 21:10:21 UTC
commit 2ab4529daad2fd133d91379ce94a297d037fd372
Author: Bryn M. Reeves <bmr>
Date:   Wed Dec 19 21:06:19 2012 +0000

    Preserve ownership and permission on copied files
    
    Preserve the ownership and permission information for collected
    files by using shutil.copy2 instead of copyfileobj() and calling
    os.chown() after copying.

diff --git a/sos/plugintools.py b/sos/plugintools.py
index 39b2368..ea29ea9 100644
--- a/sos/plugintools.py
+++ b/sos/plugintools.py
@@ -232,11 +232,9 @@ class PluginBase:
                 linkto = os.readlink(src)
                 os.symlink(linkto, new_fname)
             else:
-                fsrc = open(src,'r')
-                fdst = open(new_fname, 'w') 
-                shutil.copyfileobj(fsrc, fdst, -1)
-                fsrc.close()
-                fdst.close()
+                shutil.copy2(src, new_fname)
+                stat = os.stat(src)
+                os.chown(new_fname, stat.st_uid, stat.st_gid)
         else:
             raise PluginException('Error copying file: already exists')

Comment 6 Bryn M. Reeves 2013-09-02 12:12:13 UTC
*** Bug 1003550 has been marked as a duplicate of this bug. ***

Comment 9 errata-xmlrpc 2013-11-21 22:37:29 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, and where to find the updated
files, follow the link below.

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

http://rhn.redhat.com/errata/RHBA-2013-1688.html


Note You need to log in before you can comment on or make changes to this bug.