Open JonathonReinhart opened 1 year ago
There is some history to this code:
The mkdir_p is harmless, but the chmod/chown might actually affect the invoking user's home directory if .scuba.yml exists there.
My first thought was to simply remove the chown()
call, since mkdir_p
accepts a mode argument, which is used only if the directory is created. However:
When trying to identify a solution, I realized this problem also exists if scuba
were invoked in /home
(don't ask why anyone would do that):
mkdir_p()
would create nothing, as /home/$USER
(presumably) already exists.chown()
would modify the real (host) /home/$USER
.Going another step, if a user invoked scuba
in /
, this would also happen.
So I guess, before chown
ing the homedir, we need to answer the question:
How do we determine if the path comes from the host? It's not as simple as asking "is this a bind mount", as noted above. I think we need to ask "is this directory, or any directory above it a bind mount?"
Another weird corner case:
/home
or /
$HOMEDIR
somewhere other than /home/$USER
When scubainit creates /home/$USER
it will be created in the host /home/
. Ugh.
Maybe we should just disallow running scuba in /
or /home
...
scubainit
has code to create the user's home dir (in the container), originally thescubauser
: https://github.com/JonathonReinhart/scuba/blob/v2.11.0/scubainit/scubainit.c#L390-L409It will unconditionally
chmod(path, 0700)
andchown(path, uid, gid)
.Usually, this is not a problem because either:
scuba
is invoked from outside/home/$USER
(on the host)scuba
is invoked from a subdirectory of/home/$USER
(on the host)But there is an unlikely corner-case:
scuba
is invoked directory in the/home/$USER
/home/$USER
is the pwd, so it is bind mounted exactly in the container (at the same path).chmod(path, 0700)
runs, it actually affects the directory on the host./home
...Note: We say
/home/$USER
rather than "the home directory" because$HOME
could point somewhere else entirely, and this problem only applies to/home/$USER
because that's whatscubainit
is currently hard-coded to use. (#216 is not yet implemented.)