Merge pull request #12952 from spowelljr/privOnlyWSL

Only check privileged ports for WSL
pull/12979/head
Medya Ghazizadeh 2021-11-17 16:03:52 -08:00 committed by GitHub
commit 43482ee901
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -1231,7 +1231,7 @@ func validatePorts(ports []string) error {
if p > 65535 || p < 1 {
return errors.Errorf("Sorry, one of the ports provided with --ports flag is outside range %s", ports)
}
if p < 1024 && i == 0 {
if detect.IsMicrosoftWSL() && p < 1024 && i == 0 {
return errors.Errorf("Sorry, you cannot use privileged ports on the host (below 1024) %s", ports)
}
}

View File

@ -29,6 +29,7 @@ import (
cfg "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/detect"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/proxy"
)
@ -432,10 +433,11 @@ func TestValidateRuntime(t *testing.T) {
}
func TestValidatePorts(t *testing.T) {
var tests = []struct {
type portTest struct {
ports []string
errorMsg string
}{
}
var tests = []portTest{
{
ports: []string{"test:80"},
errorMsg: "Sorry, one of the ports provided with --ports flag is not valid [test:80]",
@ -444,15 +446,17 @@ func TestValidatePorts(t *testing.T) {
ports: []string{"0:80"},
errorMsg: "Sorry, one of the ports provided with --ports flag is outside range [0:80]",
},
{
ports: []string{"80:80"},
errorMsg: "Sorry, you cannot use privileged ports on the host (below 1024) [80:80]",
},
{
ports: []string{"8080:80", "6443:443"},
errorMsg: "",
},
}
if detect.IsMicrosoftWSL() {
tests = append(tests, portTest{
ports: []string{"80:80"},
errorMsg: "Sorry, you cannot use privileged ports on the host (below 1024) [80:80]",
})
}
for _, test := range tests {
t.Run(strings.Join(test.ports, ","), func(t *testing.T) {
gotError := ""