An ideally least privileged process should be able to have readonly access to data on a filesystem, which itself is readonly. Hence this is the situation
root@linux# ###(1) filesystem is untrusted + readonly
root@linux# grep untrusted_ro_fs /proc/mounts
/dev/sdb1 /mnt/untrusted_ro_fs ext4 ro 0 0
root@linux# ###(2) no read permissions for (o)thers for /mnt/untrusted_ro_fs/root
root@linux# ls -ld /mnt/untrusted_ro_fs/root
drwxr-x--- 1 root root 1138 Jul 3 21:13 /mnt/untrusted_ro_fs/root
root@linux# ###(3a) unpriviledge process ls (run with uid=9999 and gid=9999) no read access
root@linux# setpriv --reuid=9999 --regid=9999 --clear-groups ls /mnt/untrusted_ro_fs/root
ls: cannot open directory '/root': Permission denied
root@linux# ###(3b) unpriviledge process cat (run with uid=9999 and gid=9999) no read access
root@linux# setpriv --reuid=9999 --regid=9999 --clear-groups cat /mnt/untrusted_ro_fs/root/file
cat: /mtn/untrusted_ro_fs/root/file: Permission denied
root@linux# ###(4) file permission change fails on ro filesystem
root@linux# chmod a+rx /mnt/untrusted_ro_fs/root/
chmod: changing permissions of '/mnt/untrusted_ro_fs/root/': Read-only file system
I seek answers how to accomplish above read access (3a + 3b). This are the pathways I have come up with. Ideally answers would either a) provide alternative solutions or b) elaborate on those provided:
a) "daemon-style privelege drop": opening file-descriptors as root and subsequently
setuid
inside the process.b) "using FIFOs" which appears only to help with (3b)
root@linux# mkfifo /access_to_root_file.fifo
root@linux# chown root:9999 /access_to_root_file.fifo
root@linux# chmod 0640 /access_to_root_file.fifo
root@linux# cat /mnt/untrusted_ro_fs/root/file > /access_to_root_file.fifo &
root@linux# setpriv --reuid=9999 --regid=9999 --clear-groups cat /access_to_root_file.fifo
c) "overlayfs"
root@linux# mkdir /mnt/upper /mnt/work /mnt/merged
root@linux# mount -t overlay overlay -o lowerdir=/mnt/untrusted_ro_fs,upperdir=/mnt/upper,workdir=/mnt/work /mnt/merged
root@linux# chmod a+rx /mnt/merged/root
root@linux# setpriv --reuid=9999 --regid=9999 --clear-groups ls /mnt/merged/root &>/dev/null && echo SUCCESS-ls
SUCCESS
root@linux# chmod a+rx /mnt/merged/root/file
root@linux# setpriv --reuid=9999 --regid=9999 --clear-groups cat /mnt/merged/root/file &>/dev/null && echo SUCCESS-cat
SUCCESS
d) "virtualization" (i.e. kvv + qemu) where the readonly access to blockdevice of untrusted filesystem is setup for the vm.
bindfs
I have to wonder though, is it possible to have a "thumb-rule" forbindfs
being FUSE if this is a) "security" is FUSE already safer (not in kernel) or less rather less safe (added complexity) and b) is the general idead true that this solution comes at a cost of performance (user vs. kernel)? – humanityANDpeace Jul 05 '21 at 06:11