1

I am trying to give all Users on a system their own writable copy of a root-owned directory, and OverlayFS sounds like the tool for the job, but I am finding it not as straightforward as it sounded at first.

First, the setup:

> mkdir upper work merged merged-user
> sudo mkdir -p lower/path/to
> sudo touch lower/path/to/file
> ls -l
drwx------ 2 user group 4096 Aug 10 00:00 merged
drwx------ 2 user group 4096 Aug 10 00:00 merged-user
drwxr-xr-x 3 root root  4096 Aug 10 00:00 lower
drwx------ 2 user group 4096 Aug 10 00:00 upper
drwx------ 2 user group 4096 Aug 10 00:00 work

The goal at the end is to allow User user to write to any directory or path in the merged or merged-user mount point.

First attempt, with mount:

> sudo mount -t overlay overlay -o "lowerdir=$PWD/lower,upperdir=$PWD/upper,workdir=$PWD/work" merged
> ls -l merged/path/to
total 4
-rw-r--r-- 1 root root 5 Aug 10 00:00 file
> echo me > merged/path/to/file 
sh: merged/path/to/file: Permission denied

I get it; at the kernel level, OverlayFS isn't touching the permissions, so the merged directory doesn't have the permissions setup I would like. Enter fuse-overlayfs:

fuse-overlayfs -o "lowerdir=lower,upperdir=upper,workdir=work,squash_to_uid=$(id -u)" merged-user
> ls -la merged-user/
total 8
drwx------ 3 user group 4096 Aug 10 00:00 .
drwxr-xr-x 3 root root  4096 Aug 10 00:00 path
> echo me > merged-user/path/to/file 
sh: merged-user/path/to/file: Permission denied

Still permission denied, even with the squash_to_uid option. Am I missing some other parameter that would enabled merged or merged-user to appear as the User's own directories?

1
  • 1
    Probably, some readers will ask why do this, since root can read the files whoever they belong to? However, you might try another fuse fs bindfs. I'm not sure that it does what you want. There's an old example too. Commented Aug 11, 2024 at 7:44

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.