diff --git a/chroot/run.go b/chroot/run.go index fbccbcdb0d..04d735b689 100644 --- a/chroot/run.go +++ b/chroot/run.go @@ -158,7 +158,7 @@ func RunUsingChroot(spec *specs.Spec, bundlePath, homeDir string, stdin io.Reade cmd := unshare.Command(runUsingChrootCommand) cmd.Stdin, cmd.Stdout, cmd.Stderr = stdin, stdout, stderr cmd.Dir = "/" - cmd.Env = append([]string{fmt.Sprintf("LOGLEVEL=%d", logrus.GetLevel())}, os.Environ()...) + cmd.Env = []string{fmt.Sprintf("LOGLEVEL=%d", logrus.GetLevel())} logrus.Debugf("Running %#v in %#v", cmd.Cmd, cmd) confwg.Add(1) @@ -204,6 +204,11 @@ func runUsingChrootMain() { os.Exit(1) } + if options.Spec == nil || options.Spec.Process == nil { + fmt.Fprintf(os.Stderr, "invalid options spec in runUsingChrootMain\n") + os.Exit(1) + } + // Prepare to shuttle stdio back and forth. rootUID32, rootGID32, err := util.GetHostRootIDs(options.Spec) if err != nil { @@ -565,7 +570,7 @@ func runUsingChroot(spec *specs.Spec, bundlePath string, ctty *os.File, stdin io cmd := unshare.Command(append([]string{runUsingChrootExecCommand}, spec.Process.Args...)...) cmd.Stdin, cmd.Stdout, cmd.Stderr = stdin, stdout, stderr cmd.Dir = "/" - cmd.Env = append([]string{fmt.Sprintf("LOGLEVEL=%d", logrus.GetLevel())}, os.Environ()...) + cmd.Env = []string{fmt.Sprintf("LOGLEVEL=%d", logrus.GetLevel())} cmd.UnshareFlags = syscall.CLONE_NEWUTS | syscall.CLONE_NEWNS requestedUserNS := false for _, ns := range spec.Linux.Namespaces { @@ -655,6 +660,11 @@ func runUsingChrootExecMain() { // Set the hostname. We're already in a distinct UTS namespace and are admins in the user // namespace which created it, so we shouldn't get a permissions error, but seccomp policy // might deny our attempt to call sethostname() anyway, so log a debug message for that. + if options.Spec == nil || options.Spec.Process == nil { + fmt.Fprintf(os.Stderr, "invalid options spec passed in\n") + os.Exit(1) + } + if options.Spec.Hostname != "" { if err := unix.Sethostname([]byte(options.Spec.Hostname)); err != nil { logrus.Debugf("failed to set hostname %q for process: %v", options.Spec.Hostname, err) @@ -803,7 +813,6 @@ func runUsingChrootExecMain() { // Output debug messages when that differs from what we're being asked to do. func logNamespaceDiagnostics(spec *specs.Spec) { sawMountNS := false - sawUserNS := false sawUTSNS := false for _, ns := range spec.Linux.Namespaces { switch ns.Type { @@ -838,9 +847,8 @@ func logNamespaceDiagnostics(spec *specs.Spec) { } case specs.UserNamespace: if ns.Path != "" { - logrus.Debugf("unable to join user namespace %q, creating a new one", ns.Path) + logrus.Debugf("unable to join user namespace, sorry about that") } - sawUserNS = true case specs.UTSNamespace: if ns.Path != "" { logrus.Debugf("unable to join UTS namespace %q, creating a new one", ns.Path) @@ -851,9 +859,6 @@ func logNamespaceDiagnostics(spec *specs.Spec) { if !sawMountNS { logrus.Debugf("mount namespace not requested, but creating a new one anyway") } - if !sawUserNS { - logrus.Debugf("user namespace not requested, but creating a new one anyway") - } if !sawUTSNS { logrus.Debugf("UTS namespace not requested, but creating a new one anyway") } diff --git a/docs/buildah-bud.md b/docs/buildah-bud.md index 3857105eb9..116e10b1d9 100644 --- a/docs/buildah-bud.md +++ b/docs/buildah-bud.md @@ -261,11 +261,13 @@ another process. Controls what type of isolation is used for running processes as part of `RUN` instructions. Recognized types include *oci* (OCI-compatible runtime, the default), *rootless* (OCI-compatible runtime invoked using a modified -configuration, with *--no-new-keyring* added to its *create* -invocation, with network and UTS namespaces disabled, and IPC, PID, -and user namespaces enabled; the default for unprivileged users), and -*chroot* (an internal wrapper that leans more toward chroot(1) than -container technology). +configuration, with *--no-new-keyring* added to its *create* invocation, +reusing the host's network and UTS namespaces, and creating private IPC, PID, +mount, and user namespaces; the default for unprivileged users), and *chroot* +(an internal wrapper that leans more toward chroot(1) than container +technology, reusing the host's control group, network, IPC, and PID namespaces, +and creating private mount and UTS namespaces, and creating user namespaces +only when they're required for ID mapping). Note: You can also override the default isolation type by setting the BUILDAH\_ISOLATION environment variable. `export BUILDAH_ISOLATION=oci` diff --git a/docs/buildah-from.md b/docs/buildah-from.md index 87c777b351..7b20d43b80 100644 --- a/docs/buildah-from.md +++ b/docs/buildah-from.md @@ -213,11 +213,13 @@ another process. Controls what type of isolation is used for running processes under `buildah run`. Recognized types include *oci* (OCI-compatible runtime, the default), *rootless* (OCI-compatible runtime invoked using a modified -configuration, with *--no-new-keyring* added to its *create* -invocation, with network and UTS namespaces disabled, and IPC, PID, -and user namespaces enabled; the default for unprivileged users), and -*chroot* (an internal wrapper that leans more toward chroot(1) than -container technology). +configuration, with *--no-new-keyring* added to its *create* invocation, +reusing the host's network and UTS namespaces, and creating private IPC, PID, +mount, and user namespaces; the default for unprivileged users), and *chroot* +(an internal wrapper that leans more toward chroot(1) than container +technology, reusing the host's control group, network, IPC, and PID namespaces, +and creating private mount and UTS namespaces, and creating user namespaces +only when they're required for ID mapping). Note: You can also override the default isolation type by setting the BUILDAH\_ISOLATION environment variable. `export BUILDAH_ISOLATION=oci` diff --git a/docs/buildah-run.md b/docs/buildah-run.md index 6273ce12da..117350b408 100644 --- a/docs/buildah-run.md +++ b/docs/buildah-run.md @@ -76,10 +76,13 @@ process. Controls what type of isolation is used for running the process. Recognized types include *oci* (OCI-compatible runtime, the default), *rootless* (OCI-compatible runtime invoked using a modified configuration, with -*--no-new-keyring* added to its *create* invocation, with network and -UTS namespaces disabled, and IPC, PID, and user namespaces enabled; -the default for unprivileged users), and *chroot* (an internal wrapper -that leans more toward chroot(1) than container technology). +*--no-new-keyring* added to its *create* invocation, reusing the host's network +and UTS namespaces, and creating private IPC, PID, mount, and user namespaces; +the default for unprivileged users), and *chroot* (an internal wrapper that +leans more toward chroot(1) than container technology, reusing the host's +control group, network, IPC, and PID namespaces, and creating private mount and +UTS namespaces, and creating user namespaces only when they're required for ID +mapping). Note: You can also override the default isolation type by setting the BUILDAH\_ISOLATION environment variable. `export BUILDAH_ISOLATION=oci`