From 7709438aabee630759913b3ad3fd3e612aff5684 Mon Sep 17 00:00:00 2001 From: Herwin Bozet Date: Sun, 15 Nov 2026 01:21:29 +0100 Subject: [PATCH] Added the test lab guide, Stopped logging clients closing without close_notify docs/lab.md: a lab of two servers replicating each other and three clients, step by step: the certificates, the configs, what to try (replication, attachments, queries, refusals, catching up, revocation, Python, Docker), each command run as written. The server took a client leaving without TLS's close_notify (every tool command, the DLL, a killed process) for an error and logged it at INFO on every connection: it's a normal close now. Co-Authored-By: Claude Opus 5.5 --- crates/bakashrot-server/src/connection.rs | 5 + docs/lab.md | 207 ++++++++++++++++++++++ docs/server.md | 2 + readme.md | 2 +- 4 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 docs/lab.md diff --git a/crates/bakashrot-server/src/connection.rs b/crates/bakashrot-server/src/connection.rs index 9855773..fbfd823 100644 --- a/crates/bakashrot-server/src/connection.rs +++ b/crates/bakashrot-server/src/connection.rs @@ -71,6 +71,11 @@ async fn serve(shared: &Arc, tcp: TcpStream, address: IpAddr) -> Result< let bytes = match timeout(IDLE_TIMEOUT, frames.next()).await { Err(_) => return Err(format!("{}: idle too long", peer.node)), Ok(None) => return Ok(peer.node), + // Closed without TLS's close_notify: how the tools, the DLL and + // a killed process leave (a request cut short isn't run). + Ok(Some(Err(error))) if error.kind() == std::io::ErrorKind::UnexpectedEof => { + return Ok(peer.node); + } Ok(Some(bytes)) => bytes.map_err(|error| format!("{}: {error}", peer.node))?, }; let revoked = shared diff --git a/docs/lab.md b/docs/lab.md new file mode 100644 index 0000000..3056294 --- /dev/null +++ b/docs/lab.md @@ -0,0 +1,207 @@ +# A test lab, step by step + +Two servers replicating each other, a client pushing to one, another +reading from the other. Every command here was run as written (on one +machine, 2026-11-15, Windows): the outputs shown are what came back. + +Get a release (CI's artifacts, or `release.ps1` / `python release.py`): +the programs, `bakashrot.dll` / `libbakashrot.so`, the wheel, the +example configs. The certificates are throwaway for now: the identity +OID is a placeholder until NibblePoker's PEN (`oid.md`), every tool run +says so. Reissue them all once it changes. + +| Machine | What runs there | Files it gets | +|---|---|---| +| admin (any) | `bakashrot-cert` | `ca.key` stays here, never copied | +| server-1 | `bakashrot-server` | `ca.crt`, `server-1.crt`, `server-1.key`, `server.toml` | +| server-2 | `bakashrot-server` | `ca.crt`, `server-2.crt`, `server-2.key`, `server.toml` | +| kitchen | `bakashrot` (pushes to server-1) | `ca.crt`, `kitchen.crt`, `kitchen.key`, `client.toml` | +| dashboard | `bakashrot` (reads from server-2) | `ca.crt`, `dashboard.crt`, `dashboard.key`, `client.toml` | +| any | Python, pushes and reads | `ca.crt`, `lab-py.crt`, `lab-py.key`, `client.toml` | + +Below, `server-1.lab` and `server-2.lab` are the servers' addresses: put +their hostnames or IPs. The clients can be on the servers' machines. + +## 1. The certificates (admin) + +``` +bakashrot-cert ca --name "Lab CA" +bakashrot-cert issue --name server-1 --role peer --server +bakashrot-cert issue --name server-2 --role peer --server +bakashrot-cert issue --name kitchen --role sensor +bakashrot-cert issue --name dashboard --role dashboard +bakashrot-cert issue --name lab-py --role sensor --role dashboard +``` + +A certificate is its name (the node) and its roles; the servers' configs +say what each role may do. `--server` makes a server's certificate; with +the `peer` role, the other server's config lets it replicate. More +clients: one `issue` each, any name and roles (`--role a --role b`). + +## 2. The servers + +`server.toml` on server-1 (server-2's: swap `1` and `2`): + +```toml +[server] +listen = "0.0.0.0:7000" +ca = "ca.crt" +certificate = "server-1.crt" +key = "server-1.key" +crl = "ca.crl" # optional; a missing file is fine, it's watched +database = "bakashrot.sqlite" +topics = ["lab.temps", "lab.events"] + +[retention] +"*" = "7d" + +[replication] +push_to = ["server-2.lab:7000"] # dialed, sent to +accept_from = ["server-2.lab"] # taken from (its address as seen from here) + +[roles.sensor] +push_topics = ["lab.*"] + +[roles.dashboard] +read_topics = ["*"] +query = true + +[roles.peer] +send_topics = ["lab.*"] +accept_topics = ["lab.*"] +``` + +- `topics` are names, not patterns (`"lab.*"` there is refused, with its + line); the roles take patterns. +- Every setting, with its default: `server.example.toml` (`config.md`). +- Open the port: `New-NetFirewallRule -DisplayName BakaShrot -Direction + Inbound -Protocol TCP -LocalPort 7000 -Action Allow` on Windows, the + distribution's firewall on Linux. + +Start each one from its folder: `bakashrot-server server.toml`. Their logs: + +``` +INFO server-1 listening on 0.0.0.0:7000 +INFO server-2.lab:7000: linked to server-2 +``` + +The first to start says once that the other refused (`WARN ... +actively refused it`) and dials again every 10 s. Stop with Ctrl+C +(SIGTERM on Linux): what was answered is stored. Unattended: a systemd +unit (`server.md`, "Running"), NSSM on Windows, or Docker (below). + +## 3. The clients + +`client.toml` for kitchen (dashboard's: its own name, `server-2.lab`): + +```toml +server = "server-1.lab:7000" +ca = "ca.crt" +certificate = "kitchen.crt" +key = "kitchen.key" +``` + +`bakashrot` reads `client.toml` from the current folder (`-c` for +another). + +## 4. Things to try + +**Push on one server, read on the other.** On kitchen: + +``` +> bakashrot push lab.temps '{"celsius":21.5}' +Pushed as message #1 +> bakashrot push lab.events '{"with":"file"}' -a note.txt +Pushed as message #1, with an attachment of 6 bytes +``` + +(Quoted for bash and PowerShell 7.3+; cmd wants `"{\"celsius\":21.5}"`, +and Windows PowerShell 5.1 drops the inner quotes: there, `@file` reads +the message from a file, `-` from stdin.) A few seconds later (a check-in every 5 s), +on dashboard: + +``` +> bakashrot list +Topics (2): + lab.temps + lab.events +Nodes (1): + kitchen +> bakashrot messages lab.temps kitchen +1 {"celsius":21.5} +> bakashrot latest lab.events kitchen +Message lab.events:kitchen#1, pushed 2026-11-15T00:15:09.401Z +Attachment: 6 bytes +{"with":"file"} +> bakashrot attachment lab.events kitchen 1 got.txt +Saved 6 bytes as got.txt +> bakashrot query "SELECT topic, node, message_id, message_data ->> '$.celsius' AS c FROM messages" +{"columns":["topic","node","message_id","c"],"rows":[["lab.events","kitchen","1",null],["lab.temps","kitchen","1","21.5"]]} +``` + +**Refusals.** A topic not in the config: + +``` +> bakashrot push other "{}" +Refused by the server (UnknownName): unknown topic 'other' +``` + +A certificate whose roles aren't in the config +(`issue --name visitor --role guest`): + +``` +Failed to connect to server-1.lab:7000 (NotAllowed): none of visitor's roles (guest) is allowed on this server +``` + +**Catching up.** Stop server-2, push a few messages on kitchen (server-1 +takes them; it logs once that server-2 refused), start server-2: within +about 10 s every one is on dashboard, in order. + +**Revoking.** On admin, `bakashrot-cert revoke dashboard.crt` writes +`ca.crl`; copy it next to each server's `server.toml` (the `crl` above). +Within 5 s they reload it (`INFO ca.crl: reloaded, 1 revoked`), and the +certificate is refused, at its next connection or request: + +``` +Failed to connect to server-2.lab:7000 (AuthRejected): the server refused this client's certificate (CertificateRevoked) +``` + +**Python.** `pip install bakashrot-0.2.0-py3-none-.whl` (from the +release's `python/`), then, next to lab-py's `client.toml` (it may push and +read: `sensor` and `dashboard`): + +```python +import bakashrot + +with bakashrot.Client.from_file("client.toml") as client: + client.connect() + print(client.push({"celsius": 20.5}, "lab.temps")) # its id: 1 + print(client.latest("lab.temps", client.node)) # Message(id=1, topic='lab.temps', node='lab-py', ...) + print(client.query("SELECT COUNT(*) AS n FROM messages")) # [{'n': '...'}]: query results are strings +``` + +The whole API: +`client.md`, "Python". + +**Also worth a look:** a node pushes to one server only (its messages +reach the others by replication: pushing the same node to both makes +diverging ids, `known-issues.md`); `BAKASHROT_LOG=debug` for more logs; +the database is a plain SQLite file, the `messages` and `browse` views +are for looking into it (`storage.md`, "The query surface"). + +## Docker instead (Linux) + +The image `ghcr.io/aziascreations/bakashrot-server` (`server.md`, "In +Docker"; not run by hand yet, only CI's check). On a server's machine, +`docker/compose.yml` from the repository, and next to it `config/` with +`ca.crt`, the server's certificate and key and `server.toml` as above, +except: + +```toml +database = "/var/lib/bakashrot/bakashrot.sqlite" +``` + +The server runs as uid 10001, which must read its key: +`sudo chown 10001:10001 config/server-1.key`. Then `docker compose up -d`, +`docker compose logs -f`, `docker compose down` (a clean stop; the +database stays in its volume). diff --git a/docs/server.md b/docs/server.md index 476b4c0..73a932e 100644 --- a/docs/server.md +++ b/docs/server.md @@ -160,6 +160,8 @@ the same ids with different messages, undetected. closes; otherwise `Welcome` (the server's name, the client's node). 4. **Requests**, one at a time. Before each, the certificate is checked against the current CRL: revoked since, the connection is dropped. + A client closing without TLS's close_notify (the tools, the DLL, a + killed process) is a normal close, not logged. | Timeout | | |---|---| diff --git a/readme.md b/readme.md index 2b32095..734576d 100644 --- a/readme.md +++ b/readme.md @@ -49,7 +49,7 @@ rust-toolchain.toml the pinned toolchain (1.100.0) build.ps1, test.ps1, release.ps1, clean.ps1 release.py a release for this platform: build, package, smoke test docs/ designs across crates: protocol.md, certificates.md, oid.md, config.md, - storage.md, server.md, client.md, known-issues.md + storage.md, server.md, client.md, known-issues.md, lab.md (a test lab, step by step) crates/ bakashrot-proto/ packets, frames, names, limits, error codes, shared by everything bakashrot-pki/ certificates: issuing, identities, CRLs, the TLS setup