if part of home path is in '--pwd', '--no-home' is ignored, HOME folder contents are mounted
Version of Singularity:
3.3.0-1
Expected behavior
Home directory should not be mounted to the image if '--no-home' flag is provided, no matter what is set for '--pwd'.
Actual behavior
if part of HOME path is in '--pwd', '--no-home' is ignored, home directory contents are mounted to the image.
Steps to reproduce behavior
$ echo $HOME
/home/ubuntu
$ singularity pull docker://ubuntu
$ ls ~
cgprna_2.3.1.sif go singularity singularity-3.2.0.tar.gz singularity-3.3.0.tar.gz
$ cd /tmp
# This is not expected behavior
$ singularity exec --no-home --pwd /home/ubuntu /home/ubuntu/ubuntu_latest.sif ls /home/ubuntu
cgprna_2.3.1.sif go singularity singularity-3.2.0.tar.gz singularity-3.3.0.tar.gz ubuntu_latest.sif
# This is not expected behavior
$ singularity exec --no-home --pwd /home /home/ubuntu/ubuntu_latest.sif ls /home/ubuntu
cgprna_2.3.1.sif go singularity singularity-3.2.0.tar.gz singularity-3.3.0.tar.gz ubuntu_latest.sif
# This is expected
$ singularity exec --no-home --pwd /tmp /home/ubuntu/ubuntu_latest.sif ls /home/ubuntu
ls: cannot access '/home/ubuntu': No such file or directory
I think this behavior is reasonable. It doesn't set $HOME inside the container, does it?
@DrDaveD No, it isn't reasonable. The --pwd flag IMO, should just change your directory in the container, not modify the bind mounts that are happening. And it's any directory, not just your $HOME.
For example, if I do:
singularity exec --no-home --pwd /home/user_home2 myimage.sif [...]
Then /home/user_home2 is bind mounted from the host, even though nothing else from the host /home is accessible.
@byb121 ... With your example of:
singularity exec --no-home --pwd /home/ubuntu /home/ubuntu/ubuntu_latest.sif ls /home/ubuntu
That should fail changing to the /home/ubuntu directory (assuming we aren't mounting it, and you didn't create it), and you'll end up with a working directory of / since /home/ubuntu shouldn't exist. That is the behavior you are expecting yes?
I believe the paths order is: pwd, $HOME, /
Ok having an option to only change dir and not do a bind mount does seem like a reasonable thing to have, but the --pwd option of singularity has always done that so I think it's a little too late to change at this point. There's likely a lot of scripts that depend on that. Probably the documentation should be changed to be more explicit that that's what it's doing.
I think I know what it is ... This is guessing until I can talk with some folks that know this part of the code better.
But I think what is happening is that we're making a chdir() call to the value given on the --pwd command line. Then we're mounting the current working directory. We mount the CWD by default ... and since we just changed our Working directory, the value we put on the --pwd line is the one that gets mounted.
That, IMO, is a bug. The help states that --pwd is to affect the "process inside the container", and not the outside.
@mem @bauerm97 @cclerget Does the above seem right to you on what's happening?
the --pwd option of singularity has always done that
2.6.1 I have installed does not bind mount the host directory. If 3.x has always done that, then that's been a bug (IMO) in 3.x that we're just now having come to light. :/
The help for the --pwd option also only references the container payload, nothing about modifying how the host sees the mounts. I would expect my CWD that gets mounted, to be the directory I'm in, not the directory I specify with the --pwd option.
You're right, I was remembering the 2.x behavior incorrectly. So we do have a difference in behavior between 2.x & 3.x, not good. In fact I don't see 2.6.1 bind-mounting the CWD at all, which really surprises me because I thought it did. Even the --no-home option there, which is described as "Do NOT mount users home directory if home is not the current working directory" did not operate as described because it did not mount the home directory when the CWD was the home directory. (Note that my home directory is not under /home and I have sometimes seen anomalies because of that).
In fact I don't see 2.6.1 bind-mounting the CWD at all, which really surprises me because I thought it did.
I agree... I wrote the --no-home option and I explicitly didn't want to mess with the working directory mounting. :/ Just have a way to control the mounting if the admin set automatic home mounting to true.
@jmstover I agree with you. As you said, from a user aspect --pwd should only set the landing point inside the container, at least that's what pwd really means to me. If the path does not exist, either returning an error or landing to a default location is acceptable.
@DrDaveD --no-home is explicitly defined in doc that should stop mounting the home directory. If --pwd wants to mount the home, I think an error should be raised, as the two options are conflicting.
IMO, all of the mounts should be handled by --bind, those default mounts and --home is a bit messy.
If the path does not exist, either returning an error or landing to a default location is acceptable.
I don't think it will error (pretty sure there's a warning message printed). I think it goes:
[value of --pwd]
$HOME
/
So, if all else fails, you end up at / in the container.
As you said, from a user aspect
--pwdshould only set the landing point inside the container, at least that's whatpwdreally means to me. If the path does not exist, either returning an error or landing to a default location is acceptable.
User +1s on this perspective! I didn't know that --pwd would cause some binding side-effects. I came here from #4132 which might be related
Yeah... that's the only effect that I expect as well.
It seems that when you specify the --pwd flag, the process CWD gets changed to the value of --pwd early in the process run. Which has mounting side effects because of the auto CWD mount. And the CWD you think you're in when you run singularity, isn't the CWD seen for the automount.
So.... @mem @bauerm97 @cclerget any idea's
so, I wonder what the verdict will be? IMHO it should be "remove bind mounting of path specified in --pwd" since I might like to point PWD to some path inside container which might or might not have corresponding counter part on the system. I really would hate to see side effects while running across boxes where such directory might or might not exist on the system. If it is desired to be mounted -- it should be listed explicitly among binds.
Should be fixed by #4250 which get rid of mounting --pwd as the current working directory which is indeed a wrong behavior