Skip to content

Commit

Permalink
Added port validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kadern0 committed Aug 11, 2021
1 parent 8173cab commit 0777f14
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,10 @@ func validateFlags(cmd *cobra.Command, drvName string) {
viper.Set(imageRepository, validateImageRepository(viper.GetString(imageRepository)))
}

if cmd.Flags().Changed(ports) {
validatePorts(viper.GetStringSlice(ports))
}

if cmd.Flags().Changed(containerRuntime) {
runtime := strings.ToLower(viper.GetString(containerRuntime))

Expand Down Expand Up @@ -1314,6 +1318,24 @@ func validateListenAddress(listenAddr string) {
}
}

// This function validates that the --ports are not below 1024 for the host and not outside range
func validatePorts(ports []string) {
for _, portDuplet := range ports {
for i, port := range strings.Split(portDuplet, ":") {
p, err := strconv.Atoi(port)
if err != nil {
exit.Message(reason.Usage, "Sorry, one of the ports provided with --ports flag is not valid {{.ports}}", out.V{"ports": ports})
}
if p > 65535 {
exit.Message(reason.Usage, "Sorry, one of the ports provided with --ports flag is outside range {{.ports}}", out.V{"ports": ports})
}
if p < 1024 && i == 0 {
exit.Message(reason.Usage, "Sorry, you cannot use privileged ports on the host (below 1024) {{.ports}}", out.V{"ports": ports})
}
}
}
}

// This function validates that the --insecure-registry follows one of the following formats:
// "<ip>[:<port>]" "<hostname>[:<port>]" "<network>/<netmask>"
func validateInsecureRegistry() {
Expand Down

0 comments on commit 0777f14

Please sign in to comment.