Bug 788641

Summary: virt-edit doesn't preserve file permissions
Product: [Community] Virtualization Tools Reporter: Richard W.M. Jones <rjones>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED UPSTREAM QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: mbooth, virt-maint
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 788642 (view as bug list) Environment:
Last Closed: 2012-02-09 18:34:41 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 788642    

Description Richard W.M. Jones 2012-02-08 17:16:36 UTC
Description of problem:

virt-edit creates a new file when it is used.  Unfortunately
this means that the old file's permissions, SELinux context
etc are lost.

virt-edit should preserve all of this by copying it from the
old file to the new file.

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

1.17.5

How reproducible:

100%

Steps to Reproduce:

This reproducer uses the phony Fedora test image from
libguestfs, but any Linux guest image would do.

$ cd libguestfs
$ cp tests/guests/fedora.img /tmp
$ ./run ./fish/guestfish -a /tmp/fedora.img -i \
      write /test "hello" : chmod 0600 /test : ll /test
$ ./run ./edit/virt-edit -a /tmp/fedora.img /test -e 's/hello/goodbye/'
$ ./run ./fish/guestfish -a /tmp/fedora.img -i \
      ll /test : cat /test : rm /test

Actual results:

The commands above print:

-rw------- 1 root root 5 Feb  8 17:14 /sysroot/test
-rw-r--r-- 1 root root 7 Feb  8 17:15 /sysroot/test
goodbye

which shows that the permissions have changed.

Expected results:

Permissions, SELinux context etc should be preserved.

Additional info:

Comment 1 Richard W.M. Jones 2012-02-08 17:19:15 UTC
Are there other tools which don't and should preserve permissions?

Comment 2 Richard W.M. Jones 2012-02-08 18:25:08 UTC
The answer to comment 1 appears to be 'no'.

Patch posted upstream which preserves file mode, UID, GID
and SELinux context:

https://www.redhat.com/archives/libguestfs/2012-February/msg00033.html

Comment 3 Richard W.M. Jones 2012-02-09 18:34:41 UTC
This will be fixed upstream in 1.17.6.