// Run mounts the right overlay filesystems and actually runs the prepared // pod by exec()ing the stage1 init inside the pod filesystem. func Run(cfg RunConfig, dir string, dataDir string) { useOverlay, err := preparedWithOverlay(dir) if err != nil { log.Fatalf("error: %v", err) } privateUsers, err := preparedWithPrivateUsers(dir) if err != nil { log.Fatalf("error: %v", err) } debug("Setting up stage1") if err := setupStage1Image(cfg, dir, useOverlay); err != nil { log.Fatalf("error setting up stage1: %v", err) } debug("Wrote filesystem to %s\n", dir) for _, app := range cfg.Apps { if err := setupAppImage(cfg, app.Name, app.Image.ID, dir, useOverlay); err != nil { log.Fatalf("error setting up app image: %v", err) } } destRootfs := common.Stage1RootfsPath(dir) flavor, err := os.Readlink(filepath.Join(destRootfs, "flavor")) if err != nil { log.Printf("error reading flavor: %v\n", err) } if flavor == "kvm" { err := kvmCheckSSHSetup(destRootfs, dataDir) if err != nil { log.Fatalf("error setting up ssh keys: %v", err) } } if err := os.Setenv(common.EnvLockFd, fmt.Sprintf("%v", cfg.LockFd)); err != nil { log.Fatalf("setting lock fd environment: %v", err) } if err := os.Setenv(common.EnvSELinuxContext, fmt.Sprintf("%v", cfg.ProcessLabel)); err != nil { log.Fatalf("setting SELinux context environment: %v", err) } debug("Pivoting to filesystem %s", dir) if err := os.Chdir(dir); err != nil { log.Fatalf("failed changing to dir: %v", err) } ep, err := getStage1Entrypoint(dir, runEntrypoint) if err != nil { log.Fatalf("error determining 'run' entrypoint: %v", err) } args := []string{filepath.Join(destRootfs, ep)} debug("Execing %s", ep) if cfg.Debug { args = append(args, "--debug") } args = append(args, "--net="+cfg.Net.String()) if cfg.Interactive { args = append(args, "--interactive") } if len(privateUsers) > 0 { args = append(args, "--private-users="+privateUsers) } if cfg.MDSRegister { mdsToken, err := registerPod(".", cfg.UUID, cfg.Apps) if err != nil { log.Fatalf("failed to register the pod: %v", err) } args = append(args, "--mds-token="+mdsToken) } if cfg.LocalConfig != "" { args = append(args, "--local-config="+cfg.LocalConfig) } args = append(args, cfg.UUID.String()) // make sure the lock fd stays open across exec if err := sys.CloseOnExec(cfg.LockFd, false); err != nil { log.Fatalf("error clearing FD_CLOEXEC on lock fd") } tpmEvent := fmt.Sprintf("rkt: Rootfs: %s Manifest: %s Stage 1 args: %s", cfg.CommonConfig.RootHash, cfg.CommonConfig.ManifestData, strings.Join(args, " ")) // If there's no TPM available or there's a failure for some other // reason, ignore it and continue anyway. Long term we'll want policy // that enforces TPM behaviour, but we don't have any infrastructure // around that yet. _ = tpm.Extend(tpmEvent) if err := syscall.Exec(args[0], args, os.Environ()); err != nil { log.Fatalf("error execing init: %v", err) } }
// Run mounts the right overlay filesystems and actually runs the prepared // pod by exec()ing the stage1 init inside the pod filesystem. func Run(cfg RunConfig, dir string, dataDir string) { useOverlay, err := preparedWithOverlay(dir) if err != nil { log.FatalE("error preparing overlay", err) } privateUsers, err := preparedWithPrivateUsers(dir) if err != nil { log.FatalE("error preparing private users", err) } debug("Setting up stage1") if err := setupStage1Image(cfg, dir, useOverlay); err != nil { log.FatalE("error setting up stage1", err) } debug("Wrote filesystem to %s\n", dir) for _, app := range cfg.Apps { if err := setupAppImage(cfg, app.Name, app.Image.ID, dir, useOverlay); err != nil { log.FatalE("error setting up app image", err) } } destRootfs := common.Stage1RootfsPath(dir) if len(cfg.DNS) > 0 || len(cfg.DNSSearch) > 0 || len(cfg.DNSOpt) > 0 { addResolvConf(cfg, destRootfs) } if err := os.Setenv(common.EnvLockFd, fmt.Sprintf("%v", cfg.LockFd)); err != nil { log.FatalE("setting lock fd environment", err) } if err := os.Setenv(common.EnvSELinuxContext, fmt.Sprintf("%v", cfg.ProcessLabel)); err != nil { log.FatalE("setting SELinux context environment", err) } if err := os.Setenv(common.EnvSELinuxMountContext, fmt.Sprintf("%v", cfg.MountLabel)); err != nil { log.FatalE("setting SELinux mount context enviroment", err) } debug("Pivoting to filesystem %s", dir) if err := os.Chdir(dir); err != nil { log.FatalE("failed changing to dir", err) } ep, err := getStage1Entrypoint(dir, runEntrypoint) if err != nil { log.FatalE("error determining 'run' entrypoint", err) } args := []string{filepath.Join(destRootfs, ep)} debug("Execing %s", ep) if cfg.Debug { args = append(args, "--debug") } args = append(args, "--net="+cfg.Net.String()) if cfg.Interactive { args = append(args, "--interactive") } if len(privateUsers) > 0 { args = append(args, "--private-users="+privateUsers) } if cfg.MDSRegister { mdsToken, err := registerPod(".", cfg.UUID, cfg.Apps) if err != nil { log.FatalE("failed to register the pod", err) } args = append(args, "--mds-token="+mdsToken) } if cfg.LocalConfig != "" { args = append(args, "--local-config="+cfg.LocalConfig) } s1v, err := getStage1InterfaceVersion(dir) if err != nil { log.FatalE("error determining stage1 interface version", err) } if cfg.Hostname != "" { if interfaceVersionSupportsHostname(s1v) { args = append(args, "--hostname="+cfg.Hostname) } else { log.Printf("warning: --hostname option is not supported by stage1") } } args = append(args, cfg.UUID.String()) // make sure the lock fd stays open across exec if err := sys.CloseOnExec(cfg.LockFd, false); err != nil { log.Fatalf("error clearing FD_CLOEXEC on lock fd") } tpmEvent := fmt.Sprintf("rkt: Rootfs: %s Manifest: %s Stage1 args: %s", cfg.CommonConfig.RootHash, cfg.CommonConfig.ManifestData, strings.Join(args, " ")) // If there's no TPM available or there's a failure for some other // reason, ignore it and continue anyway. Long term we'll want policy // that enforces TPM behaviour, but we don't have any infrastructure // around that yet. _ = tpm.Extend(tpmEvent) if err := syscall.Exec(args[0], args, os.Environ()); err != nil { log.FatalE("error execing init", err) } }