Bug 15454

Summary: wic: rootdirectory of the partition is always owned by root
Product: [Yocto Project Subprojects] Wic Reporter: Pavel Zhukov <pavel>
Component: wicAssignee: Trevor Woerner <twoerner>
Status: ACCEPTED --- QA Contact:
Severity: normal    
Priority: Medium CC: alexandre.belloni, JPEWhacker, randy.macleod, ross.burton, twoerner
Version: v0.3.0   
Target Milestone: v0.4.0   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Pavel Zhukov 2024-03-22 15:48:56 UTC
if image contains a directory (/mydir as an example) which is owned by non-root user and the directory has to be placed on separate partition then root directory of the partition will be created with root:root ownership [1] and directory is not accessible by the original owner after booting.

Here is an example: 

package.bb 

do_install(){
    install -D --owner=user --group=user -m0755 ${D}/mydir
}

wks file:
part /mydir  --source rootfs --rootfs-dir=${IMAGE_ROOTFS}/mydir  --fixed-size 50000 --label=newpart --align 4096 --fstype=ext4

as the result rootfs contains /mydir directory which is owned by "user:user" which is expected but once "newpart" partition is mounted /mydir is owned by root:root and not accessible by "user" anymore. This issue affects only root directory of the partition. Subdirectories' and files' ownership is intact. 



pkg_postinst_ontarget can be used to reset permissions as a workaround however proper fix would be better.

[1]
https://github.com/openembedded/openembedded-core/blob/master/scripts/lib/wic/plugins/source/rootfs.py#L185
Comment 1 Randy MacLeod 2024-03-28 14:37:46 UTC
Alex (CCed) thinks there is a way to work-around the problem.
--YP bug review
Comment 2 Joshua Watt 2024-03-28 14:43:07 UTC
This is intentional and the way mounting works in general. If you want mydir to be owned by user:user after mounting, you need to change the root directory of the image being mounted there to be owned by that user.

IOW, the root directory permissions of a mount replace the permissions of the directory where it is mounted.
Comment 3 Joshua Watt 2024-03-28 14:43:36 UTC
See previous comment
Comment 4 Pavel Zhukov 2024-04-09 12:39:54 UTC
(In reply to Joshua Watt from comment #2)
> This is intentional and the way mounting works in general. If you want mydir
> to be owned by user:user after mounting, you need to change the root
> directory of the image being mounted there to be owned by that user.
> 
> IOW, the root directory permissions of a mount replace the permissions of
> the directory where it is mounted.

This is correct. And this bug has been created exactly with this purpose.
If wic plugin creates mount for such directory the root directory of such image should be owned by the user.
https://github.com/openembedded/openembedded-core/blob/master/scripts/lib/wic/plugins/source/rootfs.py#L185 instead of default mkdir call