1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00
ctrl/README.md

164 lines
7.3 KiB
Markdown
Raw Normal View History

2023-10-04 20:53:03 +00:00
# Ctrl
2021-09-22 17:54:42 +00:00
2024-11-17 20:22:35 +00:00
ctrl is a Command & Control (C2) backend system for Servers, IOT and Edge platforms. Simply put, control anything.
2021-04-16 19:19:19 +00:00
2022-01-25 04:18:59 +00:00
Example use cases:
2022-01-06 09:20:30 +00:00
2024-11-17 20:22:35 +00:00
- Send shell commands or scripts to control one or many end nodes that will instruct to change config, restart services and control those systems.
2024-11-16 17:09:36 +00:00
- Gather data from both secure and not secure devices and systems, and transfer them encrypted in a secure way over the internet to your central system for handling those data.
- Collect metrics or monitor end nodes, then send and store the result to some ctrl instance, or pass those data's on to another ctrl instance for further handling of metrics or monitoring data.
2022-01-06 09:20:30 +00:00
- Distribute certificates.
2024-11-16 17:09:36 +00:00
- Run as a sidecar in Kubernetes for direct access to the pod.
2022-01-06 09:20:30 +00:00
2024-11-16 17:09:36 +00:00
As long as you can do something as an operator in a shell on a system you can do the same with ctrl in a secure and encrypted way to one or all end nodes (servers) in one go with one single message/command.
2021-04-15 05:52:42 +00:00
2021-03-11 16:14:43 +00:00
## Features
2024-11-16 17:09:36 +00:00
- Run bash commands or complete scripts of your prefered scripting language (bash, python, powershell and so on).
- Read and write to files.
- Copy files.
- ACL's to restric who can do what.
2021-04-13 15:48:25 +00:00
2024-11-17 20:22:35 +00:00
## Doc
The complete documentation can be found here [https://postmannen.github.io/ctrl/introduction.html](https://postmannen.github.io/ctrl/introduction.html)
2024-11-16 17:09:36 +00:00
## Example
2022-06-03 13:17:25 +00:00
2024-11-16 17:09:36 +00:00
An example of a **request** message to copy into ctrl's **readfolder**.
2022-06-03 13:17:25 +00:00
2024-11-16 17:09:36 +00:00
## Quick start
2022-06-03 13:17:25 +00:00
2024-11-16 17:09:36 +00:00
Start up a local nats message broker
2022-01-05 10:26:10 +00:00
2022-06-03 13:17:25 +00:00
```bash
2024-11-16 17:09:36 +00:00
docker run -p 4444:4444 nats -p 4444
2022-06-03 13:17:25 +00:00
```
2022-01-05 10:26:10 +00:00
2024-11-16 17:09:36 +00:00
Create a ctrl docker image.
2022-01-05 10:26:10 +00:00
2022-06-03 13:17:25 +00:00
```bash
2024-11-16 17:09:36 +00:00
git clone git@github.com:postmannen/ctrl.git
cd ctrl
docker build -t ctrl:test1 .
mkdir -p testrun/readfolder
cd testrun
2022-06-03 13:17:25 +00:00
```
2022-01-05 10:26:10 +00:00
2024-11-16 17:09:36 +00:00
create a .env file
2022-01-05 10:26:10 +00:00
```bash
2024-11-16 17:09:36 +00:00
cat << EOF > .env
NODE_NAME="node1"
BROKER_ADDRESS="127.0.0,1:4444"
ENABLE_DEBUG=1
START_PUB_REQ_HELLO=60
IS_CENTRAL_ERROR_LOGGER=0
EOF
2022-01-05 10:26:10 +00:00
```
2024-11-16 17:09:36 +00:00
Start the ctrl container.
2022-01-05 10:26:10 +00:00
```bash
2024-11-16 17:09:36 +00:00
docker run --env-file=".env" --rm -ti -v $(PWD)/readfolder:/app/readfolder ctrl:test1
```
2024-11-17 20:22:35 +00:00
Prepare and send a message.
2022-03-10 08:09:07 +00:00
```yaml
2024-11-16 17:09:36 +00:00
cat << EOF > msg.yaml
2022-03-10 08:09:07 +00:00
---
- toNodes:
2024-11-16 17:09:36 +00:00
- node1
2022-03-10 08:09:07 +00:00
method: REQCliCommand
methodArgs:
2024-11-16 17:09:36 +00:00
- "bash"
- "-c"
- |
echo "some config line" > /etc/my-service-config.1
echo "some config line" > /etc/my-service-config.2
echo "some config line" > /etc/my-service-config.3
systemctl restart my-service
2021-09-09 07:54:33 +00:00
2024-11-16 17:09:36 +00:00
replyMethod: REQNone
ACKTimeout: 0
EOF
2021-04-16 13:27:28 +00:00
2024-11-16 17:09:36 +00:00
cp msg.yaml readfolder
2021-04-16 13:27:28 +00:00
```
2024-11-16 17:09:36 +00:00
### Input methods
2022-01-06 09:20:30 +00:00
2024-11-16 17:09:36 +00:00
New Request Messages in Json/Yaml format can be injected by the user to ctrl in the following ways:
2022-01-06 09:20:30 +00:00
2024-11-16 17:09:36 +00:00
- **Unix Socket**. Use for example netcat or another tool to deliver new messages to a socket like `nc -U tmp/ctrl.sock < msg.yaml`.
- **Read Folder**. Write/Copy messages to be delivered to the `readfolder` of ctrl.
- **TCP Listener**, Use for example netcat or another tool to deliver new messages a TCP Listener like `nc localhost:8888 < msg.yaml`.
2022-01-06 09:20:30 +00:00
2024-11-16 17:09:36 +00:00
### Error messages from nodes
2021-09-21 09:09:14 +00:00
2024-11-16 17:09:36 +00:00
- Error messages will be sent back to the central error handler and the originating node upon failure.
2021-09-21 09:09:14 +00:00
2024-11-16 17:09:36 +00:00
The error logs can be read on the central server in the directory `<ctrl-home>/data/errorLog`, and in the log of the instance the source node. You can also create a message to read the errorlog if you don't have direct access to the central server.
2021-09-21 09:09:14 +00:00
2024-11-16 17:09:36 +00:00
### Flags and configuration file
2021-03-11 16:14:43 +00:00
2024-11-16 17:09:36 +00:00
ctrl supports both the use of flags with env variables. An .env file can also be used.
2021-03-11 16:14:43 +00:00
2024-11-16 17:09:36 +00:00
### Schema for the messages to send into ctrl via the API's
2021-03-11 16:14:43 +00:00
|Field Name | Value Type | Description|
2024-11-16 17:09:36 +00:00
|-----|-------|------------|
|toNode | `string` | A single node to send a message to|
|toNodes | `string array` | A comma separated list of nodes to send a message to|
|method | `string` | The request method to use |
|methodArgs | `string array` | The arguments to use for the method |
|replyMethod | `string` | The method to use for the reply message |
|replyMethodArgs | `string array` | The arguments to use for the reply method |
|ACKTimeout | `int` | The time to wait for a received acknowledge (ACK). 0 for no acknowledge|
|retries | `int` | The number of times to retry if no ACK was received |
|replyACKTimeout | `int` | The timeout to wait for an ACK message before we retry |
|replyRetries | `int` | The number of times to retry if no ACK was received for repply messages |
|methodTimeout | `int` | The timeout in seconds for how long we wait for a method to complete |
|replyMethodTimeout | `int` | The timeout in seconds for how long we wait for a method to complete for repply messages |
|directory | `string` | The directory for where to store the data of the repply message |
|fileName | `string` | The name of the file for where we store the data of the reply message |
|schedule | [int type value for interval in seconds, int type value for total run time in seconds] | Schedule a message to re run at interval |
2021-03-11 16:14:43 +00:00
2024-11-16 17:09:36 +00:00
### Request Methods
2021-03-11 16:14:43 +00:00
2024-11-16 17:09:36 +00:00
| Method name| Description|
|------------|------------|
|REQOpProcessList | Get a list of the running processes|
|REQOpProcessStart | Start up a process|
|REQOpProcessStop | Stop a process|
|REQCliCommand | Will run the command given, and return the stdout output of the command when the command is done|
|REQCliCommandCont | Will run the command given, and return the stdout output of the command continously while the command runs|
|REQTailFile | Tail log files on some node, and get the result for each new line read sent back in a reply message|
|REQHttpGet | Scrape web url, and get the html sent back in a reply message|
|REQHello | Send Hello messages|
|REQCopySrc| Copy a file from one node to another node|
|REQErrorLog | Method for receiving error logs for Central error logger|
|REQNone | Don't send a reply message|
|REQToConsole | Print to stdout or stderr|
|REQToFileAppend | Append to file, can also write to unix sockets|
|REQToFile | Write to file, can also write to unix sockets|
2021-03-11 16:14:43 +00:00
## History
2022-06-22 06:59:03 +00:00
ctrl is the continuation of the code I earlier wrote for RaaLabs called Steward. The original repo was public with a MIT license, but in October 2023 the original repo was made private, and are no longer avaialable to the public. The goal of this repo is to provide an actively maintained, reliable and stable version. This is also a playground for myself to test out ideas an features for such a service as described earlier.
2022-06-03 13:17:25 +00:00
This started out as an idea I had for how to control infrastructure. This is the continuation of the same idea, and a project I'm working on free of charge in my own spare time, so please be gentle :)
NB: Filing of issues and bug fixes are highly appreciated. Feature requests will genereally not be followed up simply because I don't have the time to review it at this time :
2024-11-16 17:09:36 +00:00
Steward was written with an MIT License. With the new fork the service was renamed to ctrl and the license were changed to AGPL V3.0. More information in the [LICENSE-CHANGE.md](LICENSE-CHANGE.md) and [LICENSE](LICENSE) files.
## Disclaimer
All code in this repository are to be concidered not-production-ready, and the use is at your own responsibility and risk. The code are the attempt to concretize the idea of a purely async management system where the controlling unit is decoupled from the receiving unit, and that that we know the state of all the receiving units at all times.
Also read the license file for further details.
Expect the main branch to have breaking changes. If stability is needed, use the released packages, and read the release notes where changes will be explained.