aquasecurity / kube-hunter

Hunt for security weaknesses in Kubernetes clusters
Apache License 2.0
4.65k stars 578 forks source link

Fix: Removed automatic import of handler object #506

Closed danielsagi closed 2 years ago

danielsagi commented 2 years ago

Description

fixes #505 . fixed #502

Thanks for everyone for commenting about this critical one! Right after the Arp and Dns spoofing hunters were moved to run as plugins #500 . A new feature for specifying thread count was merged #433 . While both of those changes worked fine by themselves, together they introduced a new problem. In order to control the thread count, a get_config had to be called in the handler.py module, right before instantiation. Now, when initializing the plugins, an import from the package kube_hunter.core.events.types had to be called.

The problem arose when the package ..events did an import by itself from the handler.py module, thus initializing the handler before config was set.

After taking a deep look into this, I realised we don't need this automatic import, and were better off importing this manually by adding the .handler explicitly to each import.

Another issue arose after that, which I'm sure I don't need to explain to those who are familiar with python, it's a bad habit to call an imported object with the same name as it's father module.

Solution

  1. handler.py was renamed to event_handler.py
  2. removed automatic import of handler object from the events package
  3. All related imports was changed to match new module name

This should fix everything. and the upstream version would follow as 0.6.8

Contribution checklist

CLAassistant commented 2 years ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

codecov[bot] commented 2 years ago

Codecov Report

Merging #506 (e6d1bb3) into main (9ce385a) will decrease coverage by 0.05%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #506      +/-   ##
==========================================
- Coverage   65.32%   65.26%   -0.06%     
==========================================
  Files          44       44              
  Lines        2457     2456       -1     
==========================================
- Hits         1605     1603       -2     
- Misses        852      853       +1     
Impacted Files Coverage Δ
kube_hunter/core/events/__init__.py 100.00% <ø> (ø)
kube_hunter/core/events/event_handler.py 86.66% <ø> (ø)
kube_hunter/core/types/hunters.py 65.21% <100.00%> (ø)
kube_hunter/modules/discovery/apiserver.py 89.39% <100.00%> (ø)
kube_hunter/modules/discovery/dashboard.py 55.55% <100.00%> (ø)
kube_hunter/modules/discovery/etcd.py 75.00% <100.00%> (ø)
kube_hunter/modules/discovery/hosts.py 54.01% <100.00%> (ø)
kube_hunter/modules/discovery/kubectl.py 46.42% <100.00%> (ø)
kube_hunter/modules/discovery/kubelet.py 46.00% <100.00%> (ø)
kube_hunter/modules/discovery/ports.py 88.88% <100.00%> (ø)
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 9ce385a...e6d1bb3. Read the comment docs.