168 lines
9.4 KiB
Markdown
168 lines
9.4 KiB
Markdown
# Tessera — behavioral specification (v1)
|
||
|
||
Tessera is a self-hosted backup vault. This document is the contract for metaphors, state machines, error copy, and security baseline.
|
||
|
||
## Metaphor glossary
|
||
|
||
| Internal concept | User-facing term | Notes |
|
||
|------------------|------------------|-------|
|
||
| Repository | **Vault** | One encrypted store per host |
|
||
| Scheduled / manual job | **Orbit** | “Your data circles the vault on a schedule” |
|
||
| Point-in-time backup | **Snapshot** | A **tile** on the vault ring |
|
||
| Remote machine | **Outpost** | Runs `tessera-agent` |
|
||
| Encrypted link to hub | **Wormhole** | Pair once; beam snapshots upstream |
|
||
| Retention | **Decay** | Old snapshots fade per policy |
|
||
| Restore | **Reconstitute** | Destructive-capable; always confirm |
|
||
| Deduped deltas | “Only stardust that changed” | Tooltip only—not headline copy |
|
||
|
||
### Status dots (Lune-style)
|
||
|
||
| Color | Meaning |
|
||
|-------|---------|
|
||
| Green | All orbits current; last snapshot succeeded |
|
||
| Amber | Orbit running, pairing waiting, or reconstitute countdown |
|
||
| Grey | Outpost offline or never paired |
|
||
| Red | Last snapshot or reconstitute failed |
|
||
|
||
---
|
||
|
||
## State machine: orbit run
|
||
|
||
```
|
||
┌─────────────┐
|
||
schedule/ │ idle │
|
||
manual snap └──────┬──────┘
|
||
│ start
|
||
▼
|
||
┌─────────────┐
|
||
┌────│ preparing │──── timeout ──► failed
|
||
│ └──────┬──────┘
|
||
│ │ provider ready
|
||
│ ▼
|
||
│ ┌─────────────┐
|
||
│ │ capturing │◄── dry-run: skip vault write, end at rehearsed
|
||
│ └──────┬──────┘
|
||
│ │ packs sealed
|
||
│ ▼
|
||
│ ┌─────────────┐
|
||
│ │ sealing │
|
||
│ └──────┬──────┘
|
||
│ │ index updated
|
||
│ ▼
|
||
│ ┌─────────────┐
|
||
└───►│ applying │ decay after success only
|
||
│ decay │
|
||
└──────┬──────┘
|
||
│
|
||
┌───────────┴───────────┐
|
||
▼ ▼
|
||
┌─────────────┐ ┌─────────────┐
|
||
│ completed │ │ failed │
|
||
└─────────────┘ └─────────────┘
|
||
```
|
||
|
||
**Invariants**
|
||
|
||
- Only one active capture per orbit per vault at a time (hub enforces lock).
|
||
- Automatic decay runs only after a **successful** non-dry-run seal and applies to the captured orbit.
|
||
- Dry-run (“rehearse”) never writes snapshot metadata to the vault store.
|
||
|
||
---
|
||
|
||
## State machine: reconstitute
|
||
|
||
```
|
||
user picks snapshot + target
|
||
│
|
||
▼
|
||
┌─────────────┐
|
||
│ confirming │ show evidence: size, age, paths/DB name
|
||
└──────┬──────┘
|
||
│ user confirms
|
||
▼
|
||
┌─────────────┐
|
||
│ countdown │ 12s grace; abort returns to idle
|
||
└──────┬──────┘
|
||
│ timer elapsed
|
||
▼
|
||
┌─────────────┐
|
||
│ restoring │
|
||
└──────┬──────┘
|
||
│
|
||
┌────────┴────────┐
|
||
▼ ▼
|
||
completed failed
|
||
```
|
||
|
||
**Copy during countdown:** “Reconstituting in {n}s — abort restores nothing.”
|
||
|
||
---
|
||
|
||
## State machine: wormhole pairing
|
||
|
||
```
|
||
Hub Outpost (agent)
|
||
│ │
|
||
│ display 6-char pairing code │
|
||
│◄───────────────────────────────│ user runs: tessera wormhole pair
|
||
│ │
|
||
│ POST /wormhole/claim │
|
||
│◄───────────────────────────────│
|
||
│ │
|
||
│ issue device token + id │
|
||
│───────────────────────────────►│
|
||
│ │
|
||
│ Bearer upload token on upload API │
|
||
│◄───────────────────────────────│
|
||
```
|
||
|
||
States: `unpaired` → `code_shown` → `claimed` → `active` → `offline` (heartbeat miss).
|
||
|
||
---
|
||
|
||
## Error UX copy (English v1)
|
||
|
||
| Situation | User message | Telemetry (expandable) |
|
||
|-----------|--------------|------------------------|
|
||
| Vault locked | “Another orbit is still circling the vault. Try again when it finishes.” | `orbit_lock:{id}` |
|
||
| Wrong passphrase | “That key doesn’t unlock this vault.” | No stack traces |
|
||
| Provider missing | “We couldn’t reach the source at this outpost.” | Provider error string |
|
||
| Postgres dump failed | “The database wouldn’t yield a snapshot.” | `pg_dump` exit code |
|
||
| Disk full | “The vault is out of space—free room or widen the hold.” | Bytes needed |
|
||
| Wormhole expired code | “That pairing code has burned up. Generate a fresh one on the vault.” | TTL 10m |
|
||
| Reconstitute aborted | “Reconstitute cancelled. Nothing was changed.” | — |
|
||
| Decay pruned | “{n} old snapshots decayed per your policy.” | Snapshot IDs |
|
||
|
||
Tone: short sentences, metaphor in headings, facts in telemetry panels.
|
||
|
||
---
|
||
|
||
## Security baseline
|
||
|
||
1. **Vault key:** New vaults use Argon2id (19 MiB, time cost 2, parallelism 1). The salt is `keys/tessera.salt` (mode 0600) and the parameters are `keys/kdf.json`. A salt with no `kdf.json` stays PBKDF2-HMAC-SHA256, 100,000 iterations, so vaults created before Argon2id still open. The derived key is not stored. Never log the passphrase. New vaults refuse a well-known development passphrase. New snapshot metadata is AES-GCM ciphertext in `{id}.json.enc`. Existing plaintext `{id}.json` files still list and restore. Chunk index JSON stays plaintext.
|
||
2. **Hub auth:** Browser access uses server-side sessions: OIDC sign-in (authorization code with PKCE) and an emergency operator account. Every route passes one central gate: authenticate, resolve the resource, then check the caller's grants. Management actions are administrator-only; non-admins can only hold `orbit.read`, `snapshot.read`, `capture.run`, `snapshot.download` and per-relation `refresh.run`. Outpost tokens and pairing codes are stored as digests. Requests are rate limited. The per-route matrix is in `docs/auth-endpoint-contract.md`. Behind a reverse proxy, set `TESSERA_TRUSTED_PROXIES` to the proxies you operate. The default listen address is `127.0.0.1:8787`.
|
||
3. **Agents:** No vault master key. After pairing, the hub issues an upload token stored in SQLite. The token survives a hub restart. Claim is an atomic update of a pairing code that has not expired.
|
||
4. **Wormhole:** A Restic agent sends missing chunks to its own authenticated, append-only REST repository and registers the finished snapshot using its paired token. The hub checks that the token belongs to the outpost assigned to that orbit. Legacy uploads require `total_bytes`. Chunks are written at `offset` into a mode `0600` `.part` file. When the ranges cover the payload, the hub stores it in Restic, applies decay, and deletes the `.part`. A later chunk on a sealed session is 409. `TESSERA_WORMHOLE_MTLS=1` (or `true`) starts a separate rustls listener that requires a client certificate. It needs `TESSERA_WORMHOLE_CERT`, `TESSERA_WORMHOLE_KEY`, and `TESSERA_WORMHOLE_CLIENT_CA`. `TESSERA_WORMHOLE_LISTEN` defaults to `127.0.0.1:8788`. While that listener is running, the plain HTTP upload and commit routes return 403. An `https://` agent needs `TESSERA_WORMHOLE_CA`, `TESSERA_WORMHOLE_CLIENT_CERT`, and `TESSERA_WORMHOLE_CLIENT_KEY`.
|
||
5. **Providers:** Filesystem and Postgres are in this release. The command provider is rejected with `command provider is outside this release; use filesystem or postgres`. Postgres parses `postgres://` or `postgresql://`, writes the password to a mode `0600` pgpass file, and passes `PGPASSFILE`, `PGHOST`, `PGPORT`, `PGUSER`, and `PGDATABASE`. The URL and password are not process arguments.
|
||
6. **Control plane:** SQLite (`data/tessera.db`) holds metadata, pairing codes, upload tokens, and upload ranges — no backup payloads.
|
||
7. **Audit:** Pairing, wormhole seal, reconstitute start/complete, and decay prune are logged to `audit_log`.
|
||
|
||
---
|
||
|
||
## Decay presets (friendly → policy)
|
||
|
||
| Preset | Rule |
|
||
|--------|------|
|
||
| `week-of-dailies` | Keep 7 daily snapshots |
|
||
| `month-of-weeklies` | Keep 4 weekly |
|
||
| `year-of-monthlies` | Keep 12 monthly |
|
||
| `custom` | Hub-stored JSON policy (see `tessera-core::decay`) |
|
||
|
||
---
|
||
|
||
## API conventions
|
||
|
||
- REST JSON under `/api/v1/`
|
||
- OpenAPI 3.1 via hub `utoipa`
|
||
- Webhooks (struct only v1): `orbit.completed`, `orbit.failed`, `decay.pruned`, `outpost.offline`
|