freebsd / poudriere

Port/Package build and test system
https://github.com/freebsd/poudriere/wiki
BSD 2-Clause "Simplified" License
394 stars 163 forks source link

poudriere-image generate wrong / owner with overlaydir option #1181

Open ocochard opened 1 month ago

ocochard commented 1 month ago

Prerequisites

Describe the bug

Generating a poudriere-image with option -c overlaydir, when this directory belongs to a local system user, broke permission on the generated filesystem.

How to reproduce

Steps to reproduce the behavior:

with a local simple user:

mkdir -p /tmp/overlay/root
mkdir -p /tmp/overlay/etc
touch /tmp/overlay/etc/dummy1.txt
touch /tmp/overlay/root/dummy2.txt
sudo poudriere image ... -c /tmp/overlay

The generated image will have all existing directories belonging to an unknown user (because host local user id doesn’t exist on generated image), in this example its /, /etc and /root. These bug is due to the cp -fRpr used.

Expected behavior

We could not preserve original user owner when copying the overlay directory: There is no local user created by default on the targeted disk image, and an already existing directory should not have this owner overwrited.

ocochard commented 1 month ago

A potential replacement of the cp could be something like (cd "${EXTRADIR}" && find . -print0 | cpio -pdm0 --no-preserve-owner ${WRKDIR}/world/)

jlduran commented 37 minutes ago

What I have been doing to work around this issue is having the same uids/gids on the builder as on the target. This way the mapping is one-to-one. Pushing the overlay directory to a git repository, or provisioning form another builder may indeed be problematic.

However, there are times I need to have a specific uid/gid (/tmp/overlay/usr/local/etc/raddb, for example with a uid:gid of 133:133). Perhaps, another option could be an mtree-based solution, where the ownership "metadata" is stored.