(hostGatewayIP string)
| 66 | } |
| 67 | |
| 68 | func ParentMain(hostGatewayIP string) error { |
| 69 | if !IsRootlessParent() { |
| 70 | return errors.New("should not be called when !IsRootlessParent()") |
| 71 | } |
| 72 | stateDir, err := RootlessKitStateDir() |
| 73 | log.L.Debugf("stateDir: %s", stateDir) |
| 74 | if err != nil { |
| 75 | return fmt.Errorf("rootless containerd not running? (hint: use `containerd-rootless-setuptool.sh install` to start rootless containerd): %w", err) |
| 76 | } |
| 77 | childPid, err := RootlessKitChildPid(stateDir) |
| 78 | if err != nil { |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | detachedNetNSPath, err := detachedNetNS(stateDir) |
| 83 | if err != nil { |
| 84 | return err |
| 85 | } |
| 86 | detachNetNSMode := detachedNetNSPath != "" |
| 87 | log.L.Debugf("RootlessKit detach-netns mode: %v", detachNetNSMode) |
| 88 | |
| 89 | // FIXME: remove dependency on `nsenter` binary |
| 90 | arg0, err := exec.LookPath("nsenter") |
| 91 | if err != nil { |
| 92 | return err |
| 93 | } |
| 94 | // -r/ (root dir) is intentionally omitted. nsenter would open the host |
| 95 | // root fd before setns, then chroot to it after entering the mount |
| 96 | // namespace, anchoring the process to host paths. In rootless mode, |
| 97 | // host dirs owned by real uid 0 (e.g. /var/lib/containerd) are |
| 98 | // inaccessible inside the user namespace and overlay mounts would |
| 99 | // fail with EACCES. |
| 100 | args := []string{arg0} |
| 101 | |
| 102 | // Only append wd if we do have a working dir |
| 103 | // - https://github.com/rootless-containers/usernetes/pull/327 |
| 104 | // - https://github.com/containerd/nerdctl/issues/3328 |
| 105 | wd, err := os.Getwd() |
| 106 | if err != nil { |
| 107 | log.L.WithError(err).Warn("unable to determine working directory") |
| 108 | } else { |
| 109 | args = append(args, "-w"+wd) |
| 110 | os.Setenv("PWD", wd) |
| 111 | } |
| 112 | |
| 113 | args = append(args, "--preserve-credentials", |
| 114 | "-m", "-U", |
| 115 | "-t", strconv.Itoa(childPid), |
| 116 | "-F", // no fork |
| 117 | ) |
| 118 | if !detachNetNSMode { |
| 119 | args = append(args, "-n") |
| 120 | } |
| 121 | args = append(args, os.Args...) |
| 122 | log.L.Debugf("rootless parent main: executing %q with %v", arg0, args) |
| 123 | |
| 124 | // Env vars corresponds to RootlessKit spec: |
| 125 | // https://github.com/rootless-containers/rootlesskit/tree/v0.13.1#environment-variables |
no test coverage detected
searching dependent graphs…