Skip to content

Commit d40ed5a

Browse files
authored
Update kube_config.py
This issue occurs because parse_rfc3339 in the Kubernetes Python client does not guard against re.search() returning None. When the input string is not a valid RFC3339 timestamp, calling .groups() on None raises an AttributeError, which in kube_config.py is logged only as 'NoneType' object has no attribute 'groups' without showing the problematic string. This makes debugging difficult and allows execution to continue with an invalid expiry value. The fix is to update parse_rfc3339 to raise a clear ValueError when parsing fails and to improve logging in kube_config.py so the invalid string is included in the error message. This will provide clearer errors, prevent silent misconfigurations, and make the client more robust.
1 parent bbc5253 commit d40ed5a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

kubernetes/base/config/kube_config.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,14 +510,19 @@ def _load_from_exec_plugin(self):
510510
base64_file_content=False,
511511
temp_file_path=self._temp_file_path).as_file()
512512
else:
513-
logging.error('exec: missing token or clientCertificateData '
514-
'field in plugin output')
515-
return None
513+
logging.error("exec: missing token or clientCertificateData "
514+
" field in plugin output")
515+
return None
516+
516517
if 'expirationTimestamp' in status:
517-
self.expiry = parse_rfc3339(status['expirationTimestamp'])
518+
try:
519+
self.expiry = parse_rfc3339(status['expirationTimestamp'])
520+
except Exception as e:
521+
logging.error("Failed to parse expirationTimestamp '%s': %s",
522+
status['expirationTimestamp'], str(e) )
523+
raise
518524
return True
519-
except Exception as e:
520-
logging.error(str(e))
525+
521526

522527
def _load_user_token(self):
523528
base_path = self._get_base_path(self._user.path)

0 commit comments

Comments
 (0)