Skip to content

Commit 637b1d8

Browse files
committed
start: Simpler and safer mount on start
The --mount-string argument defaults to `/Users` on darwin, and homedir.Homedir() on other platforms (e.g. $HOME on unix). This is wrong in many ways: - `/Users` is not HOME on darwin (the right path is `/Users/$USER`). Using the default mount we cannot access anything inside the guest in the user home directory. We can access the special `/Users/Shared` directory, but this should not be a default mount. - Mounting the user home directory inside the guest in read-write mode is a horrible default. This exposes the users private keys in .ssh/ to the guest, any sensitive files in the user home directory, and allows the guest to change any file on the host. - Using the `--mount` option mount the default mount directory silently. This is unexpected, surprising, and not documented in the minikube handbook[1]. Example access to user private key from the guest with the default mount: $ minikube start --mount $ minikube ssh cat /minikube-host/.ssh/id_ed25519 -----BEGIN OPENSSH PRIVATE KEY----- ... -----END OPENSSH PRIVATE KEY----- Fixed by removing the default mount directory and changing mount logic to check for non-empty mount-string instead of the mount flag. The mount flag is kept for backward compatibility, but its value is ignored. In the next release we want to use this flag for supporting multiple mounts. Example usage before: minikube start --mount --mount-string ~/models:/mnt/models Example usage after: minikube start --mount-string ~/models:/mnt/models Breaking changes: User depending the default mount will have to replace the command: minikube start --mount With: minikube start --mount-string $HOME:/minikube-host [1] https://minikube.sigs.k8s.io/docs/handbook/mount/
1 parent c432003 commit 637b1d8

File tree

10 files changed

+27
-133
lines changed

10 files changed

+27
-133
lines changed

