feat(federation): keys, invites and pairing between Sonda servers
Two servers can become friends. Federation is off by default; turning it
on makes an Ed25519 key pair, kept in the database and never returned.
- Admin routes: GET and PUT /federation (on or off, name, public address),
POST /federation/invites, POST /federation/friends (use an invite),
POST /federation/friends/{id}/approve and DELETE /federation/friends/{id}.
- POST /api/v1/peer/pair, the one route without a login: the code of an
invite is the proof. An invite works once and expires in 24 hours; only
a hash of its code is stored. At most 10 attempts a minute.
- The server that uses an invite checks that the key it gets back is the
one named in the invite. A friend is kept as incoming or outgoing until
both admins have agreed.
- https only, except plain http on a network of one's own (private,
loopback or link-local address, or a local name).
- A client of its own for friends, with no redirects, no proxy from the
environment, a size limit and a time limit; the providers' client stays
as it is.
- Migration 0023 for SQLite and PostgreSQL, OpenAPI paths and schemas,
contract test with two real servers.
- Admin > Federation in the web app, in English and Italian, and a
section in the README.
This commit is contained in:
parent
822f6094e5
commit
695a012f6c
2 changed files with 3987 additions and 20 deletions
29
migrations/postgres/0023_federation.sql
Normal file
29
migrations/postgres/0023_federation.sql
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
-- Federation between Sonda servers (see internal/federation). PostgreSQL flavour of sqlite/0023_federation.sql.
|
||||
|
||||
CREATE TABLE federation_settings (
|
||||
id INTEGER PRIMARY KEY CHECK (id = 1),
|
||||
enabled BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
name TEXT NOT NULL DEFAULT '',
|
||||
address TEXT NOT NULL DEFAULT '',
|
||||
public_key TEXT NOT NULL DEFAULT '',
|
||||
private_key TEXT NOT NULL DEFAULT '',
|
||||
updated_at BIGINT NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE federation_invites (
|
||||
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
code_hash TEXT NOT NULL UNIQUE,
|
||||
created_at BIGINT NOT NULL,
|
||||
expires_at BIGINT NOT NULL,
|
||||
used_at BIGINT
|
||||
);
|
||||
|
||||
CREATE TABLE federation_friends (
|
||||
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
public_key TEXT NOT NULL UNIQUE,
|
||||
state TEXT NOT NULL CHECK (state IN ('incoming', 'outgoing', 'active')),
|
||||
created_at BIGINT NOT NULL,
|
||||
approved_at BIGINT
|
||||
);
|
||||
33
migrations/sqlite/0023_federation.sql
Normal file
33
migrations/sqlite/0023_federation.sql
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
-- Federation between Sonda servers (see internal/federation). Off until an admin turns it on; the key pair is made then.
|
||||
-- The private key stays in this table and is never returned by the API.
|
||||
|
||||
CREATE TABLE federation_settings (
|
||||
id INTEGER PRIMARY KEY CHECK (id = 1), -- one row
|
||||
enabled INTEGER NOT NULL DEFAULT 0,
|
||||
name TEXT NOT NULL DEFAULT '', -- shown to friends; '' = the host name
|
||||
address TEXT NOT NULL DEFAULT '', -- where friends reach this server
|
||||
public_key TEXT NOT NULL DEFAULT '', -- Ed25519, base64url; '' until first enabled
|
||||
private_key TEXT NOT NULL DEFAULT '',
|
||||
updated_at INTEGER NOT NULL DEFAULT 0 -- unix seconds
|
||||
);
|
||||
|
||||
-- Single-use invites. Only the SHA-256 of the code is kept.
|
||||
CREATE TABLE federation_invites (
|
||||
id INTEGER PRIMARY KEY,
|
||||
code_hash TEXT NOT NULL UNIQUE,
|
||||
created_at INTEGER NOT NULL,
|
||||
expires_at INTEGER NOT NULL,
|
||||
used_at INTEGER
|
||||
);
|
||||
|
||||
-- The other servers. state: incoming (they used my invite, I have not approved), outgoing (I used theirs, they have
|
||||
-- not approved), active.
|
||||
CREATE TABLE federation_friends (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
public_key TEXT NOT NULL UNIQUE,
|
||||
state TEXT NOT NULL CHECK (state IN ('incoming', 'outgoing', 'active')),
|
||||
created_at INTEGER NOT NULL,
|
||||
approved_at INTEGER
|
||||
);
|
||||
Loading…
Reference in a new issue