aquasecurity / kube-hunter

Hunt for security weaknesses in Kubernetes clusters
Apache License 2.0
4.66k stars 579 forks source link

Pyinstaller is failing #418

Closed danielsagi closed 3 years ago

danielsagi commented 3 years ago

What happened

When compiling using make pyinstaller there is a runtime error that occurs when starting any scan:

Traceback (most recent call last):
  File "kube_hunter/__main__.py", line 37, in <module>
    from kube_hunter.modules.discovery.hosts import RunningAsPodEvent, HostScanEvent
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "/usr/local/lib/python3.9/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "kube_hunter/modules/__init__.py", line 2, in <module>
    from . import report
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "/usr/local/lib/python3.9/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "kube_hunter/modules/report/__init__.py", line 2, in <module>
    from kube_hunter.modules.report.factory import get_reporter, get_dispatcher
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "/usr/local/lib/python3.9/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "kube_hunter/modules/report/factory.py", line 5, in <module>
    from kube_hunter.modules.report.plain import PlainReporter
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "/usr/local/lib/python3.9/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "kube_hunter/modules/report/plain.py", line 1, in <module>
    from prettytable import ALL, PrettyTable
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "/usr/local/lib/python3.9/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "prettytable/__init__.py", line 43, in <module>
  File "pkg_resources/__init__.py", line 465, in get_distribution
  File "pkg_resources/__init__.py", line 341, in get_provider
  File "pkg_resources/__init__.py", line 884, in require
  File "pkg_resources/__init__.py", line 770, in resolve
pkg_resources.DistributionNotFound: The 'prettytable' distribution was not found and is required by the application
[3989] Failed to execute script __main__

Expected behavior

prettytable should be integrated correctly.

reference

There is a discussion regarding this issue in pyinstaller repository.

Adding a specific import hook for pyinstaller should fix this:

from PyInstaller.utils.hooks import collect_all

datas, binaries, hiddenimports = collect_all('prettytable')

Adding a specific folder that will contain those hooks to address further similar issues will be a good idea.