Fix empty report (#281)

* Fix empty report when active hunting

Running kube-hunter active hunting with plain report
did not show any report.
This commit changes Vulnerability.vid default value
to "None" (previously None)

Closes #280

* Improve debug and exception messages

Debugging hunters execution is hard due to lack of debug
information. No indication is made when a hunter starts.
Exceptions where printed without stack trace, which made
it difficult to follow.
This commit is contained in:
Yehuda Chikvashvili
2020-01-09 19:04:33 +02:00
committed by GitHub
parent fe3dba90d8
commit a4a8c71653
7 changed files with 11 additions and 8 deletions

View File

@@ -128,6 +128,7 @@ class EventQueue(Queue, object):
while self.running:
try:
hook = self.get()
logging.debug("Executing {} with {}".format(hook.__class__, hook.event.__dict__))
hook.execute()
except Exception as ex:
logging.debug("Exception: {} - {}".format(hook.__class__, ex))

View File

@@ -80,7 +80,7 @@ class Vulnerability(object):
})
# TODO: make vid mandatory once migration is done
def __init__(self, component, name, category=None, vid=None):
def __init__(self, component, name, category=None, vid="None"):
self.vid = vid
self.component = component
self.category = category

View File

@@ -92,7 +92,7 @@ class ApiServiceClassify(EventFilterBase):
else:
self.event = ApiServer()
except Exception as e:
logging.error("Could not access /version on API service: {}".format(e))
logging.exception("Could not access /version on API service")
def execute(self):
discovered_protocol = self.event.protocol

View File

@@ -152,7 +152,7 @@ class HostDiscovery(Discovery):
try:
ip, sn = config.cidr.split('/')
except ValueError as e:
logging.error("unable to parse cidr: {0}".format(e))
logging.exception("unable to parse cidr")
return
cloud = HostDiscoveryHelpers.get_cloud(ip)
for ip in HostDiscoveryHelpers.generate_subnet(ip, sn=sn):

View File

@@ -225,8 +225,9 @@ class AccessApiServer(Hunter):
for item in resp["items"]:
items.append(item["metadata"]["name"])
return items
logging.debug("Got HTTP {} respone: {}".format(r.status_code, r.text))
except (requests.exceptions.ConnectionError, KeyError):
pass
logging.debug("Failed retrieving items from API server at {}".format(path))
return None

View File

@@ -33,7 +33,7 @@ class HTTPDispatcher(object):
)
except requests.HTTPError as e:
# specific http exceptions
logging.error(
logging.exception(
"\nCould not dispatch report using HTTP {method} to {url}\nResponse Code: {status}".format(
status=r.status_code,
url=dispatch_url,
@@ -42,10 +42,9 @@ class HTTPDispatcher(object):
)
except Exception as e:
# default all exceptions
logging.error("\nCould not dispatch report using HTTP {method} to {url} - {error}".format(
logging.exception("\nCould not dispatch report using HTTP {method} to {url}".format(
method=dispatch_method,
url=dispatch_url,
error=e
url=dispatch_url
))
class STDOUTDispatcher(object):

View File

@@ -31,3 +31,5 @@ exclude_lines =
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
# Don't complain about log messages not being tested
logging\.