-
Notifications
You must be signed in to change notification settings - Fork 16
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
Agent command manager #4
Comments
Update(11/06/2024) Understanding the issue requeriments. Reviewing related issues, discussing with team issue impact and doubts to deliver to management. Main commands:
Optional/not definitive commands
A primitive approach for the JSON structure representing the commands could be as follows:
Currently designing sequence diagram diagram to illustrate it. (20/06/2024) The attached diagram wants to replicate the following behavior:
(21/06/2024) Working on POC. |
Update 18/06/2024
Update 19/06/2024
Update 21/06/2024
Update 25/06/2024
|
Possible optional design of our Agent command manager, first revisionThe current list of possible necessary commands to be considered:
Initial format of the JSON containing the command information:
Class diagramclassDiagram
class Server {
+sendCommand(cmd: Command)
}
class CommandManager {
-commandStore: CommandStore
-executor: Executor
+storeCommands()
+executeCommand()
}
class CommandStore {
+storeCommand(cmd: Command)
+getNextCommand(): Command
+deleteCompletedCommands(cmd: Command)
}
class Executor {
-feedback: Feedback
+execute(cmd: Command)
+generateFeedback(cmd: Command)
+reportFeedback(): Feedback
}
class AgentCommsAPIClient {
+getConnection()
+pollCommands()
+receiveCommands(cmds: List<Command>)
+addCommands(cmds: List<Command>)
+sendFeedback(feedback: Feedback)
}
class Command {
+name: String
+type: String
+data: String
+status: String
+execute()
+markCompleted()
}
class Feedback {
+status: String
+message: String
}
CommandManager "1" *-- "1" CommandStore
CommandManager "1" *-- "1" Executor
CommandManager "1" -- "1" AgentCommsAPIClient
AgentCommsAPIClient "1..*" -- "1" Server
CommandStore "1" -- "1..*" Command
Command "1" -- "0..1" Feedback
Executor "1" -- "0..1" Feedback
Sequence diagramsequenceDiagram
participant Server
participant AgentCommsAPIClient
participant CommandManager
participant CommandStore
participant Executor
participant Feedback
AgentCommsAPIClient->>Server: getConnection()
AgentCommsAPIClient->>Server: pollCommands()
Server->>AgentCommsAPIClient: sendCommand()
AgentCommsAPIClient->>CommandManager: addCommands()
CommandManager->>CommandStore: storeCommand()
CommandManager->>Executor: executeCommand()
Executor->>CommandStore: getNextCommand()
Executor->>Executor: execute()
Executor->>Feedback: generateFeedback()
Executor->>CommandManager: reportFeedback()
CommandManager->>CommandStore: markCompleted()
CommandStore->>CommandStore: deleteCompletedCommands()
CommandManager->>AgentCommsAPIClient: reportFeedback()
AgentCommsAPIClient->>Server: reportFeedback()
|
Update 26/06/2024POC commanderI have been working on a little in c++ to try to approach little by little to the requirements of the issue, in this case, what I have is a Commander class, that executes two threads (pending to analyze the use of routines and coroutines), one of them is in charge of receiving the messages and save them in the store, and the other to process them and pass the feedback, to then delete them from the store: File: commander/commander.cpp Example of use in the restar-agent case:
|
Update 27/06/2024After a meeting with the team and Vikman, we have drawn some conclusions to improve the poc, I have updated the code to better contain the dispatch and execute functions: Doing some tests with the code flow we can observe the following:
Video testing demonstration, top cmd is program execution, and bottom cmd is for command_queue.txt, the file where the commands for persistence are stored: root@ubuntu24_._vagrant.2024-06-27.12-52-50.mp4 |
LGTM. GJ team! |
Parent issue:
Description
As part of the new data persistence model being implemented across Wazuh, we need a new way to manage commands sent from the Wazuh servers to the agents. In this spike, we will identify all the commands the agent must support, including the data required by the agent to execute them. We will also design a command manager which will be in charge of executing these commands.
The following diagram outlines a simplified design:
Functional requirements
Implementation restrictions
We want to use C++ to leverage its performance and system-level capabilities.
This module should be implemented as a library to ensure modularity and reusability, allowing it to be integrated seamlessly with other modules.
This module will be tied to the main process of the agent, ensuring it operates as a core component of the agent's functionality.
Plan
Review the existing agent to compile a comprehensive list of all commands that agents must support.
Determine the structure and required attributes of the commands. Each command will be represented as a JSON document to standardize its format.
Create a robust API for the command manager that allows it to receive command events from the server and provide clear feedback on the execution status or errors encountered.
As a proof of concept, implement a basic restart command to ensure the command manager can execute commands correctly. This will involve coding the logic to handle the restart operation, persist the command, mark it as completed, and generate appropriate feedback.
The text was updated successfully, but these errors were encountered: