Skip to content

Commit

Permalink
Merge pull request #6833 from josedonizetti/kic-fix-unprivileged-port…
Browse files Browse the repository at this point in the history
…-bind

kic: fix unprivileged port bind tunnel docker for mac
  • Loading branch information
medyagh authored Feb 28, 2020
2 parents 15dfc5c + 11c0612 commit 83dd0db
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/minikube/tunnel/kic/ssh_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func createSSHConn(name, sshPort, sshKey string, svc *v1.Service) *sshConn {
"-i", sshKey,
}

askForSudo := false
var privilegedPorts []int32
for _, port := range svc.Spec.Ports {
arg := fmt.Sprintf(
"-L %d:%s:%d",
Expand All @@ -52,10 +54,27 @@ func createSSHConn(name, sshPort, sshKey string, svc *v1.Service) *sshConn {
port.Port,
)

// check if any port is privileged
if port.Port < 1024 {
privilegedPorts = append(privilegedPorts, port.Port)
askForSudo = true
}

sshArgs = append(sshArgs, arg)
}

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

if askForSudo {
// TODO: use out package
fmt.Printf("The service %s requires priviledged ports to be exposed: %v\n", svc.Name, privilegedPorts)
fmt.Printf("sudo permission will be asked for it.\n")

command = "sudo"
sshArgs = append([]string{"ssh"}, sshArgs...)
}

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

return &sshConn{
name: name,
Expand Down

0 comments on commit 83dd0db

Please sign in to comment.