mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Added basic setup guides
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
# 1. Certificates
|
||||
|
||||
[Index](readme.md) · Next: [Server](2-server.md)
|
||||
|
||||
Every `bakashrot-cert` command prints this warning, ignore it for tests:
|
||||
```
|
||||
warning: the identity extension's OID is still a placeholder (docs/oid.md): fine for tests, not for certificates in use
|
||||
```
|
||||
|
||||
More options: `bakashrot-cert.exe <command> --help`.
|
||||
|
||||
|
||||
## The root certificate
|
||||
|
||||
```shell
|
||||
bakashrot-cert.exe ca --name bakashrot-test
|
||||
```
|
||||
|
||||
Resulting files:
|
||||
* `ca.crt` - Must be copied to each server and client.
|
||||
* `ca.key` - Stays on this machine, it can make any certificate.
|
||||
|
||||
|
||||
## A server certificate
|
||||
|
||||
```shell
|
||||
bakashrot-cert.exe issue --server --name server-lan1
|
||||
Wrote .\server-lan1.crt
|
||||
Wrote .\server-lan1.key
|
||||
```
|
||||
|
||||
Depending on how you set up replications, you may have to add a role with `--role <ROLE_NAME>`. \
|
||||
See [???]().
|
||||
|
||||
|
||||
## Node certificates
|
||||
|
||||
```shell
|
||||
bakashrot-cert.exe issue --name node-sensor --role sensor
|
||||
Wrote .\node-sensor.crt
|
||||
Wrote .\node-sensor.key
|
||||
|
||||
bakashrot-cert.exe issue --name node-viewer --role viewer
|
||||
Wrote .\node-viewer.crt
|
||||
Wrote .\node-viewer.key
|
||||
```
|
||||
|
||||
* The name is the node its messages are pushed as.
|
||||
* Roles mean nothing until the server's config says what they may do ([Server](2-server.md)).
|
||||
* Several roles: `--role sensor --role viewer`.
|
||||
|
||||
|
||||
## Checking one
|
||||
|
||||
```shell
|
||||
bakashrot-cert.exe show node-sensor.crt
|
||||
node-sensor.crt
|
||||
name: node-sensor
|
||||
roles: sensor
|
||||
usage: client
|
||||
issuer: bakashrot-test
|
||||
valid: Nov 15 11:35:45 2026 +00:00 to Nov 15 11:35:45 2027 +00:00
|
||||
serial: 588a92f0c5b39bc557f463f0ef50c278a2f9df50
|
||||
```
|
||||
|
||||
|
||||
## Revoking one
|
||||
|
||||
```shell
|
||||
bakashrot-cert.exe revoke node-sensor.crt
|
||||
```
|
||||
|
||||
* Writes `ca.crl` (every certificate revoked so far).
|
||||
* Copy it next to the server's `server.toml` and add `crl = "ca.crl"` under `[server]`.
|
||||
* The server reloads it within 5 s; that certificate is refused from its next request.
|
||||
@@ -0,0 +1,145 @@
|
||||
# 2. Server
|
||||
|
||||
[Index](readme.md) · Previous: [Certificates](1-certificates.md) · Next: [Client](3-client.md)
|
||||
|
||||
## Pre-requisites
|
||||
* The certificate authority's `.crt` file.
|
||||
* The server's `.crt` file.
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Configuring it
|
||||
The server's config is typically kept in `server.toml`, next the `.crt` files. \
|
||||
Create a blank one and all the following sections.
|
||||
|
||||
### Server's base config
|
||||
```toml
|
||||
# All paths are relative to CWD unless they're absolute.
|
||||
[server]
|
||||
listen = "0.0.0.0:7000" # Used when binding.
|
||||
|
||||
ca = "ca.crt"
|
||||
certificate = "server-1.crt"
|
||||
key = "server-1.key"
|
||||
|
||||
# The watched CA's CRL.
|
||||
# The CRL checks will be disabled if not given, the program will exit if given and non-existent.
|
||||
#crl = "ca.crl"
|
||||
|
||||
database = "bakashrot.sqlite"
|
||||
|
||||
# "full": every push flushed to disk before it's answered, it survives a
|
||||
# power loss. "normal": about twice the pushes, a power loss loses the last
|
||||
# second or so. ("off" isn't allowed.)
|
||||
synchronous = "full"
|
||||
|
||||
max_attachment_size = "1G" # bytes, or K M G T (1024-based); 0: none
|
||||
retention_interval = "1m" # how often old messages are deleted
|
||||
```
|
||||
|
||||
|
||||
### Replication
|
||||
```toml
|
||||
# Who this server replicates with, by address.
|
||||
# A link carries messages one way: the server that dials sends, the one dialed takes them.
|
||||
[replication]
|
||||
push_to = [] # Servers we'll actively connect to.
|
||||
# Example: ["10.0.0.2:7000", "server-2.lan:7000"]
|
||||
|
||||
accept_from = [] # Connecting servers must have these origins, otherwise we abort.µ
|
||||
# Example: ["10.0.0.2", "server-2.lan"], or ["*"]
|
||||
|
||||
retry_delay = "10s"
|
||||
sync_interval = "5s"
|
||||
batch_size = 1000 # messages per packet, 1-10000
|
||||
```
|
||||
|
||||
|
||||
### Roles section
|
||||
```toml
|
||||
[roles.sensor]
|
||||
push_topics = ["sensors.*"] # always as its own node (its name)
|
||||
read_topics = ["*"]
|
||||
query = true # read-only SQL, reads every topic
|
||||
|
||||
# Listing: by default, only the topics it may push to or read,
|
||||
# and only the nodes of the topics it may read.
|
||||
list_topics = false # true: lists every topic (query does too)
|
||||
list_nodes = false # true: lists every node (query does too)
|
||||
|
||||
# Only relevant when replicating.
|
||||
send_nodes = ["*"] # Replicates all known topics (Default)
|
||||
accept_nodes = ["*"] # Accepts al foreign topics (Default)
|
||||
```
|
||||
|
||||
#### Remarks:
|
||||
* Any node/certificate without any known role is refused.
|
||||
|
||||
#### Examples:
|
||||
> **Sensor:**
|
||||
> ```toml
|
||||
> [roles.sensor]
|
||||
> push_topics = ["sensors.*"]
|
||||
> read_topics = []
|
||||
> ```
|
||||
|
||||
> **Log Processor:**
|
||||
> ```toml
|
||||
> [roles.sensor]
|
||||
> push_topics = ["alerts.sensors.*"]
|
||||
> read_topics = ["sensors.*"]
|
||||
> ```
|
||||
|
||||
> **Explorer:** (sees every name, reads nothing)
|
||||
> ```toml
|
||||
> [roles.explorer]
|
||||
> list_topics = true
|
||||
> list_nodes = true
|
||||
> ```
|
||||
|
||||
> **Admin:** (everything a client can do, on every topic)
|
||||
> ```toml
|
||||
> [roles.admin]
|
||||
> push_topics = ["*"]
|
||||
> read_topics = ["*"]
|
||||
> query = true
|
||||
> list_topics = true
|
||||
> list_nodes = true
|
||||
> ```
|
||||
> Its certificate: `bakashrot-cert.exe issue --name node-admin --role admin`
|
||||
|
||||
|
||||
### Retention
|
||||
```toml
|
||||
# How long each topic's messages are kept, from when they were first pushed.
|
||||
# Any topic not present here will be kept forever.
|
||||
[retention]
|
||||
logs = "30d"
|
||||
"sensors.*" = "12h"
|
||||
"*" = "forever" # Implied
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Opening the port
|
||||
|
||||
Admin PowerShell:
|
||||
```powershell
|
||||
New-NetFirewallRule -DisplayName BakaShrot -Direction Inbound -Protocol TCP -LocalPort 7000 -Action Allow
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Starting it
|
||||
|
||||
```shell
|
||||
bakashrot-server.exe server.toml
|
||||
2026-11-15T11:35:51.404202Z INFO server-lan1 listening on 0.0.0.0:7000
|
||||
```
|
||||
|
||||
* Creates `bakashrot.sqlite` on first start.
|
||||
* Stop with Ctrl+C: what was accepted is saved.
|
||||
* More logs: `set BAKASHROT_LOG=debug` before starting it.
|
||||
@@ -0,0 +1,23 @@
|
||||
# 3. Client
|
||||
|
||||
[Index](readme.md) · Previous: [Server](2-server.md) · Next: [Pushing](4-pushing.md)
|
||||
|
||||
`client.toml`, next to `ca.crt`, `node-sensor.crt` and `node-sensor.key`:
|
||||
```toml
|
||||
server = "192.168.1.10:7000"
|
||||
ca = "ca.crt"
|
||||
certificate = "node-sensor.crt"
|
||||
key = "node-sensor.key"
|
||||
```
|
||||
|
||||
`viewer.toml`, the same with the viewer's certificate:
|
||||
```toml
|
||||
server = "192.168.1.10:7000"
|
||||
ca = "ca.crt"
|
||||
certificate = "node-viewer.crt"
|
||||
key = "node-viewer.key"
|
||||
```
|
||||
|
||||
* `server`: the server's IP or hostname, and its `listen` port.
|
||||
* `bakashrot.exe` reads `client.toml` from the current folder, `-c viewer.toml` for another one.
|
||||
* Optional: `crl = "ca.crl"`, to refuse a revoked server.
|
||||
@@ -0,0 +1,31 @@
|
||||
# 4. Pushing
|
||||
|
||||
[Index](readme.md) · Previous: [Client](3-client.md) · Next: [Reading](5-reading.md)
|
||||
|
||||
As `node-sensor` (`client.toml`).
|
||||
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot push sensors "{\"celsius\":21.5}"
|
||||
Pushed as message #1
|
||||
|
||||
E:\BakaShrot>bakashrot push sensors @reading.json -a photo.jpg
|
||||
Pushed as message #2, with an attachment of 245 bytes
|
||||
```
|
||||
|
||||
* Always pushed as the certificate's node (`node-sensor`).
|
||||
* `@file` reads the message from a file, `-` from stdin.
|
||||
* `-a`: one attachment per message.
|
||||
|
||||
|
||||
## Refused
|
||||
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot push other "{}"
|
||||
Refused by the server (NotAllowed): node-sensor may not push to 'other'
|
||||
|
||||
E:\BakaShrot>bakashrot messages sensors node-sensor
|
||||
Refused by the server (NotAllowed): node-sensor may not read 'sensors'
|
||||
```
|
||||
|
||||
* `other` isn't in the `sensor` role's `push_topics`.
|
||||
* The `sensor` role has no `read_topics`: reading is the viewer's ([Reading](5-reading.md)).
|
||||
@@ -0,0 +1,61 @@
|
||||
# 5. Reading
|
||||
|
||||
[Index](readme.md) · Previous: [Pushing](4-pushing.md)
|
||||
|
||||
As `node-viewer` (`-c viewer.toml`).
|
||||
|
||||
|
||||
## Topics and nodes
|
||||
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot -c viewer.toml list
|
||||
Topics (1):
|
||||
sensors
|
||||
Nodes (1):
|
||||
node-sensor
|
||||
```
|
||||
|
||||
|
||||
## A node's messages in a topic
|
||||
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot -c viewer.toml messages sensors node-sensor
|
||||
1 {"celsius":21.5}
|
||||
2 {"celsius":22}
|
||||
```
|
||||
|
||||
* One per line: id, tab, data.
|
||||
* The node is a name, not a pattern: `*` fails with `'*' isn't a node name`.
|
||||
* `-f` keeps waiting for new ones, `-t` adds the time, `--after <id>` skips the first ones.
|
||||
|
||||
|
||||
## The latest one, with its attachment
|
||||
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot -c viewer.toml latest sensors node-sensor
|
||||
Message sensors:node-sensor#2, pushed 2026-11-15T11:35:53.484Z
|
||||
Attachment: 245 bytes
|
||||
{"celsius":22}
|
||||
|
||||
E:\BakaShrot>bakashrot -c viewer.toml attachment sensors node-sensor 2 photo.jpg
|
||||
Saved 245 bytes as photo.jpg
|
||||
```
|
||||
|
||||
|
||||
## SQL
|
||||
|
||||
Read-only, every topic, needs `query = true` in the role:
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot -c viewer.toml query "SELECT node, message_id, message_data ->> '$.celsius' AS c FROM messages"
|
||||
{"columns":["node","message_id","c"],"rows":[["node-sensor","1","21.5"],["node-sensor","2","22"]]}
|
||||
```
|
||||
|
||||
|
||||
## Refused
|
||||
|
||||
```shell
|
||||
E:\BakaShrot>bakashrot -c viewer.toml push sensors "{}"
|
||||
Refused by the server (NotAllowed): node-viewer may not push to 'sensors'
|
||||
```
|
||||
|
||||
* The `viewer` role has no `push_topics`.
|
||||
@@ -0,0 +1,26 @@
|
||||
# BakaShrot - Guides
|
||||
|
||||
One server, one client that pushes (`node-sensor`), one that reads (`node-viewer`).
|
||||
Commands are for `cmd`, run from the release's folder (`E:\BakaShrot`).
|
||||
|
||||
| Step | Guide | Result |
|
||||
|------|-----------------------------------|--------------------------------------------------------------|
|
||||
| 1 | [Certificates](1-certificates.md) | A CA, the server's and the nodes' certificates; revoking one |
|
||||
| 2 | [Server](2-server.md) | `server.toml`, the port opened, the server running |
|
||||
| 3 | [Client](3-client.md) | `client.toml` for each node |
|
||||
| 4 | [Pushing](4-pushing.md) | Messages and attachments stored |
|
||||
| 5 | [Reading](5-reading.md) | Messages listed, read, queried |
|
||||
|
||||
Who gets which files:
|
||||
|
||||
| Machine | Files |
|
||||
|---------|---------------------------------------------------------------------------------------|
|
||||
| admin | `bakashrot-cert.exe`, `ca.crt`, `ca.key` (never copied) |
|
||||
| server | `bakashrot-server.exe`, `ca.crt`, `server-lan1.crt`, `server-lan1.key`, `server.toml` |
|
||||
| sensor | `bakashrot.exe`, `ca.crt`, `node-sensor.crt`, `node-sensor.key`, `client.toml` |
|
||||
| viewer | `bakashrot.exe`, `ca.crt`, `node-viewer.crt`, `node-viewer.key`, `viewer.toml` |
|
||||
|
||||
More:
|
||||
* `bakashrot <command> --help`, `bakashrot-cert <command> --help`.
|
||||
* Two replicating servers, Python, Docker: `docs/lab.md`.
|
||||
* Every setting: `docs/config.md`.
|
||||
Reference in New Issue
Block a user