Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Removed automatic import of handler object #506

Merged
merged 2 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions kube_hunter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ in order to prevent circular dependency bug.
Following the above example, let's figure out the imports:
```python
from kube_hunter.core.types import Hunter
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler

from kube_hunter.core.events.types import OpenPortEvent

Expand Down Expand Up @@ -206,7 +206,7 @@ __Make sure to return the event from the execute method, or the event will not g

For example, if you don't want to hunt services found on a localhost IP, you can create the following module, in the `kube_hunter/modules/report/`
```python
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Service, EventFilterBase

@handler.subscribe(Service)
Expand All @@ -222,7 +222,7 @@ That means other Hunters that are subscribed to this Service will not get trigge
That opens up a wide variety of possible operations, as this not only can __filter out__ events, but you can actually __change event attributes__, for example:

```python
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.types import InformationDisclosure
from kube_hunter.core.events.types import Vulnerability, EventFilterBase

Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# Running all other registered plugins before execution
pm.hook.load_plugin(args=args)

from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import HuntFinished, HuntStarted
from kube_hunter.modules.discovery.hosts import RunningAsPodEvent, HostScanEvent
from kube_hunter.modules.report import get_reporter, get_dispatcher
Expand Down
1 change: 0 additions & 1 deletion kube_hunter/core/events/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# flake8: noqa: E402
from .handler import EventQueue, handler
from . import types
2 changes: 1 addition & 1 deletion kube_hunter/core/types/hunters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_name(cls):
def publish_event(self, event):
# Import here to avoid circular import from events package.
# imports are cached in python so this should not affect runtime
from ..events import handler # noqa
from ..events.event_handler import handler # noqa

handler.publish_event(event, caller=self)

Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/discovery/apiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests

from kube_hunter.core.types import Discovery
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import OpenPortEvent, Service, Event, EventFilterBase

from kube_hunter.conf import get_config
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/discovery/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import requests

from kube_hunter.conf import get_config
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Event, OpenPortEvent, Service
from kube_hunter.core.types import Discovery

Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/discovery/etcd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Event, OpenPortEvent, Service
from kube_hunter.core.types import Discovery

Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/discovery/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from kube_hunter.conf import get_config
from kube_hunter.modules.discovery.kubernetes_client import list_all_k8s_cluster_nodes
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Event, NewHostEvent, Vulnerability
from kube_hunter.core.types import Discovery, AWS, Azure, InstanceMetadataApiTechnique

Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/discovery/kubectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import subprocess

from kube_hunter.core.types import Discovery
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import HuntStarted, Event

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/discovery/kubelet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from kube_hunter.conf import get_config
from kube_hunter.core.types import Discovery
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import OpenPortEvent, Event, Service

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/discovery/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from socket import socket

from kube_hunter.core.types import Discovery
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import NewHostEvent, OpenPortEvent

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/discovery/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from kube_hunter.conf import get_config
from kube_hunter.core.types import Discovery
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Service, Event, OpenPortEvent

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/hunting/aks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from kube_hunter.conf import get_config
from kube_hunter.modules.hunting.kubelet import ExposedPodsHandler, SecureKubeletPortHunter
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Event, Vulnerability
from kube_hunter.core.types import Hunter, ActiveHunter, MountServicePrincipalTechnique, Azure

Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/hunting/apiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from kube_hunter.conf import get_config
from kube_hunter.modules.discovery.apiserver import ApiServer
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Vulnerability, Event, K8sVersionDisclosure
from kube_hunter.core.types import Hunter, ActiveHunter, KubernetesCluster
from kube_hunter.core.types.vulnerabilities import (
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/hunting/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

from kube_hunter.modules.discovery.hosts import RunningAsPodEvent
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Event, Vulnerability
from kube_hunter.core.types import Hunter, ARPPoisoningTechnique, KubernetesCluster

Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/hunting/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re

from kube_hunter.core.types import Hunter, KubernetesCluster, GeneralSensitiveInformationTechnique
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Vulnerability, Event, Service

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/hunting/cves.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from packaging import version

from kube_hunter.conf import get_config
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler

from kube_hunter.core.events.types import K8sVersionDisclosure, Vulnerability, Event
from kube_hunter.core.types import (
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/hunting/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from kube_hunter.conf import get_config
from kube_hunter.core.types import Hunter, AccessK8sDashboardTechnique, KubernetesCluster
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Vulnerability, Event
from kube_hunter.modules.discovery.dashboard import KubeDashboardEvent

Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/hunting/etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests

from kube_hunter.conf import get_config
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Vulnerability, Event, OpenPortEvent
from kube_hunter.core.types import (
ActiveHunter,
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/hunting/kubelet.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import uuid

from kube_hunter.conf import get_config
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Vulnerability, Event, K8sVersionDisclosure
from kube_hunter.core.types import (
Hunter,
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/hunting/mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import uuid

from kube_hunter.conf import get_config
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Event, Vulnerability
from kube_hunter.core.types import ActiveHunter, Hunter, KubernetesCluster, HostPathMountPrivilegeEscalationTechnique
from kube_hunter.modules.hunting.kubelet import (
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/hunting/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from enum import Enum

from kube_hunter.conf import get_config
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Event, Vulnerability, K8sVersionDisclosure
from kube_hunter.core.types import (
ActiveHunter,
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/hunting/secrets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os

from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import Vulnerability, Event
from kube_hunter.core.types import Hunter, KubernetesCluster, AccessContainerServiceAccountTechnique
from kube_hunter.modules.discovery.hosts import RunningAsPodEvent
Expand Down
2 changes: 1 addition & 1 deletion kube_hunter/modules/report/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import threading

from kube_hunter.conf import get_config
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import (
Event,
Service,
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

set_config(Config(active=True))

from kube_hunter.core.events.handler import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.modules.discovery.apiserver import ApiServiceDiscovery
from kube_hunter.modules.discovery.dashboard import KubeDashboard as KubeDashboardDiscovery
from kube_hunter.modules.discovery.etcd import EtcdRemoteAccess as EtcdRemoteAccessDiscovery
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from kube_hunter.conf import Config, set_config
from kube_hunter.core.types import Hunter
from kube_hunter.core.events.types import Event, Service
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler

counter = 0
first_run = True
Expand Down
2 changes: 1 addition & 1 deletion tests/discovery/test_apiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from kube_hunter.modules.discovery.apiserver import ApiServer, ApiServiceDiscovery
from kube_hunter.core.events.types import Event
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler

counter = 0

Expand Down
2 changes: 1 addition & 1 deletion tests/discovery/test_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
HostDiscoveryHelpers,
)
from kube_hunter.core.types import Hunter
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
import json
import requests_mock
import pytest
Expand Down
2 changes: 1 addition & 1 deletion tests/hunting/test_apiserver_hunter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from kube_hunter.modules.hunting.apiserver import CreateANamespace, DeleteANamespace
from kube_hunter.modules.discovery.apiserver import ApiServer
from kube_hunter.core.types import ExposedSensitiveInterfacesTechnique, AccessK8sApiServerTechnique
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler

counter = 0

Expand Down
2 changes: 1 addition & 1 deletion tests/hunting/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from kube_hunter.core.events.types import Event
from kube_hunter.modules.hunting.certificates import CertificateDiscovery, CertificateEmail
from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler


def test_CertificateDiscovery():
Expand Down
2 changes: 1 addition & 1 deletion tests/hunting/test_cvehunting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

set_config(Config())

from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.core.events.types import K8sVersionDisclosure
from kube_hunter.modules.hunting.cves import (
K8sClusterCveHunter,
Expand Down
2 changes: 1 addition & 1 deletion tests/hunting/test_kubelet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import urllib.parse
import uuid

from kube_hunter.core.events import handler
from kube_hunter.core.events.event_handler import handler
from kube_hunter.modules.hunting.kubelet import (
AnonymousAuthEnabled,
ExposedExistingPrivilegedContainersViaSecureKubeletPort,
Expand Down