Skip to content

Commit c300a05

Browse files
authored
Merge pull request #9977 from kadern0/issue-8790
Added validation for --insecure-registry values
2 parents 9d5faff + dbbe066 commit c300a05

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

cmd/minikube/cmd/start.go

+33
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"os"
2626
"os/exec"
2727
"os/user"
28+
"regexp"
2829
"runtime"
2930
"strings"
3031

@@ -73,6 +74,7 @@ var (
7374
insecureRegistry []string
7475
apiServerNames []string
7576
apiServerIPs []net.IP
77+
hostRe = regexp.MustCompile(`[\w\.-]+`)
7678
)
7779

7880
func init() {
@@ -948,6 +950,7 @@ func validateRequestedMemorySize(req int, drvName string) {
948950
func validateCPUCount(drvName string) {
949951
var cpuCount int
950952
if driver.BareMetal(drvName) {
953+
951954
// Uses the gopsutil cpu package to count the number of physical cpu cores
952955
ci, err := cpu.Counts(false)
953956
if err != nil {
@@ -1092,6 +1095,8 @@ func validateFlags(cmd *cobra.Command, drvName string) {
10921095
}
10931096

10941097
validateRegistryMirror()
1098+
validateInsecureRegistry()
1099+
10951100
}
10961101

10971102
// This function validates if the --registry-mirror
@@ -1111,6 +1116,34 @@ func validateRegistryMirror() {
11111116
}
11121117
}
11131118

1119+
// This function validates that the --insecure-registry follows one of the following formats:
1120+
// "<ip>:<port>" "<hostname>:<port>" "<network>/<netmask>"
1121+
func validateInsecureRegistry() {
1122+
if len(insecureRegistry) > 0 {
1123+
for _, addr := range insecureRegistry {
1124+
hostnameOrIP, port, err := net.SplitHostPort(addr)
1125+
if err != nil {
1126+
_, _, err := net.ParseCIDR(addr)
1127+
if err == nil {
1128+
continue
1129+
}
1130+
}
1131+
if port == "" {
1132+
exit.Message(reason.Usage, "Sorry, the address provided with the --insecure-registry flag is invalid: {{.addr}}. Expected formtas are: <ip>:<port>, <hostname>:<port> or <network>/<netmask>", out.V{"addr": addr})
1133+
}
1134+
// checks both IPv4 and IPv6
1135+
ipAddr := net.ParseIP(hostnameOrIP)
1136+
if ipAddr != nil {
1137+
continue
1138+
}
1139+
isValidHost := hostRe.MatchString(hostnameOrIP)
1140+
if err != nil || !isValidHost {
1141+
exit.Message(reason.Usage, "Sorry, the address provided with the --insecure-registry flag is invalid: {{.addr}}. Expected formtas are: <ip>:<port>, <hostname>:<port> or <network>/<netmask>", out.V{"addr": addr})
1142+
}
1143+
}
1144+
}
1145+
}
1146+
11141147
func createNode(cc config.ClusterConfig, kubeNodeName string, existing *config.ClusterConfig) (config.ClusterConfig, config.Node, error) {
11151148
// Create the initial node, which will necessarily be a control plane
11161149
if existing != nil {

0 commit comments

Comments
 (0)