diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index bf5a5a9e0f..929e803ffc 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -86,6 +86,8 @@ jobs: - test_idea_format.py - test_fides_sqlite_db.py - test_fides_module.py + - test_fides_queues.py + - test_fides_bridge.py steps: - uses: actions/checkout@v4 diff --git a/config/iris_config.yaml b/config/iris_config.yaml index e54820f683..76625208fc 100644 --- a/config/iris_config.yaml +++ b/config/iris_config.yaml @@ -1,12 +1,14 @@ Identity: GenerateNewKey: true Server: - port: 9010 - Host: 127.0.0.1 - DhtServerMode: true + Port: 9010 + Host: 0.0.0.0 + DhtServerMode: 'true' Redis: Host: 127.0.0.1 - Port: 6644 + Port: 6379 Tl2NlChannel: iris_internal PeerDiscovery: - DisableBootstrappingNodes: true + DisableBootstrappingNodes: false + ListOfMultiAddresses: + - /dns/melchior.slips.stratosphere.fel.cvut.cz/udp/6437/quic 12D3KooWJJa9PpMFVP7s3TQs2sedypJXxtMVkphRhgkjGH9EYMfM diff --git a/config/slips.yaml b/config/slips.yaml index 34f41e7109..b9a21e9015 100644 --- a/config/slips.yaml +++ b/config/slips.yaml @@ -500,6 +500,8 @@ global_p2p: # running slips on an interface use_global_p2p: False iris_conf: config/iris_config.yaml + bootstrapping_node: False + bootstrapping_modules: ["fidesModule", "irisModule"] ############################# local_p2p: diff --git a/docs/iris_module.md b/docs/iris_module.md index f7db76ee5c..6c1c7ce4b9 100644 --- a/docs/iris_module.md +++ b/docs/iris_module.md @@ -109,6 +109,15 @@ dispatched to peers, without regard to trust level accumulated on them. + + +### Bootstrapping node +The Slips configuration file now has an option of bootstrapping-node mode. +The bootstrapping functionality for the global P2P network under Iris is facilitated. +This mode triggers only if Slips is run on an interface or growing zeek log directory mode AND the bootstrapping is set to True in the Slips configurations file AND GlobalP2P mode is allowed. +When the bootstrapping mode is used, Slips runs with a subset of nodes that are selected by names (currently Fides and Iris). + + ## Testing ### Unit Tests diff --git a/managers/process_manager.py b/managers/process_manager.py index 4499b5ac04..75def49146 100644 --- a/managers/process_manager.py +++ b/managers/process_manager.py @@ -29,6 +29,8 @@ ) import multiprocessing +from scipy.stats import bootstrap + import modules from modules.update_manager.update_manager import UpdateManager from slips_files.common.slips_utils import utils @@ -77,6 +79,9 @@ def read_config(self): self.modules_to_ignore: list = self.main.conf.get_disabled_modules( self.main.input_type ) + self.bootstrap_p2p = self.main.conf.is_bootstrapping_node() + self.bootstrapping_modules = self.main.conf.get_bootstrapping_modules() + #self.bootstrap_p2p, self.boootstrapping_modules = self.main.conf.get_bootstrapping_setting() def start_output_process(self, stderr, slips_logfile, stdout=""): output_process = Output( @@ -210,6 +215,26 @@ def is_ignored_module(self, module_name: str) -> bool: return True return False + def is_bootstrapping_module(self, module_name: str) -> bool: + m1 = ( + module_name.replace(" ", "") + .replace("_", "") + .replace("-", "") + .lower() + ) + for bootstrap_module in self.bootstrapping_modules: + m2 = ( + bootstrap_module.replace(" ", "") + .replace("_", "") + .replace("-", "") + .lower() + ) + + if m1.__contains__(m2): + return True + self.modules_to_ignore.append(module_name.split(".")[-1]) + return False + def is_abstract_module(self, obj) -> bool: return obj.name in ("IModule", "AsyncModule") @@ -241,8 +266,12 @@ def get_modules(self): if dir_name != file_name: continue - if self.is_ignored_module(module_name): - continue + if self.bootstrap_p2p: # if bootstrapping the p2p network + if not self.is_bootstrapping_module(module_name): # keep only the bootstrapping-necessary modules + continue + else: # if not bootstrappig mode + if self.is_ignored_module(module_name): # ignore blacklisted modules + continue # Try to import the module, otherwise skip. try: diff --git a/modules/irisModule/iris b/modules/irisModule/iris index 1ccbeba8ff..1b213218e0 100755 Binary files a/modules/irisModule/iris and b/modules/irisModule/iris differ diff --git a/modules/irisModule/irisModule.py b/modules/irisModule/irisModule.py index 094b7f1a15..eed75559d5 100644 --- a/modules/irisModule/irisModule.py +++ b/modules/irisModule/irisModule.py @@ -60,6 +60,16 @@ def _iris_configurator(self, config_path: str, redis_port: int): "Port": redis_port, "Tl2NlChannel": "iris_internal", } + if "Server" in config: + #config["Server"]["Port"] = 9010 + config["Server"]["Host"] = self.db.get_host_ip() + config["Server"]["DhtServerMode"] = "true" + else: + config["Redis"] = { + "Port": 6644, + "Host": self.db.get_host_ip(), + "DhtServerMode": "true", + } # Write the updated configuration back to the file with open(config_path, "w") as file: @@ -79,7 +89,7 @@ def _iris_configurator(self, config_path: str, redis_port: int): # Catch any other unexpected errors self.print(f"An unexpected error occurred: {e}") return None - return config["Server"]["port"] + return config["Server"]["Port"] def pre_main(self): """ diff --git a/slips_files/common/parsers/config_parser.py b/slips_files/common/parsers/config_parser.py index d93352b518..40f1b044bc 100644 --- a/slips_files/common/parsers/config_parser.py +++ b/slips_files/common/parsers/config_parser.py @@ -722,3 +722,25 @@ def get_iris_config_location(self) -> str: return self.read_configuration( "global_p2p", "iris_conf", "config/iris_config.yaml" ) + + def get_bootstrapping_setting(self) -> (bool, list): + return ( + self.read_configuration("global_p2p", "bootstrapping_node", False) + and self.read_configuration("global_p2p", "use_global_p2p", False) + and ("-i" in sys.argv or "-g" in sys.argv), + ["fidesModule", "irisModule"], + ) + + def is_bootstrapping_node(self) -> bool: + return ( + self.read_configuration("global_p2p", "bootstrapping_node", False) + and self.read_configuration("global_p2p", "use_global_p2p", False) + and ("-i" in sys.argv or "-g" in sys.argv) + ) + + def get_bootstrapping_modules(self) -> list: + return self.read_configuration( + "global_p2p", + "bootstrapping_modules", + ["fidesModule", "irisModule"], + ) diff --git a/tests/integration_tests/test_iris.py b/tests/integration_tests/test_iris.py index 380d966dfb..0e13053cdb 100644 --- a/tests/integration_tests/test_iris.py +++ b/tests/integration_tests/test_iris.py @@ -225,6 +225,7 @@ def test_messaging( "PeerDiscovery": { "ListOfMultiAddresses": [original_conn_string] }, + "Identity": {"KeyFile": "second.priv"} }, ) # generate a second command for the second peer @@ -294,3 +295,15 @@ def test_messaging( print("Deleting the output directories") shutil.rmtree(output_dir) shutil.rmtree(output_dir_peer) + os.remove("modules/irisModule/second.priv") + modify_yaml_config( + input_path="config/iris_config.yaml", + output_dir=os.path.dirname(iris_peer_config_file), + output_filename=os.path.basename(iris_peer_config_file), + changes={ + "Redis": {"Port": 6644}, + "Server": {"Port": 9010}, + "PeerDiscovery": {}, + "Identity": {"KeyFile": "private.key"} + }, + ) diff --git a/tests/module_factory.py b/tests/module_factory.py index 6c14547ee9..7e72a2ab46 100644 --- a/tests/module_factory.py +++ b/tests/module_factory.py @@ -671,6 +671,9 @@ def create_profile_handler_obj(self): def create_process_manager_obj(self): main_mock = Mock() main_mock.conf.get_disabled_modules.return_value = [] + #main_mock.conf.get_bootstrapping_setting.return_value = (False, []) + main_mock.conf.is_bootstrapping_node.return_value = False + main_mock.conf.get_bootstrapping_modules.return_value = ["fidesModule", "irisModule"] main_mock.input_type = "pcap" main_mock.mode = "normal" main_mock.stdout = "" diff --git a/tests/tests_fides_bridge.py b/tests/test_fides_bridge.py similarity index 100% rename from tests/tests_fides_bridge.py rename to tests/test_fides_bridge.py diff --git a/tests/test_process_manager.py b/tests/test_process_manager.py index 3ee9f2be61..a8eccff4ff 100644 --- a/tests/test_process_manager.py +++ b/tests/test_process_manager.py @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2021 Sebastian Garcia # SPDX-License-Identifier: GPL-2.0-only import pytest -from unittest.mock import Mock, patch +from unittest.mock import Mock, patch, MagicMock from managers.process_manager import ProcessManager from tests.module_factory import ModuleFactory from slips_files.common.slips_utils import utils @@ -286,7 +286,9 @@ def test_is_stop_msg_received( ], ) def test_is_debugger_active(mock_return_value, expected_result): - process_manager = ProcessManager(Mock()) + mock_conf = Mock() + mock_conf.get_bootstrapping_setting.return_value = (False, []) + process_manager = ProcessManager(mock_conf) # This line should now work with patch("sys.gettrace", return_value=mock_return_value): assert process_manager.is_debugger_active() == expected_result