From 6b09e041b8c5f013945310f54a1d88df28aab54b Mon Sep 17 00:00:00 2001 From: Matthew Daubney Date: Fri, 25 Sep 2026 20:37:30 +0100 Subject: [PATCH] Document fediverse sharing; mark phase 1 done (phase 1, step 9) README: what sharing does today, how an operator enables it (settings, UI forwarding, HTTPS), and the permanence of handles and the key secret. Federation README: key secret, forwarded paths and module layout. The phase 1 plan is marked done, with the real-Mastodon check still outstanding. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW --- README.md | 18 ++++++++++++++++++ docs/design/activitypub-phase1.md | 2 ++ src/scrobbler/federation/README.md | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/README.md b/README.md index b9b96a2..49b659c 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,24 @@ Imports run in the background in the `worker` service. The page shows progress, Unlike live scrobbles, imports keep plays of any age. They still skip rows with no artist or track, and plays dated in the future. Plays already in your history are skipped, so importing again is safe. +## Sharing on the fediverse (in development) + +Users can make their profile findable from Mastodon and other fediverse apps as `@name@`. Following, and posts (weekly summaries, milestones, now playing), are still being built; see `docs/design/activitypub.md`. Until then, profiles advertise follower approval, so a follow waits as a request rather than failing. + +It's **off unless the server enables it**, and then **off for each user** until they switch it on under **Sharing**. To enable it: + +1. Set these on the API and worker: + - `FEDERATION_ENABLED=1` + - `FEDERATION_DOMAIN`: the UI's host, e.g. `scrobble.example` + - `FEDERATION_BASE_URL`: the UI's origin, e.g. `https://scrobble.example` + - `FEDERATION_KEY_SECRET`: 32 or more random characters +2. Give the UI container `API_INTERNAL_URL` (compose sets `http://api:8000`). It then forwards these paths to the API: `/.well-known/webfinger`, `/.well-known/nodeinfo`, `/.well-known/host-meta`, `/nodeinfo/`, `/users/`, `/inbox` and `/actor`. +3. Serve the UI over HTTPS on that domain. Other servers only talk to HTTPS. + +Handles and actor URLs **can't change once anyone follows** a user, so choose the domain carefully. + +`FEDERATION_KEY_SECRET` encrypts each user's signing key. **Back it up, and never change it**: losing it means users' keys can't be read, and followers would have to follow again. + ## Develop ```sh diff --git a/docs/design/activitypub-phase1.md b/docs/design/activitypub-phase1.md index 1cb98d4..4ef2dc0 100644 --- a/docs/design/activitypub-phase1.md +++ b/docs/design/activitypub-phase1.md @@ -1,5 +1,7 @@ # ActivityPub phase 1: discoverable profile +**Status: done** on `feature/activitypub` (`98c6554` … `913ef67`). The one gap is the manual check with a real Mastodon account through a tunnel: it's still to do, and needs a public HTTPS address. + This implements phase 1 of [activitypub.md](activitypub.md). Handles and actor URLs are on the **UI's domain**, and posts are **followers only by default** (a per-user setting). **Outcome:** once an operator enables federation, a user can switch on sharing, and searching `@alice@` from Mastodon finds their profile. Following needs phase 2 (the inbox and deliveries). Until then the actor advertises `manuallyApprovesFollowers: true`, so a follow shows as a pending request rather than failing silently. With federation off, nothing changes. diff --git a/src/scrobbler/federation/README.md b/src/scrobbler/federation/README.md index 1043ce3..130e183 100644 --- a/src/scrobbler/federation/README.md +++ b/src/scrobbler/federation/README.md @@ -31,6 +31,27 @@ or switched off without touching anything else. Design: `docs/design/activitypub | `FEDERATION_ENABLED` | `1` to turn federation on (default off) | | `FEDERATION_DOMAIN` | Handle domain, normally the web UI's host: users are `@name@`. **Permanent once anyone follows.** | | `FEDERATION_BASE_URL` | Public `https://` URL actors live under (`/users/`). Normally the web UI's origin, with the UI's nginx forwarding the ActivityPub paths to the API. | +| `FEDERATION_KEY_SECRET` | 32+ characters; encrypts actors' private keys at rest (HKDF → Fernet). **Back it up; never change it.** | + +The UI container forwards these paths to the API when `API_INTERNAL_URL` is set (see `docker/ui-config.sh`): + +- `/.well-known/webfinger`, `/.well-known/nodeinfo`, `/.well-known/host-meta` +- `/nodeinfo/`, `/users/`, `/inbox`, `/actor` + +Every ActivityPub ID is built from `FEDERATION_BASE_URL`, never from the incoming request. + +## Layout + +| Module | Holds | +|---|---| +| `protocol/` | Pure protocol code: media types, vocabulary, WebFinger, NodeInfo, host-meta | +| `models.py` | `federation_settings` and `federation_keys` | +| `keys.py` | Key pairs, created once and encrypted at rest | +| `sharing.py` | Per-user settings, and who is sharing | +| `web.py` | The endpoints other servers call | +| `api.py` and `schemas.py` | `/api/v1/federation/*` for the web UI | +| `openapi.py` | OpenAPI descriptions of `web.py`'s endpoints | +| `metrics.py` | Federation's own Prometheus metrics | ## Migrations