Skip to content

Commit

Permalink
support --no-home in --oci mode
Browse files Browse the repository at this point in the history
When `--no-home` is set on the CLI in `--oci` mode, do not mount
onto the container home directory.

Fixes #1780
  • Loading branch information
dtrudg committed Jun 16, 2023
1 parent b1828aa commit e808056
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
files on the host that have permissions based on supplementary group
membership. Note that supplementary groups are mapped to `nobody` in the
container, and `chgrp`, `newgrp`, etc. cannot be used.

- OCI-mode now supports the `--no-home` flag, to prevent the container home
directory from being mounted.

### Bug Fixes

- Fix interaction between `--workdir` when given relative path and `--scratch`.
Expand Down
5 changes: 5 additions & 0 deletions e2e/actions/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ func (c actionTests) actionOciExec(t *testing.T) {
argv: []string{"--home", "/tmp:/home", imageRef, "true"},
exit: 0,
},
{
name: "NoHome",
argv: []string{"--no-home", imageRef, "grep", e2e.OCIUserProfile.ContainerUser(t).Dir, "/proc/self/mountinfo"},
exit: 1,
},
{
name: "UTSNamespace",
argv: []string{"--uts", imageRef, "true"},
Expand Down
3 changes: 0 additions & 3 deletions internal/pkg/runtime/launcher/oci/launcher_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ func checkOpts(lo launcher.Options) error {
if lo.WritableTmpfs {
sylog.Infof("--oci mode uses --writable-tmpfs by default")
}
if lo.NoHome {
badOpt = append(badOpt, "NoHome")
}

if len(lo.FuseMount) > 0 {
badOpt = append(badOpt, "FuseMount")
Expand Down
8 changes: 6 additions & 2 deletions internal/pkg/runtime/launcher/oci/mounts_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,17 @@ func (l *Launcher) addSysMount(mounts *[]specs.Mount) error {
// `--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.
// If the $HOME mount is skipped by config or --no-home, we still need to
// handle setting the correct $HOME dir, but just skip adding the mount.
skipMount := false
if !l.singularityConf.MountHome {
sylog.Debugf("Skipping mount of $HOME due to singularity.conf")
skipMount = true
}
if l.cfg.NoHome {
sylog.Debugf("Skipping mount of $HOME due to --no-home")
skipMount = true
}

// Get the host user's data
pw, err := user.CurrentOriginal()
Expand Down

0 comments on commit e808056

Please sign in to comment.