Admins and the instance's name; NodeInfo 2.1 and a schema-valid name

17caeec · gmorell · 2026-11-18 22:01

54 files +630 -82
Message
{commit_body(@commit)}

Files changed

modified README.md
+15 −2
@@ -93,7 +93,8 @@ posted. Marking something private sends a `Delete` for what it now covers.
93 93
94 94 Served: `/.well-known/webfinger` (`acct:user@host`, `acct:@user@host`, or
95 95 the actor or `/@user` URL), `/.well-known/host-meta`, `/.well-known/nodeinfo`
96 −and `/nodeinfo/2.0`, the instance actor `/ap/actor`, accounts under
96 +with `/nodeinfo/2.1` and `/2.0` (software `finaltrack`; the node's name and
97 +description are the admin's, see Admins), the instance actor `/ap/actor`, accounts under
97 98 `/ap/users/:name` (inbox, outbox, followers), posts at `/ap/notes/:id`, the
98 99 shared inbox `/ap/inbox`. Inbound: `Follow`, `Undo` of one, `Delete` of an
99 100 actor that's gone; every request's HTTP signature is checked.
@@ -132,6 +133,7 @@ master: `ggr.neiam.co/neiam/final_track:{master,latest,sha-…}`. The release
132 133 | `migrate` | run migrations (an init container in Kubernetes) |
133 134 | `invite [--email E] [--note N] [--days D] [--by E]` | print a single-use registration link |
134 135 | `invite-link EMAIL` | a fresh link for an invite addressed to EMAIL |
136 +| `admin [--revoke] EMAIL` | make an account an admin (or not) |
135 137 | `final_track rpc 'FinalTrack.Covers.retry_misses()'` | look up covers again for albums that never matched |
136 138
137 139 The About page has copy-ready Podman/Docker commands for a single box.
@@ -153,8 +155,18 @@ The About page has copy-ready Podman/Docker commands for a single box.
153 155 | `SMTP_RELAY`, `SMTP_PORT`, `SMTP_USERNAME`, `SMTP_PASSWORD`, `SMTP_SSL`, `SMTP_TLS`, `SMTP_AUTH` | — | mail. Optional: without a relay (and, if it needs auth, a password) mail is off — no emailed links, registration takes a password |
154 156 | `MAIL_FROM_ADDRESS`, `MAIL_FROM_NAME` | `noreply@PHX_HOST`, `Final Track` | |
155 157 | `OIDC_ENABLED`, `OIDC_ISSUER`, `OIDC_CLIENT_ID`, `OIDC_CLIENT_SECRET`, … | off | see `neiam_auth`'s README; `OIDC_LOGIN_MODE` picks how SSO and passwords coexist |
158 +| `FINAL_TRACK_NODE_NAME`, `FINAL_TRACK_NODE_DESCRIPTION` | `Final Track`, a one-liner | what NodeInfo and the instance's fediverse actor call the server; an admin's Instance page overrides them |
159 +| `FINAL_TRACK_ADMIN_GROUP` | `admins` | members of this OIDC group become admins on sign-in |
156 160 | `CLUSTER_NAMESPACE`, `POD_IP`, `RELEASE_COOKIE` | — | clustering in Kubernetes (below) |
157 161
162 +### Admins
163 +
164 +Admins get an **Instance** page (`/admin/instance`, in the account menu)
165 +for the server's name and description. Members of the OIDC admin group
166 +become admins when they sign in with SSO; elsewhere, `bin/admin EMAIL` (or
167 +`mix final_track.admin EMAIL` in dev). Leaving the group doesn't demote
168 +anyone — `bin/admin --revoke EMAIL` does.
169 +
158 170 ### Clustering
159 171
160 172 With `CLUSTER_NAMESPACE` set, libcluster lists that namespace's pods
@@ -176,5 +188,6 @@ and ActivityPub deliveries; covers must be on a volume all pods share.
176 188 | `FinalTrack.Federation` (+ `Objects`, `HTTP`, `HTTPSignature`, `Delivery`) | ActivityPub; signatures and guarded HTTP ported from angler |
177 189 | `FinalTrackWeb.FederationController`, `ProfileController`, `TagController` | the ActivityPub endpoints, `/@name`, `/tags/:tag` |
178 190 | `FinalTrackWeb.Api.ScrobbleController`, `Plugs.ScrobbleAuth` | the scrobbling API |
179 −| `FinalTrack.Accounts` | users, invites, display names |
191 +| `FinalTrack.Accounts` | users, invites, display names, admins |
192 +| `FinalTrack.Instance` | the server's name and description |
180 193 | `FinalTrack.Release` | what `bin/migrate`, `bin/invite` run |
modified config/runtime.exs
+9 −0
@@ -41,6 +41,15 @@ if config_env() == :dev do
41 41 end
42 42
43 43 if config_env() == :prod do
44 + # What the server calls itself (NodeInfo, its fediverse actor): defaults an
45 + # admin's Instance page overrides.
46 + config :final_track, FinalTrack.Instance,
47 + node_name: System.get_env("FINAL_TRACK_NODE_NAME"),
48 + node_description: System.get_env("FINAL_TRACK_NODE_DESCRIPTION")
49 +
50 + # Members of this OIDC group become admins when they sign in.
51 + config :final_track, :admin_group, System.get_env("FINAL_TRACK_ADMIN_GROUP", "admins")
52 +
44 53 # ActivityPub: off unless FINAL_TRACK_ACTIVITYPUB=true. PHX_HOST must be
45 54 # the public domain first: it's the domain fediverse accounts live on.
46 55 config :final_track, FinalTrack.Federation,
modified config/test.exs
+4 −0
@@ -37,6 +37,10 @@ config :final_track, FinalTrack.Repo,
37 37 hostname: "localhost",
38 38 database: "final_track_test#{System.get_env("MIX_TEST_PARTITION")}",
39 39 pool: Ecto.Adapters.SQL.Sandbox,
40 + # LiveView processes share a test's sandbox connection; under a full
41 + # parallel suite the default 50ms queue target made them give up.
42 + queue_target: 1_000,
43 + queue_interval: 5_000,
40 44 pool_size: System.schedulers_online() * 2,
41 45 # compose.yml's postgres by default; POSTGRES_PORT=5432 for the host's own.
42 46 port: String.to_integer(System.get_env("POSTGRES_PORT") || "54330")
modified lib/final_track/accounts.ex
+15 −0
@@ -305,6 +305,21 @@ defmodule FinalTrack.Accounts do
305 305 end
306 306 end
307 307
308 + ## Admins
309 +
310 + @doc """
311 + Makes `user` an admin, or not. Only ever called from trusted code (the
312 + OIDC adapter for the admin group, the release command); never from a
313 + form, and `is_admin` is in no changeset's cast.
314 + """
315 + def set_admin(%User{} = user, admin?) when is_boolean(admin?) do
316 + user |> Ecto.Changeset.change(is_admin: admin?) |> Repo.update()
317 + end
318 +
319 + @doc "Whether `user` is an admin."
320 + def admin?(%User{is_admin: true}), do: true
321 + def admin?(_), do: false
322 +
308 323 ## Profile
309 324
310 325 @doc "A changeset for the profile form."
modified lib/final_track/accounts/user.ex
+2 −0
@@ -5,6 +5,8 @@ defmodule FinalTrack.Accounts.User do
5 5 schema "users" do
6 6 field :email, :string
7 7 field :display_name, :string
8 + # Edits instance settings. Never cast from a form: see Accounts.set_admin/2.
9 + field :is_admin, :boolean, default: false
8 10 field :password, :string, virtual: true, redact: true
9 11 field :hashed_password, :string, redact: true
10 12 field :confirmed_at, :utc_datetime
modified lib/final_track/federation/objects.ex
+40 −15

Click to load diff…

added lib/final_track/instance.ex
+49 −0

Click to load diff…

added lib/final_track/instance/settings.ex
+26 −0

Click to load diff…

modified lib/final_track/neiam_auth_adapter.ex
+12 −2

Click to load diff…

modified lib/final_track/release.ex
+30 −0

Click to load diff…

modified lib/final_track_web/components/layouts.ex
+5 −0

Click to load diff…

modified lib/final_track_web/controllers/federation_controller.ex
+10 −6

Click to load diff…

added lib/final_track_web/live/admin_live/instance.ex
+106 −0

Click to load diff…

modified lib/final_track_web/router.ex
+4 −1

Click to load diff…

modified lib/final_track_web/user_auth.ex
+18 −0

Click to load diff…

added lib/mix/tasks/final_track.admin.ex
+31 −0

Click to load diff…

added priv/repo/migrations/20261118215342_add_is_admin_to_users.exs
+11 −0

Click to load diff…

added priv/repo/migrations/20261118215343_create_instance_settings.exs
+16 −0

Click to load diff…

added rel/overlays/bin/admin
+16 −0

Click to load diff…

added rel/overlays/bin/admin.bat
+1 −0

Click to load diff…

added test/final_track/covers_queue_test.exs
+83 −0

Click to load diff…

modified test/final_track/covers_test.exs
+0 −16

Click to load diff…

added test/final_track/instance_test.exs
+32 −0

Click to load diff…

modified test/final_track_web/controllers/federation_controller_test.exs
+28 −10

Click to load diff…

modified test/final_track_web/controllers/neiam_auth_controller_test.exs
+8 −0

Click to load diff…

modified test/final_track_web/controllers/tag_controller_test.exs
+4 −2

Click to load diff…

added test/final_track_web/live/admin_live/instance_test.exs
+46 −0

Click to load diff…

modified test/final_track_web/live/album_live_test.exs
+1 −27

Click to load diff…

modified test/final_track_web/live/home_live_test.exs
+8 −1

Click to load diff…

Parents: 8edc7bd