[relay] F23: quotas (507), a NixOS module behind Caddy with TLS and no logs, and a VM test that no address is kept
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
# F23 — The relay on a home server: quotas, a NixOS module, TLS
|
||||
|
||||
Analysis, 2026-11-16. Issues T#8 (deploy) and Amicitia #51. The container image of T#8 is left for later: the NixOS module is what the home server runs. It builds on F20 (the relay) and
|
||||
`relay.md` §3–4, which put two things before any relay that faces the internet: **quotas**, and a
|
||||
**reverse proxy that logs no IP address**.
|
||||
|
||||
## 1. Why and what
|
||||
Two people on two machines can only chat through a relay both can reach. Mark's home server is the
|
||||
first one. After F23:
|
||||
- the relay refuses to fill its disk: per-mailbox and relay-wide caps, answered with a bare **507**;
|
||||
- `deploy/nixos/module.nix` runs it on NixOS, listening on loopback only, behind **Caddy** with TLS
|
||||
from Let's Encrypt, and **no access log, no error log with an address in it**;
|
||||
- a NixOS VM test boots that configuration, sends requests through the proxy from a known address,
|
||||
and fails if that address appears anywhere in the journal or under `/var/log`;
|
||||
- Amicitia accepts an `https://` relay address (its own PR).
|
||||
|
||||
## 2. Design
|
||||
```mermaid
|
||||
flowchart LR
|
||||
A[app] -->|TLS 443| C[Caddy: TLS, no logs]
|
||||
C -->|HTTP 127.0.0.1:8470| R[tabellarius-relay: systemd, DynamicUser, loopback only]
|
||||
R --> D[(SQLite: PROTOCOL.md section 5)]
|
||||
```
|
||||
### Quotas *(protocol change, §8: a new status)*
|
||||
| Limit | Default | Set by |
|
||||
|:--|:--|:--|
|
||||
| waiting blobs in one mailbox | 1 000 | the protocol |
|
||||
| waiting bytes in one mailbox | 32 MiB | the protocol |
|
||||
| waiting bytes on the relay | 1 GiB | `--max-bytes` |
|
||||
| mailboxes on the relay | 100 000 | `--max-mailboxes` |
|
||||
| unclaimed invites on the relay | 10 000 | `--max-invites` |
|
||||
|
||||
- Over a limit, the relay answers **507 Insufficient Storage**, bare, like every refusal. The
|
||||
per-mailbox caps are checked **after** the post token, so 507 tells nothing to someone without
|
||||
the token. The relay-wide caps say only that the relay is full.
|
||||
- **No identity is needed to count**: nothing new is stored; the counts come from §5's own columns
|
||||
(`size`, the rows). No IP address is kept, not even in memory: rate limits by address would need
|
||||
one. A flood can fill the relay up to its caps; then it refuses, and the operator sees it.
|
||||
- The client already handles it: 507 is a failure, so the message waits in the outbox.
|
||||
- **Mailboxes are never deleted yet** (`relay.md` §4): an abandoned mailbox counts against the
|
||||
100 000 until a protocol version can delete one. Stated.
|
||||
|
||||
### The NixOS module (`deploy/nixos/module.nix`)
|
||||
- `services.tabellarius.enable`, `.domain`, `.maxBytes`, `.maxMailboxes`, `.maxInvites`, `.package`
|
||||
(the flake's own build).
|
||||
- **The relay:** a systemd service with `DynamicUser`, `StateDirectory=tabellarius` (the database),
|
||||
`--listen 127.0.0.1:8470`. Hardened: `ProtectSystem=strict`, `ProtectHome`, `PrivateTmp`,
|
||||
`PrivateDevices`, `NoNewPrivileges`, `MemoryDenyWriteExecute`, `RestrictAddressFamilies=AF_INET
|
||||
AF_INET6`, `SystemCallFilter=@system-service`, and **`IPAddressDeny=any` with
|
||||
`IPAddressAllow=localhost`**: even a bug cannot make it talk to anything but the proxy.
|
||||
- **The proxy:** `services.caddy`, one virtual host, `reverse_proxy 127.0.0.1:8470`. The NixOS
|
||||
module writes an access log per host by default; the host's `logFormat` is set to
|
||||
`output discard`, and Caddy's default logger too. Caddy's own TLS-handshake and proxy errors can
|
||||
name a client address, so no log is the rule; an operator who needs one turns it on and knows
|
||||
why. Headers: none added.
|
||||
- **journald:** the relay prints one line at start. Nothing per request.
|
||||
|
||||
### The VM test (`deploy/nixos/test.nix`, `nix flake check`)
|
||||
Two machines: `server` with the module (TLS from Caddy's internal CA instead of Let's Encrypt), and
|
||||
`client` at a fixed address. The client creates a mailbox, posts, fetches, acknowledges, makes a
|
||||
mistake (a wrong token, a malformed request), and fills a mailbox to its 507. Then the test greps
|
||||
the server's whole journal and `/var/log` for the client's address and fails if it appears.
|
||||
|
||||
**Not run here.** This machine has neither Nix nor WSL. The module and the test are written to be
|
||||
run with `nix flake check` on Linux, and the PR says so. Mark's server is the first real run.
|
||||
|
||||
## 3. Risks
|
||||
- **Privacy:** the logs are the risk this feature exists to close. The VM test is its proof, once
|
||||
it runs. The network layer (a router, the ISP) still sees addresses and timing (§1).
|
||||
- **Abuse:** caps bound the disk; they do not stop someone from filling them. Proof of work or
|
||||
invite-only mailbox creation is for a later protocol version.
|
||||
- **Reproducibility:** the module uses the flake's package, so the relay that runs is the one built
|
||||
from this commit (`docs/VERIFY.md`).
|
||||
|
||||
## 4. Tests — written first
|
||||
1. Each cap: the post or create that would cross it gets 507; one under it succeeds; after an
|
||||
acknowledgement (or a purge) there is room again.
|
||||
2. The per-mailbox cap answers 404, not 507, to a wrong token.
|
||||
3. The CLI reads `--max-bytes`, `--max-mailboxes`, `--max-invites`; a bad value is refused.
|
||||
4. The VM test (§2), on Linux.
|
||||
|
||||
Planted bugs: the mailbox cap checked before the token; an acknowledgement not freeing space; the
|
||||
global byte cap ignored; the invite cap counting claimed invites; the CLI option ignored.
|
||||
Reference in New Issue
Block a user