From c5becb36073b1d982fce832147af737ae5184b22 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Fri, 9 Jun 2017 17:34:39 -0700 Subject: [PATCH] Allow control of user and group ids for mount --- cmd/minikube/cmd/mount.go | 8 ++++++-- pkg/minikube/cluster/cluster.go | 4 ++-- pkg/minikube/cluster/commands.go | 8 ++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/minikube/cmd/mount.go b/cmd/minikube/cmd/mount.go index b66bdfe1bdd9..3054023b8e3b 100644 --- a/cmd/minikube/cmd/mount.go +++ b/cmd/minikube/cmd/mount.go @@ -35,6 +35,8 @@ import ( var mountIP string var isKill bool +var uid int +var gid int // mountCmd represents the mount command var mountCmd = &cobra.Command{ @@ -52,7 +54,7 @@ var mountCmd = &cobra.Command{ if len(args) != 1 { errText := `Please specify the directory to be mounted: -\tminikube mount HOST_MOUNT_DIRECTORY:VM_MOUNT_DIRECTORY(ex:"/host-home:/vm-home") + minikube mount HOST_MOUNT_DIRECTORY:VM_MOUNT_DIRECTORY(ex:"/host-home:/vm-home") ` fmt.Fprintln(os.Stderr, errText) os.Exit(1) @@ -128,7 +130,7 @@ var mountCmd = &cobra.Command{ ufs.StartServer(net.JoinHostPort(ip.String(), port), debugVal, hostPath) wg.Done() }() - err = cluster.MountHost(api, vmPath, ip, port) + err = cluster.MountHost(api, vmPath, ip, port, uid, gid) if err != nil { fmt.Println(err.Error()) os.Exit(1) @@ -140,5 +142,7 @@ var mountCmd = &cobra.Command{ func init() { mountCmd.Flags().StringVar(&mountIP, "ip", "", "Specify the ip that the mount should be setup on") mountCmd.Flags().BoolVar(&isKill, "kill", false, "Kill the mount process spawned by minikube start") + mountCmd.Flags().IntVar(&uid, "uid", 1001, "Default user id used for the mount") + mountCmd.Flags().IntVar(&gid, "gid", 1001, "Default group id used for the mount") RootCmd.AddCommand(mountCmd) } diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index 884f0253476f..b438cc16ee32 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -449,7 +449,7 @@ func GetHostLogs(api libmachine.API, follow bool) (string, error) { } // MountHost runs the mount command from the 9p client on the VM to the 9p server on the host -func MountHost(api libmachine.API, path string, ip net.IP, port string) error { +func MountHost(api libmachine.API, path string, ip net.IP, port string, uid, gid int) error { host, err := CheckIfApiExistsAndLoad(api) if err != nil { return errors.Wrap(err, "Error checking that api exists and loading it") @@ -461,7 +461,7 @@ func MountHost(api libmachine.API, path string, ip net.IP, port string) error { } } host.RunSSHCommand(GetMountCleanupCommand(path)) - mountCmd, err := GetMountCommand(ip, path, port) + mountCmd, err := GetMountCommand(ip, path, port, uid, gid) if err != nil { return errors.Wrap(err, "Error getting mount command") } diff --git a/pkg/minikube/cluster/commands.go b/pkg/minikube/cluster/commands.go index b19f18191731..ad4fcfb4c578 100644 --- a/pkg/minikube/cluster/commands.go +++ b/pkg/minikube/cluster/commands.go @@ -233,20 +233,24 @@ func GetMountCleanupCommand(path string) string { var mountTemplate = ` sudo mkdir -p {{.Path}} || true; -sudo mount -t 9p -o trans=tcp -o port={{.Port}} -o uid=1001 -o gid=1001 {{.IP}} {{.Path}}; +sudo mount -t 9p -o trans=tcp -o port={{.Port}} -o uid={{.UID}} -o gid={{.GID}} {{.IP}} {{.Path}}; sudo chmod 775 {{.Path}};` -func GetMountCommand(ip net.IP, path string, port string) (string, error) { +func GetMountCommand(ip net.IP, path, port string, uid, gid int) (string, error) { t := template.Must(template.New("mountCommand").Parse(mountTemplate)) buf := bytes.Buffer{} data := struct { IP string Path string Port string + UID int + GID int }{ IP: ip.String(), Path: path, Port: port, + UID: uid, + GID: gid, } if err := t.Execute(&buf, data); err != nil { return "", err