Skip to content

Commit 6593d3a

Browse files
authored
Merge pull request #107 from mbohlool/master
Support insecure-skip-tls-verify config flag
2 parents f10f4f3 + 8fc978e commit 6593d3a

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

kubernetes/config/kube_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,14 @@ def _load_cluster_info(self):
189189
self.key_file = FileOrData(
190190
self._user, 'client-key',
191191
file_base_path=self._config_base_path).as_file()
192+
if 'insecure-skip-tls-verify' in self._cluster:
193+
self.verify_ssl = not self._cluster['insecure-skip-tls-verify']
192194

193195
def _set_config(self):
194196
if 'token' in self.__dict__:
195197
self._client_configuration.api_key['authorization'] = self.token
196198
# copy these keys directly from self to configuration object
197-
keys = ['host', 'ssl_ca_cert', 'cert_file', 'key_file']
199+
keys = ['host', 'ssl_ca_cert', 'cert_file', 'key_file', 'verify_ssl']
198200
for key in keys:
199201
if key in self.__dict__:
200202
setattr(self._client_configuration, key, getattr(self, key))

kubernetes/config/kube_config_test.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,17 @@ def __eq__(self, other):
235235
if k not in other.__dict__:
236236
return
237237
if k in self.FILE_KEYS:
238-
try:
239-
with open(v) as f1, open(other.__dict__[k]) as f2:
240-
if f1.read() != f2.read():
238+
if v and other.__dict__[k]:
239+
try:
240+
with open(v) as f1, open(other.__dict__[k]) as f2:
241+
if f1.read() != f2.read():
242+
return
243+
except IOError:
244+
# fall back to only compare filenames in case we are
245+
# testing the passing of filenames to the config
246+
if other.__dict__[k] != v:
241247
return
242-
except IOError:
243-
# fall back to only compare filenames in case we are
244-
# testing the passing of filenames to the config
248+
else:
245249
if other.__dict__[k] != v:
246250
return
247251
else:
@@ -301,6 +305,13 @@ class TestKubeConfigLoader(BaseTestCase):
301305
"user": "ssl"
302306
}
303307
},
308+
{
309+
"name": "no_ssl_verification",
310+
"context": {
311+
"cluster": "no_ssl_verification",
312+
"user": "ssl"
313+
}
314+
},
304315
{
305316
"name": "ssl-no_file",
306317
"context": {
@@ -344,6 +355,13 @@ class TestKubeConfigLoader(BaseTestCase):
344355
"certificate-authority-data": TEST_CERTIFICATE_AUTH_BASE64,
345356
}
346357
},
358+
{
359+
"name": "no_ssl_verification",
360+
"cluster": {
361+
"server": TEST_SSL_HOST,
362+
"insecure-skip-tls-verify": "true",
363+
}
364+
},
347365
],
348366
"users": [
349367
{
@@ -487,6 +505,22 @@ def test_ssl(self):
487505
client_configuration=actual).load_and_set()
488506
self.assertEqual(expected, actual)
489507

508+
def test_ssl_no_verification(self):
509+
expected = FakeConfig(
510+
host=TEST_SSL_HOST,
511+
token=BEARER_TOKEN_FORMAT % TEST_DATA_BASE64,
512+
cert_file=self._create_temp_file(TEST_CLIENT_CERT),
513+
key_file=self._create_temp_file(TEST_CLIENT_KEY),
514+
verify_ssl=False,
515+
ssl_ca_cert=None,
516+
)
517+
actual = FakeConfig()
518+
KubeConfigLoader(
519+
config_dict=self.TEST_KUBE_CONFIG,
520+
active_context="no_ssl_verification",
521+
client_configuration=actual).load_and_set()
522+
self.assertEqual(expected, actual)
523+
490524
def test_list_contexts(self):
491525
loader = KubeConfigLoader(
492526
config_dict=self.TEST_KUBE_CONFIG,

0 commit comments

Comments
 (0)