From ed550a05517107b7621a8d8f9c560e08e6ca4b34 Mon Sep 17 00:00:00 2001 From: Renato Moutinho Date: Wed, 23 Aug 2023 21:43:36 -0300 Subject: [PATCH] Masking http(s)_proxy password from output. --- pkg/minikube/node/config.go | 12 ++++++++++++ pkg/minikube/node/start.go | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) mode change 100644 => 100755 pkg/minikube/node/start.go diff --git a/pkg/minikube/node/config.go b/pkg/minikube/node/config.go index f58839aa5a5c..c1635fa29e86 100644 --- a/pkg/minikube/node/config.go +++ b/pkg/minikube/node/config.go @@ -21,7 +21,9 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "strconv" + "strings" "sync" "github.com/spf13/viper" @@ -47,6 +49,16 @@ func showVersionInfo(k8sVersion string, cr cruntime.Manager) { out.Infof("opt {{.docker_option}}", out.V{"docker_option": v}) } for _, v := range config.DockerEnv { + parts := strings.Split(v, "=") + if len(parts) == 2 { + key := strings.ToUpper(parts[0]) + if key == "HTTP_PROXY" || key == "HTTPS_PROXY" { + pattern := `//(\w+):\w+@` + regexpPattern := regexp.MustCompile(pattern) + value := regexpPattern.ReplaceAllString(parts[1], "//$1:*****@") + v = key + "=" + value + } + } out.Infof("env {{.docker_env}}", out.V{"docker_env": v}) } } diff --git a/pkg/minikube/node/start.go b/pkg/minikube/node/start.go old mode 100644 new mode 100755 index fd4c00921b4e..b8be4fc9e5c2 --- a/pkg/minikube/node/start.go +++ b/pkg/minikube/node/start.go @@ -723,9 +723,15 @@ func validateNetwork(h *host.Host, r command.Runner, imageRepository string) (st out.Styled(style.Internet, "Found network options:") optSeen = true } + k = strings.ToUpper(k) // let's get the key right away to mask password from output + // If http(s)_proxy contains password, let's not splatter on the screen + if k == "HTTP_PROXY" || k == "HTTPS_PROXY" { + pattern := `//(\w+):\w+@` + regexpPattern := regexp.MustCompile(pattern) + v = regexpPattern.ReplaceAllString(v, "//$1:*****@") + } out.Infof("{{.key}}={{.value}}", out.V{"key": k, "value": v}) ipExcluded := proxy.IsIPExcluded(ip) // Skip warning if minikube ip is already in NO_PROXY - k = strings.ToUpper(k) // for http_proxy & https_proxy if (k == "HTTP_PROXY" || k == "HTTPS_PROXY") && !ipExcluded && !warnedOnce { out.WarningT("You appear to be using a proxy, but your NO_PROXY environment does not include the minikube IP ({{.ip_address}}).", out.V{"ip_address": ip}) out.Styled(style.Documentation, "Please see {{.documentation_url}} for more details", out.V{"documentation_url": "https://minikube.sigs.k8s.io/docs/handbook/vpn_and_proxy/"})