cmd/minikube/cmd/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func runStart(cmd *cobra.Command, _ []string) {
268268

269269
validateBuiltImageVersion(starter.Runner, ds.Name)
270270

271-
if existing != nil && driver.IsKIC(existing.Driver) && viper.GetBool(createMount) {
271+
if existing != nil && driver.IsKIC(existing.Driver) && viper.GetString(mountString) != "" {
272272
old := ""
273273
if len(existing.ContainerVolumeMounts) > 0 {
274274
old = existing.ContainerVolumeMounts[0]

cmd/minikube/cmd/start_flags.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ func initMinikubeFlags() {
173173
startCmd.Flags().Bool(keepContext, false, "This will keep the existing kubectl context and will create a minikube context.")
174174
startCmd.Flags().Bool(embedCerts, false, "if true, will embed the certs in kubeconfig.")
175175
startCmd.Flags().StringP(containerRuntime, "c", constants.DefaultContainerRuntime, fmt.Sprintf("The container runtime to be used. Valid options: %s (default: auto)", strings.Join(cruntime.ValidRuntimes(), ", ")))
176-
startCmd.Flags().Bool(createMount, false, "This will start the mount daemon and automatically mount files into minikube.")
177-
startCmd.Flags().String(mountString, constants.DefaultMountDir+":/minikube-host", "The argument to pass the minikube mount command on start.")
176+
startCmd.Flags().Bool(createMount, false, "Kept for backward compatibility, value is ignored.")
177+
startCmd.Flags().String(mountString, "", "Directory to mount in the guest using format '/host-path:/guest-path'.")
178178
startCmd.Flags().String(mount9PVersion, defaultMount9PVersion, mount9PVersionDescription)
179179
startCmd.Flags().String(mountGID, defaultMountGID, mountGIDDescription)
180180
startCmd.Flags().String(mountIPFlag, defaultMountIP, mountIPDescription)
@@ -614,7 +614,6 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
614614
SSHPort: viper.GetInt(sshSSHPort),
615615
ExtraDisks: viper.GetInt(extraDisks),
616616
CertExpiration: viper.GetDuration(certExpiration),
617-
Mount: viper.GetBool(createMount),
618617
MountString: viper.GetString(mountString),
619618
Mount9PVersion: viper.GetString(mount9PVersion),
620619
MountGID: viper.GetString(mountGID),
@@ -655,7 +654,8 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
655654
AutoPauseInterval: viper.GetDuration(autoPauseInterval),
656655
}
657656
cc.VerifyComponents = interpretWaitFlag(*cmd)
658-
if viper.GetBool(createMount) && driver.IsKIC(drvName) {
657+
658+
if viper.GetString(mountString) != "" && driver.IsKIC(drvName) {
659659
cc.ContainerVolumeMounts = []string{viper.GetString(mountString)}
660660
}
661661

@@ -867,7 +867,6 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC
867867
updateStringFromFlag(cmd, &cc.KubernetesConfig.ServiceCIDR, serviceCIDR)
868868
updateBoolFromFlag(cmd, &cc.KubernetesConfig.ShouldLoadCachedImages, cacheImages)
869869
updateDurationFromFlag(cmd, &cc.CertExpiration, certExpiration)
870-
updateBoolFromFlag(cmd, &cc.Mount, createMount)
871870
updateStringFromFlag(cmd, &cc.MountString, mountString)
872871
updateStringFromFlag(cmd, &cc.Mount9PVersion, mount9PVersion)
873872
updateStringFromFlag(cmd, &cc.MountGID, mountGID)

pkg/minikube/config/types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ type ClusterConfig struct {
8888
MultiNodeRequested bool
8989
ExtraDisks int // currently only implemented for hyperkit and kvm2
9090
CertExpiration time.Duration
91-
Mount bool
9291
MountString string
9392
Mount9PVersion string
9493
MountGID string

pkg/minikube/constants/constants_darwin.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

pkg/minikube/constants/constants_freebsd.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

pkg/minikube/constants/constants_gendocs.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

pkg/minikube/constants/constants_linux.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

pkg/minikube/constants/constants_windows.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

pkg/minikube/node/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func configureMounts(wg *sync.WaitGroup, cc config.ClusterConfig) {
7373
wg.Add(1)
7474
defer wg.Done()
7575

76-
if !cc.Mount || driver.IsKIC(cc.Driver) {
76+
if cc.MountString == "" || driver.IsKIC(cc.Driver) {
7777
return
7878
}
7979

test/integration/mount_start_test.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const (
3232
mountGID = "0"
3333
mountMSize = "6543"
3434
mountUID = "0"
35+
guestPath = "/minikube-host"
3536
)
3637

3738
var mountStartPort = 46463
@@ -55,14 +56,19 @@ func TestMountStart(t *testing.T) {
5556

5657
// Serial tests
5758
t.Run("serial", func(t *testing.T) {
59+
hostPath := t.TempDir()
60+
startProfileWithMount := func(ctx context.Context, t *testing.T, profile string) {
61+
validateStartWithMount(ctx, t, profile, hostPath)
62+
}
63+
5864
tests := []struct {
5965
name string
6066
validator validateFunc
6167
profile string
6268
}{
63-
{"StartWithMountFirst", validateStartWithMount, profile1},
69+
{"StartWithMountFirst", startProfileWithMount, profile1},
6470
{"VerifyMountFirst", validateMount, profile1},
65-
{"StartWithMountSecond", validateStartWithMount, profile2},
71+
{"StartWithMountSecond", startProfileWithMount, profile2},
6672
{"VerifyMountSecond", validateMount, profile2},
6773
{"DeleteFirst", validateDelete, profile1},
6874
{"VerifyMountPostDelete", validateMount, profile2},
@@ -87,13 +93,23 @@ func TestMountStart(t *testing.T) {
8793
}
8894

8995
// validateStartWithMount starts a cluster with mount enabled
90-
func validateStartWithMount(ctx context.Context, t *testing.T, profile string) {
96+
func validateStartWithMount(ctx context.Context, t *testing.T, profile string, hostPath string) {
9197
defer PostMortemLogs(t, profile)
9298

9399
// We have to increment this because if you have two mounts with the same port, when you kill one cluster the mount will break for the other
94100
mountStartPort++
95101

96-
args := []string{"start", "-p", profile, "--memory=3072", "--mount", "--mount-gid", mountGID, "--mount-msize", mountMSize, "--mount-port", mountPort(), "--mount-uid", mountUID, "--no-kubernetes"}
102+
args := []string{
103+
"start",
104+
"-p", profile,
105+
"--memory=3072",
106+
"--mount-string", fmt.Sprintf("%s:%s", hostPath, guestPath),
107+
"--mount-gid", mountGID,
108+
"--mount-msize", mountMSize,
109+
"--mount-port", mountPort(),
110+
"--mount-uid", mountUID,
111+
"--no-kubernetes",
112+
}
97113
args = append(args, StartArgs()...)
98114
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
99115
if err != nil {
@@ -110,7 +126,7 @@ func validateMount(ctx context.Context, t *testing.T, profile string) {
110126
sshArgs := []string{"-p", profile, "ssh", "--"}
111127

112128
args := sshArgs
113-
args = append(args, "ls", "/minikube-host")
129+
args = append(args, "ls", guestPath)
114130
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
115131
if err != nil {
116132
t.Fatalf("mount failed: %q : %v", rr.Command(), err)

0 commit comments

Comments
 (0)