From ebb0e28cb4fba8997d3706e152b05e02ac894ed8 Mon Sep 17 00:00:00 2001 From: Guillaume Rose Date: Thu, 20 May 2021 15:41:48 +0200 Subject: [PATCH] Change `crc podman-env` to use the root Podman socket Add a flag to choose rootless Podman. --- cmd/crc/cmd/podman_env.go | 16 +++++++++++++--- pkg/crc/machine/start.go | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cmd/crc/cmd/podman_env.go b/cmd/crc/cmd/podman_env.go index bb7d3ebdd8..dbda33da86 100644 --- a/cmd/crc/cmd/podman_env.go +++ b/cmd/crc/cmd/podman_env.go @@ -8,6 +8,10 @@ import ( "github.com/spf13/cobra" ) +var ( + rootless bool +) + var podmanEnvCmd = &cobra.Command{ Use: "podman-env", Short: "Setup podman environment", @@ -33,18 +37,24 @@ func runPodmanEnv() error { return err } + socket := "/run/podman/podman.sock" + if rootless { + socket = "/run/user/1000/podman/podman.sock" + } fmt.Println(shell.GetPathEnvString(userShell, constants.CrcOcBinDir)) fmt.Println(shell.GetEnvString(userShell, "CONTAINER_SSHKEY", connectionDetails.SSHKeys[0])) fmt.Println(shell.GetEnvString(userShell, "CONTAINER_HOST", - fmt.Sprintf("ssh://%s@%s:%d/run/user/1000/podman/podman.sock", + fmt.Sprintf("ssh://%s@%s:%d%s", connectionDetails.SSHUsername, connectionDetails.IP, - connectionDetails.SSHPort))) + connectionDetails.SSHPort, + socket))) fmt.Println(shell.GenerateUsageHintWithComment(userShell, "crc podman-env")) return nil } func init() { - rootCmd.AddCommand(podmanEnvCmd) + podmanEnvCmd.Flags().BoolVar(&rootless, "rootless", false, "Use rootless podman in the virtual machine") podmanEnvCmd.Flags().StringVar(&forceShell, "shell", "", "Set the environment for the specified shell: [fish, cmd, powershell, tcsh, bash, zsh]. Default is auto-detect.") + rootCmd.AddCommand(podmanEnvCmd) } diff --git a/pkg/crc/machine/start.go b/pkg/crc/machine/start.go index 8c9c331778..eedf5b9bcb 100644 --- a/pkg/crc/machine/start.go +++ b/pkg/crc/machine/start.go @@ -302,6 +302,10 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig) } } + if _, _, err := sshRunner.RunPrivileged("make root Podman socket accessible", "chmod 777 /run/podman/ /run/podman/podman.sock"); err != nil { + return nil, errors.Wrap(err, "Failed to change permissions to root podman socket") + } + proxyConfig, err := getProxyConfig(crcBundleMetadata.ClusterInfo.BaseDomain) if err != nil { return nil, errors.Wrap(err, "Error getting proxy configuration")