def GetFleetspeakPortsFromConfig(config_path): """Gets Fleetspeak frontend and admin ports from GRR config.""" conf = config_lib.LoadConfig(config.CONFIG.MakeNewConfig(), config_path) frontend_port = int( conf["Server.fleetspeak_message_listen_address"].rsplit(":")[-1]) admin_port = int(conf["Server.fleetspeak_server"].rsplit(":")[-1]) return frontend_port, admin_port
def main(argv): del argv # Unused. if not flags.FLAGS.dest_server_config_path: raise ValueError("dest_server_config_path flag has to be provided.") if not flags.FLAGS.dest_client_config_path: raise ValueError("dest_client_config_path flag has to be provided.") admin_ui_port = portpicker.pick_unused_port() frontend_port = portpicker.pick_unused_port() source_server_config_path = package.ResourcePath( "grr-response-core", "install_data/etc/grr-server.yaml") config_lib.LoadConfig(config.CONFIG, source_server_config_path) config.CONFIG.SetWriteBack(flags.FLAGS.dest_server_config_path) # TODO(user): remove when AFF4 is gone. config.CONFIG.Set("Database.enabled", True) config.CONFIG.Set("Blobstore.implementation", "DbBlobStore") config.CONFIG.Set("Database.implementation", "MysqlDB") config.CONFIG.Set("Mysql.database", flags.FLAGS.config_mysql_database) if flags.FLAGS.config_mysql_username is not None: config.CONFIG.Set("Mysql.username", flags.FLAGS.config_mysql_username) if flags.FLAGS.config_mysql_password is not None: config.CONFIG.Set("Mysql.password", flags.FLAGS.config_mysql_password) config.CONFIG.Set("AdminUI.port", admin_ui_port) config.CONFIG.Set("AdminUI.headless", True) config.CONFIG.Set("Frontend.bind_address", "127.0.0.1") config.CONFIG.Set("Frontend.bind_port", frontend_port) config.CONFIG.Set("Server.initialized", True) config.CONFIG.Set("Cron.active", False) config.CONFIG.Set("Client.poll_max", 1) config.CONFIG.Set("Client.server_urls", ["http://localhost:%d/" % frontend_port]) if flags.FLAGS.config_logging_path is not None: config.CONFIG.Set("Logging.path", flags.FLAGS.config_logging_path) config.CONFIG.Set("Logging.verbose", False) if flags.FLAGS.config_osquery_path: config.CONFIG.Set("Osquery.path", flags.FLAGS.config_osquery_path) config_updater_keys_util.GenerateKeys(config.CONFIG) config.CONFIG.Write() config_lib.SetPlatformArchContext() context = list(config.CONFIG.context) context.append("Client Context") config_data = build_helpers.GetClientConfig(context, validate=False, deploy_timestamp=False) with io.open(flags.FLAGS.dest_client_config_path, "w") as fd: fd.write(config_data)
def main(argv): del argv # Unused. if not flags.FLAGS.dest_server_config_path: raise ValueError("dest_server_config_path flag has to be provided.") if not flags.FLAGS.dest_client_config_path: raise ValueError("dest_client_config_path flag has to be provided.") admin_ui_port = portpicker.pick_unused_port() frontend_port = portpicker.pick_unused_port() datastore_port = portpicker.pick_unused_port() source_server_config_path = package.ResourcePath( "grr-response-core", "install_data/etc/grr-server.yaml") config_lib.LoadConfig(config.CONFIG, source_server_config_path) config.CONFIG.SetWriteBack(flags.FLAGS.dest_server_config_path) # TODO(user): remove when AFF4 is gone. config.CONFIG.Set("Database.aff4_enabled", False) config.CONFIG.Set("Database.enabled", True) config.CONFIG.Set("Blobstore.implementation", "DbBlobStore") config.CONFIG.Set("Database.implementation", "SharedMemoryDB") config.CONFIG.Set("SharedMemoryDB.port", datastore_port) config.CONFIG.Set("AdminUI.port", admin_ui_port) config.CONFIG.Set("AdminUI.headless", True) config.CONFIG.Set("Frontend.bind_address", "127.0.0.1") config.CONFIG.Set("Frontend.bind_port", frontend_port) config.CONFIG.Set("Server.initialized", True) config.CONFIG.Set("Client.poll_max", 1) config.CONFIG.Set("Client.server_urls", ["http://localhost:%d/" % frontend_port]) config_updater_keys_util.GenerateKeys(config.CONFIG) config.CONFIG.Write() config_lib.SetPlatformArchContext() context = list(config.CONFIG.context) context.append("Client Context") deployer = build.ClientRepacker() config_data = deployer.GetClientConfig(context, validate=False, deploy_timestamp=False) with io.open(flags.FLAGS.dest_client_config_path, "w") as fd: fd.write(config_data)
def main(argv): del argv # Unused. if flags.FLAGS.mysql_username is None: raise ValueError("--mysql_username has to be specified.") # Create 2 temporary files to contain server and client configuration files # that we're about to generate. # # TODO(user): migrate to TempFilePath as soon grr.test_lib is moved to # grr_response_test. fd, built_server_config_path = tempfile.mkstemp(".yaml") os.close(fd) print("Using temp server config path: %s" % built_server_config_path) fd, built_client_config_path = tempfile.mkstemp(".yaml") os.close(fd) print("Using temp client config path: %s" % built_client_config_path) def CleanUpConfigs(): os.remove(built_server_config_path) os.remove(built_client_config_path) atexit.register(CleanUpConfigs) # Generate server and client configs. config_writer_flags = [ "--dest_server_config_path", built_server_config_path, "--dest_client_config_path", built_client_config_path, "--config_mysql_database", flags.FLAGS.mysql_database, ] if flags.FLAGS.mysql_username is not None: config_writer_flags.extend( ["--config_mysql_username", flags.FLAGS.mysql_username]) if flags.FLAGS.mysql_password is not None: config_writer_flags.extend( ["--config_mysql_password", flags.FLAGS.mysql_password]) if flags.FLAGS.logging_path is not None: config_writer_flags.extend( ["--config_logging_path", flags.FLAGS.logging_path]) p = StartComponent("grr_response_test.lib.self_contained_config_writer", config_writer_flags) if p.wait() != 0: raise RuntimeError("ConfigWriter execution failed: {}".format( p.returncode)) server_config = config_lib.LoadConfig(config.CONFIG.MakeNewConfig(), built_server_config_path) # Start the client. preliminary_client_p = StartComponent( "grr_response_client.client", ["--config", built_client_config_path]) # Start all remaining server components. server_processes = [ StartComponent("grr_response_server.gui.admin_ui", GetServerComponentArgs(built_server_config_path)), StartComponent("grr_response_server.bin.frontend", GetServerComponentArgs(built_server_config_path)), StartComponent("grr_response_server.bin.worker", GetServerComponentArgs(built_server_config_path)), ] # Start a background thread that kills the main process if one of the # server subprocesses dies. t = threading.Thread(target=DieIfSubProcessDies, args=(server_processes, )) t.daemon = True t.start() # Wait for the client to enroll and get its id. client_id = WaitForClientToEnroll(server_config["AdminUI.port"]) print("Found client id: %s" % client_id) # Python doesn't guarantee the process name of processes started by the Python # interpreter. They may vary from platform to platform. In order to ensure # that Client.binary_name config setting matches the actual process name, # let's get the name via psutil, kill the client and set the # Config.binary_name explicitly. client_binary_name = str(psutil.Process(preliminary_client_p.pid).name()) KillClient(server_config["AdminUI.port"], client_id) preliminary_client_p.wait() print("Starting the client with Client.binary_name=%s" % client_binary_name) client_p = StartComponent("grr_response_client.client", [ "--config", built_client_config_path, "-p", "Client.binary_name=%s" % client_binary_name ]) # Start a background thread that kills the main process if # client subprocess dies. t = threading.Thread(target=DieIfSubProcessDies, args=([client_p], )) t.daemon = True t.start() # Run the test suite against the enrolled client. p = StartComponent( "grr_response_test.run_end_to_end_tests", GetServerComponentArgs(built_server_config_path) + GetRunEndToEndTestsArgs(client_id, server_config)) if p.wait() != 0: raise RuntimeError("RunEndToEndTests execution failed.") print("RunEndToEndTests execution succeeded.")
def main(argv): del argv # Unused. # Create 2 temporary files to contain server and client configuration files # that we're about to generate. # # TODO(user): migrate to TempFilePath as soon grr.test_lib is moved to # grr_response_test. fd, built_server_config_path = tempfile.mkstemp(".yaml") os.close(fd) print("Using temp server config path: %s" % built_server_config_path) fd, built_client_config_path = tempfile.mkstemp(".yaml") os.close(fd) print("Using temp client config path: %s" % built_client_config_path) def CleanUpConfigs(): os.remove(built_server_config_path) os.remove(built_client_config_path) atexit.register(CleanUpConfigs) # Generate server and client configs. p = StartServerComponent("ConfigWriter", ImportSelfContainedConfigWriter, [ "--dest_server_config_path", built_server_config_path, "--dest_client_config_path", built_client_config_path, ]) p.join() if p.exitcode != 0: raise RuntimeError("ConfigWriter execution failed: {}".format( p.exitcode)) server_config = config_lib.LoadConfig(config.CONFIG.MakeNewConfig(), built_server_config_path) # Start SharedMemoryDbServer and wait for it to come up. dp = StartServerComponent("DBServer", ImportSharedMemoryDBServer, GetServerComponentArgs(built_server_config_path)) WaitForTCPPort(server_config["SharedMemoryDB.port"]) # Start all remaining server components. processes = [ dp, StartServerComponent("AdminUI", ImportAdminUI, GetServerComponentArgs(built_server_config_path)), StartServerComponent("Frontend", ImportFrontend, GetServerComponentArgs(built_server_config_path)), StartServerComponent("Worker", ImportWorker, GetServerComponentArgs(built_server_config_path)), StartClient(built_client_config_path), ] # Start a background thread that kills the main process if one of the # subprocesses dies. t = threading.Thread(target=DieIfSubProcessDies, args=(processes, )) t.daemon = True t.start() # Wait for the client to enroll and get its id. client_id = WaitForClientToEnroll(server_config["AdminUI.port"]) print("Found client id: %s" % client_id) # Run the test suite against the enrolled client. p = StartServerComponent( "RunEndToEndTests", ImportRunEndToEndTests, GetServerComponentArgs(built_server_config_path) + GetRunEndToEndTestsArgs(client_id, server_config)) p.join() if p.exitcode != 0: raise RuntimeError("RunEndToEndTests execution failed.") print("RunEndToEndTests execution succeeded.")
def main(argv): del argv # Unused. if flags.FLAGS.mysql_username is None: raise ValueError("--mysql_username has to be specified.") # Create 2 temporary files to contain server and client configuration files # that we're about to generate. # # TODO(user): migrate to TempFilePath as soon grr.test_lib is moved to # grr_response_test. fd, built_server_config_path = tempfile.mkstemp(".yaml") os.close(fd) print("Using temp server config path: %s" % built_server_config_path) fd, built_client_config_path = tempfile.mkstemp(".yaml") os.close(fd) print("Using temp client config path: %s" % built_client_config_path) def CleanUpConfigs(): os.remove(built_server_config_path) os.remove(built_client_config_path) atexit.register(CleanUpConfigs) # Generate server and client configs. config_writer_flags = [ "--dest_server_config_path", built_server_config_path, "--dest_client_config_path", built_client_config_path, "--config_mysql_database", flags.FLAGS.mysql_database, ] if flags.FLAGS.mysql_username is not None: config_writer_flags.extend( ["--config_mysql_username", flags.FLAGS.mysql_username]) if flags.FLAGS.mysql_password is not None: config_writer_flags.extend( ["--config_mysql_password", flags.FLAGS.mysql_password]) if flags.FLAGS.logging_path is not None: config_writer_flags.extend( ["--config_logging_path", flags.FLAGS.logging_path]) p = StartComponent("grr_response_test.lib.self_contained_config_writer", config_writer_flags) if p.wait() != 0: raise RuntimeError("ConfigWriter execution failed: {}".format( p.returncode)) server_config = config_lib.LoadConfig(config.CONFIG.MakeNewConfig(), built_server_config_path) # Start all remaining server components. processes = [ StartComponent("grr_response_server.gui.admin_ui", GetServerComponentArgs(built_server_config_path)), StartComponent("grr_response_server.bin.frontend", GetServerComponentArgs(built_server_config_path)), StartComponent("grr_response_server.bin.worker", GetServerComponentArgs(built_server_config_path)), StartComponent("grr_response_client.client", ["--config", built_client_config_path, "--verbose"]), ] # Start a background thread that kills the main process if one of the # subprocesses dies. t = threading.Thread(target=DieIfSubProcessDies, args=(processes, )) t.daemon = True t.start() # Wait for the client to enroll and get its id. client_id = WaitForClientToEnroll(server_config["AdminUI.port"]) print("Found client id: %s" % client_id) # Run the test suite against the enrolled client. p = StartComponent( "grr_response_test.run_end_to_end_tests", GetServerComponentArgs(built_server_config_path) + GetRunEndToEndTestsArgs(client_id, server_config)) if p.wait() != 0: raise RuntimeError("RunEndToEndTests execution failed.") print("RunEndToEndTests execution succeeded.")
def GetAdminUIPortFromConfig(config_path): """Gets the AdminUI.port setting from a given config file.""" conf = config_lib.LoadConfig(config.CONFIG.MakeNewConfig(), config_path) return conf["AdminUI.port"]