Skip to content

Commit ed550a0

Browse files
rmsilva1973Renato Moutinho Silva
authored andcommitted
Masking http(s)_proxy password from output.
1 parent dfb81dd commit ed550a0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pkg/minikube/node/config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121
"os"
2222
"os/exec"
2323
"path/filepath"
24+
"regexp"
2425
"strconv"
26+
"strings"
2527
"sync"
2628

2729
"github.com/spf13/viper"
@@ -47,6 +49,16 @@ func showVersionInfo(k8sVersion string, cr cruntime.Manager) {
4749
out.Infof("opt {{.docker_option}}", out.V{"docker_option": v})
4850
}
4951
for _, v := range config.DockerEnv {
52+
parts := strings.Split(v, "=")
53+
if len(parts) == 2 {
54+
key := strings.ToUpper(parts[0])
55+
if key == "HTTP_PROXY" || key == "HTTPS_PROXY" {
56+
pattern := `//(\w+):\w+@`
57+
regexpPattern := regexp.MustCompile(pattern)
58+
value := regexpPattern.ReplaceAllString(parts[1], "//$1:*****@")
59+
v = key + "=" + value
60+
}
61+
}
5062
out.Infof("env {{.docker_env}}", out.V{"docker_env": v})
5163
}
5264
}

pkg/minikube/node/start.go

100644100755
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,15 @@ func validateNetwork(h *host.Host, r command.Runner, imageRepository string) (st
723723
out.Styled(style.Internet, "Found network options:")
724724
optSeen = true
725725
}
726+
k = strings.ToUpper(k) // let's get the key right away to mask password from output
727+
// If http(s)_proxy contains password, let's not splatter on the screen
728+
if k == "HTTP_PROXY" || k == "HTTPS_PROXY" {
729+
pattern := `//(\w+):\w+@`
730+
regexpPattern := regexp.MustCompile(pattern)
731+
v = regexpPattern.ReplaceAllString(v, "//$1:*****@")
732+
}
726733
out.Infof("{{.key}}={{.value}}", out.V{"key": k, "value": v})
727734
ipExcluded := proxy.IsIPExcluded(ip) // Skip warning if minikube ip is already in NO_PROXY
728-
k = strings.ToUpper(k) // for http_proxy & https_proxy
729735
if (k == "HTTP_PROXY" || k == "HTTPS_PROXY") && !ipExcluded && !warnedOnce {
730736
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})
731737
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/"})

0 commit comments

Comments
 (0)