Security design and speed design
3. Security design (defence in depth)
Section titled “3. Security design (defence in depth)”The first defence is that the server cannot be found. The next ones assume it was found anyway.
| Layer | What it does | Setup |
|---|---|---|
| 1. No public address in use | The only public names are app.bideward.com and api.bideward.com, which resolve to Cloudflare. The server’s own IP is never put in DNS, in a document, in a webhook or in an e-mail. | Part D |
| 2. No inbound ports | Lightsail firewall: every inbound rule deleted (IPv4 and IPv6) after Tailscale works. ufw: deny incoming. The tunnel is outbound only. | Parts A, D |
| 3. Cloudflare rules | WAF custom rules and a rate limit stop junk before it reaches the tunnel. Bot ingestion paths without the X-Titan-Key header are blocked at the edge. | Part D |
| 4. Optional login gate | Cloudflare Access on /research* (and later /admin*) so even the login page is invisible without a Cloudflare sign-in. | Part D |
| 5. Application login | The existing sign-in: username, password and authenticator code, 12-hour session, 5 tries then 15-minute lock with Telegram alert, roles, owner actions behind the control password. | Unchanged |
| 6. Private services | The hub and the research service listen on 127.0.0.1 only. PostgreSQL has no network port; it uses a Unix socket with per-user permission. | Parts B, F |
| 7. Least privilege | Separate system users and database roles. The hub cannot change table structure; the research service cannot read the hub’s accounts. systemd sandboxing on every service. | Parts B, F |
| 8. Secrets | Env files readable by root only, mode 600. The tunnel token, database roles and keys never appear in a chat, a document or GitHub. | Part F |
| 9. Patching and recovery | Automatic security updates, daily snapshots, nightly dumps, an alert on any failure. | Parts A, J, K |
| 10. Reach in only through Tailscale | SSH works only over your private Tailscale network, with a key and no password. | Part A |
What an attacker who scans the internet sees: Cloudflare, nothing else. What an attacker who learns the server’s IP sees: a closed machine (every port filtered). What an attacker who gets one service sees: a limited user with no shell, no write access outside its folder, and only its own database role.
4. Speed design (security must not slow anything)
Section titled “4. Speed design (security must not slow anything)”- The tunnel is as fast as a normal Cloudflare proxy: the connection from the box to Cloudflare is already open, so a request costs no extra handshake. The Malaysia box serves Asian traffic closest.
- The hub keeps every hot key in memory and answers reads from memory. Writes go to PostgreSQL in the background, grouped every 250 ms into one transaction. A bet never waits for the database.
- PostgreSQL is reached by Unix socket: no TCP, no TLS, no password handshake per request, so it is faster and safer.
- Non-critical keys use a relaxed commit (synchronous_commit = off) so the database never waits for the disk; money-related writes (bet records, take-profit and ruin events, state mirror) are committed with full durability.
- Memory budget on 2 GB (Part B.3): PostgreSQL about 600 MB, hub about 500 MB, research service about 150 MB, cloudflared about 40 MB, the system the rest, plus a 1 GB swap file as a safety net only.
- A health line in Part I measures the p50 and p99 time of /log-stats and of a bet gateway call with 3 bots and with a simulated 60-bot load. The target: p99 under 150 ms inside the box.
← Previous: What Frank decided (28–29 Nov 2026) · Guide index · Next: Words you will meet, and the values you will create →