wazuh / wazuh-agent

Wazuh agent, the Wazuh agent for endpoints.
GNU Affero General Public License v3.0
21 stars 12 forks source link

Integrate the Command Handler with the Module Manager #146

Open TomasTurina opened 3 weeks ago

TomasTurina commented 3 weeks ago

Parent issue:

Description

After the development of the new Command Handler, it is necessary to integrate it with the Module Manager so that modules can execute commands and report their feedback.

Considerations

After the implementation is complete, we also need to add some UT to test the entire execution flow of a command.

jr0me commented 1 week ago

Update

Started looking into the issue and its requirements. Also looking at the current state of the involved components' code and the branch enhancement/17-migrate-syscollector-to-inventory-at-new-agent.

jr0me commented 1 week ago

Update

Created branch and linked it to this issue. Started looking into the CommandHandler, CommandStore and ModuleWrapper to come up with a solution.

jr0me commented 1 week ago

Update

Implemented first attempt to process a command, fetching its corresponding module and passing to it the command b4dc05b0c357c08ca16f8449efa0a554f401c325

Now it's necessary to come up with a non blocking mechanism to execute commands.

jr0me commented 6 days ago

Update

Implemented first approach with coroutines. The functions (in modules, module wrapper, etc) that execute the commands needed to return awaitables among other changes. Testing with the new server comms mvp.

jr0me commented 5 days ago

Update

Defined an initial format for the stateful messages created by command executions.

{
  "data":
  {
    "id": str,
    "error": int,
    "message": str
  },
  "module": str
}

Further improvements to the coroutines approach used so far. There's a dependency between the ModularManager, ModuleWrapper, Inventory, Command, CommandStore, CommandHandler that needs further iterations to improve. For instance the error and result codes or messages that come from a command being stored until it is executed and then communicated to the server needs to be settled.

jr0me commented 3 days ago

Update

Created draft PR. Timeout implementation is currently missing, as well as the insurance of execution order, since at the moment only one sequential execution at the time is allowed. Despite this, and despite a review is still missing, the issue will be blocked until https://github.com/wazuh/wazuh-agent/pull/45 is merged.

jr0me commented 1 day ago

Update

First PR merged, now looking into adding a timeout mechanism to dispatched commands, and to allow multiple commands to be dispatched simultaneously.

jr0me commented 4 hours ago

Update

Debugging the timeout mechanism implemented. Working on branch https://github.com/wazuh/wazuh-agent/tree/enhancement/146-simultaneous-command-dispatch-with-timeout