Skip to content

Commit b437fb3

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 95d4cfe commit b437fb3

File tree

8 files changed

+3
-126
lines changed

8 files changed

+3
-126
lines changed

cmd/minikube/cmd/start_flags.go

Lines changed: 2 additions & 4 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),
@@ -867,7 +866,6 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC
867866
updateStringFromFlag(cmd, &cc.KubernetesConfig.ServiceCIDR, serviceCIDR)
868867
updateBoolFromFlag(cmd, &cc.KubernetesConfig.ShouldLoadCachedImages, cacheImages)
869868
updateDurationFromFlag(cmd, &cc.CertExpiration, certExpiration)
870-
updateBoolFromFlag(cmd, &cc.Mount, createMount)
871869
updateStringFromFlag(cmd, &cc.MountString, mountString)
872870
updateStringFromFlag(cmd, &cc.Mount9PVersion, mount9PVersion)
873871
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

0 commit comments

Comments
 (0)