Masking http(s)_proxy password from output.

pull/17116/head
Renato Moutinho 2023-08-23 21:43:36 -03:00 committed by Renato Moutinho Silva
parent dfb81ddb32
commit ed550a0551
2 changed files with 19 additions and 1 deletions

View File

@ -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})
}
}

8
pkg/minikube/node/start.go Normal file → Executable file
View File

@ -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/"})