JonathonReinhart / scuba

Simple Container-Utilizing Build Apparatus
MIT License
86 stars 15 forks source link

Invoking scuba with pwd at or above /home/$USER (on the host) will chmod it to 0700 #219

Open JonathonReinhart opened 1 year ago

JonathonReinhart commented 1 year ago

scubainit has code to create the user's home dir (in the container), originally the scubauser: https://github.com/JonathonReinhart/scuba/blob/v2.11.0/scubainit/scubainit.c#L390-L409

It will unconditionally chmod(path, 0700) and chown(path, uid, gid).

Usually, this is not a problem because either:

But there is an unlikely corner-case:

$ chmod 755 /home/jreinhart
$ ls -ld /home/jreinhart/
drwxr-xr-x 61 jreinhart jreinhart 4096 Sep  9 22:59 /home/jreinhart/

$ cd /home/jreinhart/
$ scuba --image debian:11 exit
$ ls -ld /home/jreinhart/
drwx------ 61 jreinhart jreinhart 4096 Sep  9 22:59 /home/jreinhart/

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 what scubainit is currently hard-coded to use. (#216 is not yet implemented.)

JonathonReinhart commented 1 year ago

There is some history to this code:

JonathonReinhart commented 1 year ago

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):

Going another step, if a user invoked scuba in /, this would also happen.

So I guess, before chowning 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?"

JonathonReinhart commented 1 year ago

Another weird corner case:

When scubainit creates /home/$USER it will be created in the host /home/. Ugh.

Maybe we should just disallow running scuba in / or /home...