From a746bd0eb154e1f57c8ed013395f114c43efb435 Mon Sep 17 00:00:00 2001 From: danielsagi Date: Sat, 22 Jan 2022 15:56:04 +0200 Subject: [PATCH] Added correct exception handling for discovery of Metadata apis (#488) * Added correct exception handling for discovery of Metadata apis * fixed linting issues --- kube_hunter/modules/discovery/hosts.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kube_hunter/modules/discovery/hosts.py b/kube_hunter/modules/discovery/hosts.py index 76d0b40..760211e 100644 --- a/kube_hunter/modules/discovery/hosts.py +++ b/kube_hunter/modules/discovery/hosts.py @@ -166,7 +166,9 @@ class FromPodHostDiscovery(Discovery): return True except requests.exceptions.ConnectionError: logger.debug("Failed to connect AWS metadata server v1") - return False + except Exception: + logger.debug("Unknown error when trying to connect to AWS metadata v1 API") + return False def is_aws_pod_v2(self): config = get_config() @@ -189,7 +191,9 @@ class FromPodHostDiscovery(Discovery): return True except requests.exceptions.ConnectionError: logger.debug("Failed to connect AWS metadata server v2") - return False + except Exception: + logger.debug("Unknown error when trying to connect to AWS metadata v2 API") + return False def is_azure_pod(self): config = get_config() @@ -206,7 +210,9 @@ class FromPodHostDiscovery(Discovery): return True except requests.exceptions.ConnectionError: logger.debug("Failed to connect Azure metadata server") - return False + except Exception: + logger.debug("Unknown error when trying to connect to Azure metadata server") + return False # for pod scanning def gateway_discovery(self):