diff --git a/pkg/minikube/node/config.go b/pkg/minikube/node/config.go index c1635fa29e86..829e8d4bec9a 100644 --- a/pkg/minikube/node/config.go +++ b/pkg/minikube/node/config.go @@ -41,24 +41,29 @@ import ( "k8s.io/minikube/pkg/util/lock" ) +func maskProxyPassword(v string) string { + parts := strings.Split(v, "=") + if len(parts) == 2 { + key := strings.ToUpper(parts[0]) + if key == "HTTP_PROXY" || key == "HTTPS_PROXY" { + pattern := `//([^:]+):[^\@]+@` + regexpPattern := regexp.MustCompile(pattern) + value := regexpPattern.ReplaceAllString(parts[1], "//$1:*****@") + v = key + "=" + value + } + } + return v +} + func showVersionInfo(k8sVersion string, cr cruntime.Manager) { version, _ := cr.Version() register.Reg.SetStep(register.PreparingKubernetes) out.Step(cr.Style(), "Preparing Kubernetes {{.k8sVersion}} on {{.runtime}} {{.runtimeVersion}} ...", out.V{"k8sVersion": k8sVersion, "runtime": cr.Name(), "runtimeVersion": version}) for _, v := range config.DockerOpt { + v = maskProxyPassword(v) 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/config_test.go b/pkg/minikube/node/config_test.go new file mode 100644 index 000000000000..7bd094f6aff1 --- /dev/null +++ b/pkg/minikube/node/config_test.go @@ -0,0 +1,60 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package node + +import ( + "testing" +) + +func Test_maskProxyPassword(t *testing.T) { + type dockerOptTest struct { + input string + output string + } + var tests = []dockerOptTest{ + { + input: "cats", + output: "cats", + }, + { + input: "myDockerOption=value", + output: "myDockerOption=value", + }, + { + input: "http_proxy=http://myproxy.company.com", + output: "HTTP_PROXY=http://myproxy.company.com", + }, + { + input: "https_proxy=http://jdoe@myproxy.company.com:8080", + output: "HTTPS_PROXY=http://jdoe@myproxy.company.com:8080", + }, + { + input: "https_proxy=https://mary:am$uT8zB(rP@myproxy.company.com:8080", + output: "HTTPS_PROXY=https://mary:*****@myproxy.company.com:8080", + }, + { + input: "http_proxy=http://jdoe:mPu3z9uT#!@myproxy.company.com:8080", + output: "HTTP_PROXY=http://jdoe:*****@myproxy.company.com:8080", + }, + } + for _, test := range tests { + got := maskProxyPassword(test.input) + if got != test.output { + t.Errorf("maskProxyPassword(\"%v\"): got %v, expected %v", test.input, got, test.output) + } + } +}