Skip to content

Commit

Permalink
fix: set correct $HOME in --oci mode when mount home = no
Browse files Browse the repository at this point in the history
When `mount home = no` is set in `singularity.conf`, we still need to
set the correct value for `$HOME` in the container... we just don't
want to mount it.

Fixes sylabs/singularity#1783

Signed-off-by: Edita Kizinevic <edita.kizinevic@cern.ch>
  • Loading branch information
dtrudg authored and edytuk committed Jul 11, 2023
1 parent 6d76ee5 commit e0ec24b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
11 changes: 11 additions & 0 deletions e2e/config/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ func (c configTests) ociConfigGlobal(t *testing.T) {
directiveValue: "no",
exit: 1,
},
// Verify that though mount is skipped, $HOME is still set correctly
// https://github.com/sylabs/singularity/issues/1783
{
name: "MountHomeNoCorrectDir",
argv: []string{archiveRef, "sh", "-c", "test $HOME == " + e2e.OCIUserProfile.ContainerUser(t).Dir},
profile: e2e.OCIUserProfile,
cwd: "/",
directive: "mount home",
directiveValue: "no",
exit: 0,
},
{
name: "MountHomeYes",
argv: []string{archiveRef, "grep", e2e.OCIUserProfile.ContainerUser(t).Dir, "/proc/self/mountinfo"},
Expand Down
25 changes: 21 additions & 4 deletions internal/pkg/runtime/launcher/oci/mounts_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,17 @@ func (l *Launcher) addSysMount(mounts *[]specs.Mount) error {
return nil
}

// addHomeMount adds a user home directory as a tmpfs mount. We are currently
// emulating `--compat` / `--containall`, so the user must specifically bind in
// their home directory from the host for it to be available.
// addHomeMount adds a user home directory as a tmpfs mount, and sets the
// container home directory. We are currently emulating `--compat` /
// `--containall`, so the user must specifically bind in their home directory
// from the host for it to be available.
func (l *Launcher) addHomeMount(mounts *[]specs.Mount) error {
// If the $HOME mount is skipped by config need to still handle setting the
// correct $HOME dir, but just skip adding the mount.
skipMount := false
if !l.apptainerConf.MountHome {
sylog.Debugf("Skipping mount of $HOME due to apptainer.conf")
return nil
skipMount = true
}

// Get the host user's data
Expand All @@ -295,6 +299,10 @@ func (l *Launcher) addHomeMount(mounts *[]specs.Mount) error {
homeDest := homeSlice[1]
l.cfg.HomeDir = homeDest

if skipMount {
return nil
}

// Since the home dir is a bind-mount in this case, we don't have to mount a tmpfs directory for the in-container home dir, and we can just do the bind-mount & return.
return addBindMount(mounts, bind.Path{
Source: homeSrc,
Expand All @@ -305,6 +313,11 @@ func (l *Launcher) addHomeMount(mounts *[]specs.Mount) error {
// If we're running in fake-root mode (and we haven't requested a custom home dir), we do need to create a tmpfs mount for the home dir, but it's a special case (because of its location & permissions), so we handle that here & return.
if l.cfg.Fakeroot {
l.cfg.HomeDir = "/root"

if skipMount {
return nil
}

*mounts = append(*mounts,
specs.Mount{
Destination: "/root",
Expand All @@ -325,6 +338,10 @@ func (l *Launcher) addHomeMount(mounts *[]specs.Mount) error {
l.cfg.HomeDir = pw.Dir
}

if skipMount {
return nil
}

// If we've not hit a special case (bind-mounted custom home dir, or fakeroot), then create a tmpfs mount as a home dir in the requested location (whether it's custom or not; by this point, l.cfg.HomeDir will reflect the right value).
*mounts = append(*mounts,
specs.Mount{
Expand Down

0 comments on commit e0ec24b

Please sign in to comment.