Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minikube tunnel for Docker on Windows #9753

Merged
29 changes: 29 additions & 0 deletions pkg/drivers/kic/kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ limitations under the License.
package kic

import (
"context"
"fmt"
"net"
"os/exec"
"runtime"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -205,6 +207,33 @@ func (d *Driver) prepareSSH() error {
return errors.Wrapf(err, "apply authorized_keys file ownership, output %s", rr.Output())
}

if runtime.GOOS == "windows" {
path, _ := exec.LookPath("powershell")
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
defer cancel()

klog.Infof("ensuring only current user has permissions to key file located at : %s...", keyPath)

// Get the SID of the current user
currentUserSidCmd := exec.CommandContext(ctx, path, "-NoProfile", "-NonInteractive", "([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Value")
currentUserSidOut, currentUserSidErr := currentUserSidCmd.CombinedOutput()
if currentUserSidErr != nil {
klog.Warningf("unable to determine current user's SID. minikube tunnel may not work.")
} else {
icaclsArguments := fmt.Sprintf(`"%s" /grant:r *%s:F /inheritancelevel:r`, keyPath, strings.TrimSpace(string(currentUserSidOut)))
icaclsCmd := exec.CommandContext(ctx, path, "-NoProfile", "-NonInteractive", "icacls.exe", icaclsArguments)
icaclsCmdOut, icaclsCmdErr := icaclsCmd.CombinedOutput()

if icaclsCmdErr != nil {
return errors.Wrap(icaclsCmdErr, "unable to execute icacls to set permissions")
}

if !strings.Contains(string(icaclsCmdOut), "Successfully processed 1 files; Failed processing 0 files") {
klog.Errorf("icacls failed applying permissions - err - [%s], output - [%s]", icaclsCmdErr, strings.TrimSpace(string(icaclsCmdOut)))
}
}
}

return nil
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/minikube/tunnel/kic/ssh_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package kic
import (
"fmt"
"os/exec"
"runtime"

"github.com/phayes/freeport"
v1 "k8s.io/api/core/v1"
Expand All @@ -39,7 +40,7 @@ func createSSHConn(name, sshPort, sshKey string, svc *v1.Service) *sshConn {
sshArgs := []string{
// TODO: document the options here
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking no",
"-o", "StrictHostKeyChecking=no",
"-N",
"[email protected]",
"-p", sshPort,
Expand All @@ -66,8 +67,7 @@ func createSSHConn(name, sshPort, sshKey string, svc *v1.Service) *sshConn {
}

command := "ssh"

if askForSudo {
if askForSudo && runtime.GOOS != "windows" {
out.Step(
style.Warning,
"The service {{.service}} requires privileged ports to be exposed: {{.ports}}",
Expand All @@ -79,7 +79,6 @@ func createSSHConn(name, sshPort, sshKey string, svc *v1.Service) *sshConn {
command = "sudo"
sshArgs = append([]string{"ssh"}, sshArgs...)
}

cmd := exec.Command(command, sshArgs...)

return &sshConn{
Expand All @@ -94,7 +93,7 @@ func createSSHConnWithRandomPorts(name, sshPort, sshKey string, svc *v1.Service)
sshArgs := []string{
// TODO: document the options here
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking no",
"-o", "StrictHostKeyChecking=no",
"-N",
"[email protected]",
"-p", sshPort,
Expand Down