# 04 · Public-Safe Operations & Deployment Runbook

> **SSOT Status**: Authoritative Specification  
> **Machine Source**: [`spec/fiderail.manifest.json`](../spec/fiderail.manifest.json) (`schemaVersion: 1.0.0`)  
> **Release**: `v2.3.5`

> This runbook is public-safe and never contains server IPs, SSH ports, private keys, or RPC/proxy tokens.

---

## 1. Production Topology

```text
Internet / AI Agents
   │
   ▼ HTTPS (Cloudflare Proxy · Full Strict TLS)
┌──────────────────────────────────────────────────────────┐
│ fiderail.com     (Trust Radar Web UI + Audit Report)     │
│ api.fiderail.com (REST / MCP HTTP / Well-Known Keys)     │
└──────────────┬───────────────────────────────────────────┘
               │ reverse_proxy (Caddy 2 · TLS :443 / :80)
               ▼
┌──────────────────────────────────────────────────────────┐
│ 127.0.0.1:8787 (fiderail-api.service, Node.js >= 22.13)  │
│        ▲                                                 │
│  [Primary]:  PostgreSQL 16 (127.0.0.1:5432, partitioned) │
│  [Dev / CI]: SQLite WAL (FIDERAIL_DB_PATH)               │
│        ▲                                                 │
│ fiderail-indexer.service (4-Chain Workers + Bazaar + L1) │
│        ▲ Daily compressed pg_dump (.timer)               │
│ /var/backups/fiderail/                                   │
└──────────────────────────────────────────────────────────┘
```

### Public Endpoints & Contacts
- **Web Portal**: `https://fiderail.com`
- **API & Streamable HTTP MCP**: `https://api.fiderail.com`
- **General Contact**: `founder@fiderail.com`
- **Security Contact**: `security@fiderail.com`

---

## 2. Host Baseline & Hardening (Debian 12)

- **Recommended Single-Node Baseline**: Debian 12 (bookworm), `>= 2 vCPU`, `8 GiB RAM`, `30+ GB NVMe`, non-privileged `fiderail` service user.
- **Directory Layout**:
  - `/opt/fiderail`: Application files (`fiderail:fiderail`)
  - `/var/lib/fiderail`: Runtime data (`fiderail:fiderail`)
  - `/var/backups/fiderail`: Automated daily backups (`fiderail:fiderail`)
  - `/etc/fiderail/fiderail.env`: Restricted environment config (`root:fiderail`, `chmod 640`)
- **PostgreSQL 16 Tuning Baseline** (8 GiB RAM single-node, bound strictly to `127.0.0.1:5432`):
  - `shared_buffers = 2GB`, `effective_cache_size = 5GB`, `work_mem = 16MB`, `maintenance_work_mem = 256MB`, `max_connections = 100`.
- **Network & Outbound Isolation**:
  - SSH key-only login + `fail2ban` + default-drop firewall restricting `:80`/`:443` to CDN edge CIDRs;
  - Outbound L1 / `/v1/diagnose` probing routed through an authenticated fail-closed proxy with strict private-DNS SSRF blocking.

---

## 3. Environment Configuration & Ed25519 State Root Signing

Configure `/etc/fiderail/fiderail.env` from [`deploy/fiderail.env.example`](../deploy/fiderail.env.example):

- **Database**: Set `DATABASE_URL` to use PostgreSQL 16 (takes priority over `FIDERAIL_DB_PATH`).
- **Multi-RPC Failover Pools**: Comma-separated RPC lists per chain (`BASE_RPC_URLS`, `BASE_RECEIPT_RPC_URLS`, `SOLANA_RPC_URLS`, `ARBITRUM_RPC_URLS`, `POLYGON_RPC_URLS`) with `RPC_PACE_MS=350` per-host burst serialization.
- **Ed25519 `stateRoot` Signing**:
  - Set `FIDERAIL_STATE_ROOT_PRIVATE_KEY_PEM` (PKCS#8 PEM with literal `\n` escapes for single-line systemd `EnvironmentFile`) and optional `FIDERAIL_STATE_ROOT_PUBLIC_KEY_PEM` (SPKI PEM, auto-derived when omitted).
  - Public verification keys are served automatically at `GET /.well-known/fiderail-keys.json`.

---

## 4. Backup, Migration, and Verification Checklist

1. **Daily PostgreSQL 16 Compressed Backup**:
   ```bash
   pg_dump "$DATABASE_URL" --format=custom --compress=6 --file="/var/backups/fiderail/fiderail-pg16-$(date -u +%Y%m%dT%H%M%SZ).dump"
   ```
2. **Lossless SQLite to PostgreSQL 16 Migration**:
   ```bash
   npm run migrate:sqlite-to-pg -- ./data/fiderail-backup.db "$DATABASE_URL"
   ```
3. **Post-Deploy Verification**:
   - `npm test` passes (TypeScript build + Node test suite + SSOT anti-drift + Python SDK suite);
   - `systemctl is-active postgresql fiderail-api fiderail-indexer caddy`;
   - `curl -sS https://api.fiderail.com/healthz` confirms `status: "ok"`, `version: "2.3.5"`, `dataset.storageMode: "postgresql+snapshot"`, `indexer.storageMode: "postgresql+snapshot"`, `stateRootSigning.enabled: true`, and all 4 chains signed;
   - `curl -sS https://api.fiderail.com/.well-known/fiderail-keys.json` returns the active Ed25519 public key for offline signature verification.
