Skip to content

Commit

Permalink
Merge pull request #9284 from johngmyers/remove-export-password
Browse files Browse the repository at this point in the history
Don't export basic auth credentials if basic auth is disabled
  • Loading branch information
k8s-ci-robot authored Jun 8, 2020
2 parents cd8681c + 49ea71d commit 7650a98
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/kubeconfig/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/kops:go_default_library",
"//pkg/apis/kops/util:go_default_library",
"//pkg/dns:go_default_library",
"//upup/pkg/fi:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
Expand Down
20 changes: 19 additions & 1 deletion pkg/kubeconfig/create_kubecfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/apis/kops/util"
"k8s.io/kops/pkg/dns"
"k8s.io/kops/upup/pkg/fi"
)
Expand Down Expand Up @@ -127,7 +128,24 @@ func BuildKubecfg(cluster *kops.Cluster, keyStore fi.Keystore, secretStore fi.Se

b.Server = server

if secretStore != nil {
k8sVersion, err := util.ParseKubernetesVersion(cluster.Spec.KubernetesVersion)
if err != nil || k8sVersion == nil {
klog.Warningf("unable to parse KubernetesVersion %q", cluster.Spec.KubernetesVersion)
k8sVersion, _ = util.ParseKubernetesVersion("1.0.0")
}

basicAuthEnabled := false
if !util.IsKubernetesGTE("1.18", *k8sVersion) {
if cluster.Spec.KubeAPIServer == nil || cluster.Spec.KubeAPIServer.DisableBasicAuth == nil || !*cluster.Spec.KubeAPIServer.DisableBasicAuth {
basicAuthEnabled = true
}
} else if !util.IsKubernetesGTE("1.19", *k8sVersion) {
if cluster.Spec.KubeAPIServer != nil && cluster.Spec.KubeAPIServer.DisableBasicAuth != nil && !*cluster.Spec.KubeAPIServer.DisableBasicAuth {
basicAuthEnabled = true
}
}

if basicAuthEnabled && secretStore != nil {
secret, err := secretStore.FindSecret("kube")
if err != nil {
return nil, err
Expand Down

0 comments on commit 7650a98

Please sign in to comment.