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

Added validation for --insecure-registry values #9977

Merged
merged 1 commit into from
Dec 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"os/exec"
"os/user"
"regexp"
"runtime"
"strings"

Expand Down Expand Up @@ -71,6 +72,7 @@ var (
insecureRegistry []string
apiServerNames []string
apiServerIPs []net.IP
hostRe = regexp.MustCompile(`[\w\.-]+`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still want me to add the comment?

)

func init() {
Expand Down Expand Up @@ -897,6 +899,7 @@ func validateRequestedMemorySize(req int, drvName string) {
func validateCPUCount(drvName string) {
var cpuCount int
if driver.BareMetal(drvName) {

// Uses the gopsutil cpu package to count the number of physical cpu cores
ci, err := cpu.Counts(false)
if err != nil {
Expand Down Expand Up @@ -1041,6 +1044,8 @@ func validateFlags(cmd *cobra.Command, drvName string) {
}

validateRegistryMirror()
validateInsecureRegistry()

}

// This function validates if the --registry-mirror
Expand All @@ -1060,6 +1065,34 @@ func validateRegistryMirror() {
}
}

// This function validates that the --insecure-registry follows one of the following formats:
// "<ip>:<port>" "<hostname>:<port>" "<network>/<netmask>"
func validateInsecureRegistry() {
if len(insecureRegistry) > 0 {
for _, addr := range insecureRegistry {
hostnameOrIP, port, err := net.SplitHostPort(addr)
if err != nil {
_, _, err := net.ParseCIDR(addr)
if err == nil {
continue
}
}
if port == "" {
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})
}
// checks both IPv4 and IPv6
ipAddr := net.ParseIP(hostnameOrIP)
if ipAddr != nil {
continue
}
isValidHost := hostRe.MatchString(hostnameOrIP)
if err != nil || !isValidHost {
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})
}
}
}
}

func createNode(cc config.ClusterConfig, kubeNodeName string, existing *config.ClusterConfig) (config.ClusterConfig, config.Node, error) {
// Create the initial node, which will necessarily be a control plane
if existing != nil {
Expand Down