Skip to content

Commit c0af96c

Browse files
committed
Make "--insecure-skip-tls-verify" work on all cases
In the getting started example of AWS, the master uses an IP that is changed on stop/start. If you are playing with a cluster and stop and start the master, the IP is changed and you can't connect again, even using the "--insecure-skip-tls-verify" option. This patch fixes it and makes the option work on those cases too by making sure no CA/CAData is added when it shouldn't.
1 parent 2bb6f74 commit c0af96c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Diff for: pkg/client/unversioned/clientcmd/client_config.go

+8
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ func (config *DirectClientConfig) getCluster() clientcmdapi.Cluster {
305305
mergo.Merge(&mergedClusterInfo, configClusterInfo)
306306
}
307307
mergo.Merge(&mergedClusterInfo, config.overrides.ClusterInfo)
308+
// An override of --insecure-skip-tls-verify=true and no accompanying CA/CA data should clear already-set CA/CA data
309+
// otherwise, a kubeconfig containing a CA reference would return an error that "CA and insecure-skip-tls-verify couldn't both be set"
310+
caLen := len(config.overrides.ClusterInfo.CertificateAuthority)
311+
caDataLen := len(config.overrides.ClusterInfo.CertificateAuthorityData)
312+
if config.overrides.ClusterInfo.InsecureSkipTLSVerify && caLen == 0 && caDataLen == 0 {
313+
mergedClusterInfo.CertificateAuthority = ""
314+
mergedClusterInfo.CertificateAuthorityData = nil
315+
}
308316

309317
return mergedClusterInfo
310318
}

Diff for: pkg/client/unversioned/clientcmd/client_config_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,31 @@ func createValidTestConfig() *clientcmdapi.Config {
6565
return config
6666
}
6767

68+
func createCAValidTestConfig() *clientcmdapi.Config {
69+
70+
config := createValidTestConfig()
71+
config.Clusters["clean"].CertificateAuthorityData = []byte{0, 0}
72+
return config
73+
}
74+
75+
func TestInsecureOverridesCA(t *testing.T) {
76+
config := createCAValidTestConfig()
77+
clientBuilder := NewNonInteractiveClientConfig(*config, "clean", &ConfigOverrides{
78+
ClusterInfo: clientcmdapi.Cluster{
79+
InsecureSkipTLSVerify: true,
80+
},
81+
})
82+
83+
actualCfg, err := clientBuilder.ClientConfig()
84+
if err != nil {
85+
t.Errorf("Unexpected error: %v", err)
86+
}
87+
88+
matchBoolArg(true, actualCfg.Insecure, t)
89+
matchStringArg("", actualCfg.TLSClientConfig.CAFile, t)
90+
matchByteArg(nil, actualCfg.TLSClientConfig.CAData, t)
91+
}
92+
6893
func TestMergeContext(t *testing.T) {
6994
const namespace = "overriden-namespace"
7095

0 commit comments

Comments
 (0)