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:


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2013:1688 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@redhat.com>
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.