The state directory must now be owned by the bridge's effective uid. A directory owned by anyone else is refused with StateDirectoryError before any file is created or opened, and is left exactly as found, even when its mode is already 0700. Mode enforcement (exactly 0700) is unchanged and runs after the ownership check. Tests: the real /root as an unprivileged user; a deterministic injected-uid case proving no database/WAL/SHM is created and the directory is not mutated; a foreign-owned loose-mode directory left unmodified; a user- namespace fixture using the unmodified production path. Checks: typecheck clean; npm test 198 passed; client build ok; test:real-stt 11 passed; test:real-hermes 9 passed; test:simulator 6 passed; git diff --check clean. Not reviewed. No physical-device, droplet or production evidence. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
108 lines
5.7 KiB
Markdown
108 lines
5.7 KiB
Markdown
# Running the bridge on a DigitalOcean droplet
|
|
|
|
**Status: written, not run.** These steps have not been executed on a droplet. The bridge, the
|
|
built-in speech model and the Hermes adapter have only been run on the development desktop.
|
|
Creating the droplet, pointing DNS at it and starting services are Dan's actions.
|
|
|
|
## What runs where
|
|
|
|
```
|
|
phone (Even app) --HTTPS--> Caddy :443 --> bridge 127.0.0.1:8787 --> Hermes 127.0.0.1:8642
|
|
|
|
|
built-in Whisper (in the bridge process)
|
|
```
|
|
|
|
The bridge listens on loopback only. Caddy is the only thing exposed, and it provides the
|
|
certificate. Speech is transcribed inside the bridge, so recordings never leave the droplet.
|
|
|
|
Hermes can run on the same droplet (shown above) or elsewhere; if elsewhere, `HERMES_BASE_URL`
|
|
must be `https://`.
|
|
|
|
## Sizing
|
|
|
|
Measured on the development desktop (Intel i7-13850HX), bridge with `whisper-base`, 8-bit
|
|
weights:
|
|
|
|
| Measurement | Value |
|
|
|---|---|
|
|
| Memory after loading the model | about 0.5 GB |
|
|
| Memory after transcribing | about 0.8 GB |
|
|
| 11 s of speech, process pinned to one core | about 1.7 s |
|
|
| Same, `whisper-tiny` | about 1.2 s, about 0.6 GB |
|
|
| Model download at deploy time (`fetch-model`) | 79 MB (`whisper-base`), 4 s on the desktop's connection |
|
|
| Longest pause of the bridge's event loop while transcribing | 3 ms (the model runs in a worker thread) |
|
|
|
|
Pinning to one core made no difference to speed, so extra cores will not help; a single droplet
|
|
vCPU is the relevant unit. **A shared droplet vCPU is slower than that desktop core by an amount
|
|
that has not been measured.** If it were three times slower, 11 s of speech would take about 5 s,
|
|
well inside the 30 s deadline.
|
|
|
|
Suggested starting point, to be confirmed by measuring on the droplet: **2 GB RAM, 1 to 2 vCPU**
|
|
for the bridge alone. 1 GB is likely too tight alongside the OS. If Hermes shares the droplet,
|
|
add whatever Hermes needs; that was not measured.
|
|
|
|
If transcription is too slow on the droplet, set `STT_MODEL=whisper-tiny` (faster, less
|
|
accurate) and run `fetch-model` again.
|
|
|
|
## Steps
|
|
|
|
1. **Droplet and DNS.** Ubuntu LTS. Point a hostname at it (for example `bridge.example.com`).
|
|
Firewall: allow 22, 80 and 443 only.
|
|
2. **Packages.** Node.js 22.13 or later, git, Caddy.
|
|
3. **User and directories.**
|
|
```sh
|
|
useradd --system --home /opt/hermeven --shell /usr/sbin/nologin hermeven
|
|
mkdir -p /opt/hermeven /etc/hermeven
|
|
# The state directory is the service user's alone: mode 0700, set explicitly.
|
|
install -d -m 0700 -o hermeven -g hermeven /var/lib/hermeven
|
|
```
|
|
The bridge also enforces this itself at every start. The directory that holds the database
|
|
must be owned by the user the bridge runs as: if it belongs to anyone else (including root)
|
|
the bridge refuses to start and leaves the directory exactly as it found it, even if its
|
|
mode is already 0700. If the owner is right but the mode is looser, the bridge sets it to
|
|
0700. So `-o hermeven` in the command above matters as much as `-m 0700`.
|
|
4. **Code.** Clone the repository into `/opt/hermeven`, then `npm ci`. (The dev dependencies are
|
|
needed: the bridge runs through `tsx`.)
|
|
5. **Configuration.** Copy `deploy/bridge.env.example` to `/etc/hermeven/bridge.env`, fill it
|
|
in, `chmod 600`, `chown hermeven`.
|
|
5a. **Speech model.** As root (not the service user), fetch and verify the pinned model into a
|
|
directory the service can read but not write:
|
|
```sh
|
|
HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env npm --prefix /opt/hermeven run bridge:cli -- fetch-model
|
|
HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env npm --prefix /opt/hermeven run bridge:cli -- verify-model
|
|
```
|
|
Every file is checked against the SHA-256 committed in `services/bridge/models/`. The running
|
|
service never downloads anything: it re-verifies these files each time it loads the model and
|
|
refuses to load if one is missing or different. This is the only step that needs outbound
|
|
access to huggingface.co.
|
|
6. **Hermes.** Enable its API server with a key, bound to `127.0.0.1`. Use a read-only or test
|
|
profile first.
|
|
7. **Service.** Copy `deploy/hermeven-bridge.service` to `/etc/systemd/system/`, then
|
|
`systemctl daemon-reload && systemctl enable --now hermeven-bridge`. Watch
|
|
`journalctl -u hermeven-bridge -f` for `stt.ready`. `stt.load_failed` with `reason: missing`
|
|
or `mismatch` means step 5a was skipped or the files changed.
|
|
8. **TLS.** Put `deploy/Caddyfile.example` at `/etc/caddy/Caddyfile` with your hostname, reload
|
|
Caddy, then check `curl https://bridge.example.com/healthz`.
|
|
9. **App build.** On your own machine:
|
|
`HERMEVEN_BRIDGE_ORIGIN=https://bridge.example.com npm run -w @hermeven/even-client pack`.
|
|
10. **Pair.** On the droplet, as the service user with the same environment:
|
|
```sh
|
|
sudo -u hermeven HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env npm --prefix /opt/hermeven run bridge:cli -- pair
|
|
```
|
|
11. **Origin.** Open the phone page, read Diagnostics, "Page origin", put it in
|
|
`HERMEVEN_ALLOWED_ORIGINS`, restart the service.
|
|
|
|
## Things to check on the droplet and write down
|
|
|
|
- Time from `stt.loading` to `stt.ready`, and memory of the service after a few questions.
|
|
- `transcribe_ms` for a few real questions (the phone page shows it per question).
|
|
- That `curl http://<droplet-ip>:8787/healthz` from outside **fails** (bridge not exposed).
|
|
- `stat -c '%a' /var/lib/hermeven /var/lib/hermeven/hermeven.sqlite*` shows `700` and `600`.
|
|
- That the unit's hardening options do not stop the model loading. `ProtectSystem=strict` and
|
|
`MemoryMax` in particular are untested with ONNX Runtime.
|
|
|
|
## Not covered yet
|
|
|
|
Backups of `/var/lib/hermeven`, log rotation, upgrades, monitoring, and a compiled build that
|
|
would remove the need for dev dependencies on the droplet.
|