From 529342ab39f2c4a4ce9adf552ea463c4541b07ff Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Sat, 28 Nov 2026 20:13:32 +0000 Subject: [PATCH 1/2] nixos/chatterbox: Add Pocket ID sign-in Append a PKCE provider to the existing Synapse OIDC configuration. Require explicit account links and preserve Google and password login. --- .../colony/shill/containers/chatterbox.md | 19 ++++++++ .../colony/shill/containers/middleman.md | 2 +- .../vms/shill/containers/chatterbox.nix | 48 +++++++++++++++++-- .../vms/shill/containers/middleman/auth.nix | 9 ++++ .../chatterbox/synapse-oidc-secret.txt.age | 18 +++++++ 5 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 secrets/chatterbox/synapse-oidc-secret.txt.age diff --git a/docs/sites/colony/shill/containers/chatterbox.md b/docs/sites/colony/shill/containers/chatterbox.md index cb1fa2e..3225cf9 100644 --- a/docs/sites/colony/shill/containers/chatterbox.md +++ b/docs/sites/colony/shill/containers/chatterbox.md @@ -17,6 +17,25 @@ Port 8008 carries client and federation traffic with forwarded headers, while a uses port 9000. Registration and guest access are disabled; uploads, dynamic thumbnails and URL previews are enabled, with preview fetching restricted to [middleman](middleman.md). +#### Pocket ID sign-in + +Synapse offers [Pocket ID](middleman.md#pocket-id) alongside Google and password login. +`matrix-synapse` appends the Pocket ID provider to the existing provider list at startup. +The `matrix` client requires PKCE, and new account registration through it is disabled. + +Deploy `middleman` to register the client before deploying `chatterbox`. For each existing +Matrix account, use Synapse's Admin API from inside `chatterbox` to link a verified Pocket ID +subject (`sub`). + +1. Read the account with `GET /_synapse/admin/v2/users/`. +2. Send a `PUT` for that account with the existing `external_ids` plus + `{"auth_provider":"oidc-pocket-id","external_id":""}`. + Include the current `admin` value to preserve the account's administrator status. +3. Sign in through Pocket ID in a fresh Element session and verify the Matrix ID is the same. + For encrypted rooms, verify the new session or restore from the existing recovery key. + +See the [Synapse User Admin API](https://element-hq.github.io/synapse/latest/admin_api/user_admin_api.html#create-or-modify-account). + ### Bridges The box runs heisenbridge for IRC, `mautrix-whatsapp`, and two `mautrix-meta` instances for diff --git a/docs/sites/colony/shill/containers/middleman.md b/docs/sites/colony/shill/containers/middleman.md index 66e0e12..c945f4e 100644 --- a/docs/sites/colony/shill/containers/middleman.md +++ b/docs/sites/colony/shill/containers/middleman.md @@ -116,7 +116,7 @@ all vhosts are `onlySSL`, kTLS and HTTP/2. "SSO" = gated behind [oauth2-proxy](# | `id.nul.ie` | `localhost:1411` | Pocket ID; `/setup` only from internal networks; `X-API-Key` stripped | | `netdata-colony.nul.ie` | `.ams1.int.nul.ie:19999` | netdata fan-out over `vm`, `fw`, `ctr`, `oci`, `http`, `jackflix-ctr`, `chatterbox-ctr`, `colony-psql-ctr`; **SSO** | | `pass.nul.ie` | `vaultwarden-ctr:8080` | [vaultwarden](vaultwarden.md); `/notifications/hub` proxied with websockets | -| `matrix.nul.ie` | `chatterbox-ctr:8008` | [chatterbox](chatterbox.md) Synapse client + federation; also listens on `:8448` as federation `default_server`; `= /` redirects to Element; serves Matrix `.well-known`s | +| `matrix.nul.ie` | `chatterbox-ctr:8008` | [chatterbox](chatterbox.md) Synapse client + federation; native Pocket ID sign-in; also listens on `:8448` as federation `default_server`; `= /` redirects to Element; serves Matrix `.well-known`s | | `element.nul.ie` | static `element-web` | Element configured for the `nul.ie` homeserver | | `torrents.nul.ie` | `jackflix-ctr:9091` | Transmission ([jackflix](jackflix.md)); **SSO** | | `jackett.nul.ie` | `jackflix-ctr:9117` | **SSO** | diff --git a/nixos/boxes/colony/vms/shill/containers/chatterbox.nix b/nixos/boxes/colony/vms/shill/containers/chatterbox.nix index f1bc313..5a06b0f 100644 --- a/nixos/boxes/colony/vms/shill/containers/chatterbox.nix +++ b/nixos/boxes/colony/vms/shill/containers/chatterbox.nix @@ -24,8 +24,42 @@ in configuration = { lib, pkgs, config, assignments, allAssignments, ... }: let - inherit (lib) genAttrs mkMerge mkIf mkForce; + inherit (lib) genAttrs mkAfter mkMerge mkIf mkForce; inherit (lib.my) networkdAssignment; + + synapseSecretConfig = config.age.secrets."chatterbox/synapse.yaml".path; + synapseOidcConfig = "/run/matrix-synapse/oidc-providers.json"; + pocketIdProvider = pkgs.writeText "synapse-pocket-id.json" (builtins.toJSON { + idp_id = "pocket-id"; + idp_name = "Pocket ID"; + issuer = "https://id.${pubDomain}"; + client_id = "matrix"; + client_secret_path = config.age.secrets."chatterbox/synapse-oidc-secret.txt".path; + pkce_method = "always"; + scopes = [ "openid" ]; + enable_registration = false; + }); + + # Synapse merges config files at the top level, so append to the private + # provider list before passing it to Synapse as the final config layer. + mergeSynapseOidc = pkgs.writers.writePython3 "merge-synapse-oidc" { + libraries = [ pkgs.python3Packages.pyyaml ]; + } '' + import json + import sys + from pathlib import Path + + import yaml + + private_config, pocket_id_config, output = map(Path, sys.argv[1:]) + existing = yaml.safe_load(private_config.read_text()) + providers = existing.get("oidc_providers") or [] + providers.append(json.loads(pocket_id_config.read_text())) + + temporary = output.with_suffix(".tmp") + temporary.write_text(json.dumps({"oidc_providers": providers})) + temporary.replace(output) + ''; in { config = mkMerge [ @@ -41,6 +75,10 @@ in owner = "matrix-synapse"; group = "matrix-synapse"; }; + "chatterbox/synapse-oidc-secret.txt" = { + owner = "matrix-synapse"; + group = "matrix-synapse"; + }; "chatterbox/nul.ie.signing.key" = { owner = "matrix-synapse"; group = "matrix-synapse"; @@ -81,7 +119,11 @@ in systemd = { network.networks."80-container-host0" = networkdAssignment "host0" assignments.internal; - services = { } // (genAttrs [ "mautrix-whatsapp" "mautrix-meta-messenger" "mautrix-meta-instagram" ] (_: { + services = { + matrix-synapse.preStart = mkAfter '' + ${mergeSynapseOidc} ${synapseSecretConfig} ${pocketIdProvider} ${synapseOidcConfig} + ''; + } // (genAttrs [ "mautrix-whatsapp" "mautrix-meta-messenger" "mautrix-meta-instagram" ] (_: { # ffmpeg needed to convert GIFs to video path = with pkgs; [ ffmpeg ]; })); @@ -99,7 +141,7 @@ in "oidc" ]; - extraConfigFiles = [ config.age.secrets."chatterbox/synapse.yaml".path ]; + extraConfigFiles = [ synapseSecretConfig synapseOidcConfig ]; settings = { server_name = "nul.ie"; public_baseurl = "https://matrix.nul.ie"; diff --git a/nixos/boxes/colony/vms/shill/containers/middleman/auth.nix b/nixos/boxes/colony/vms/shill/containers/middleman/auth.nix index f6c0b2d..aaa0415 100644 --- a/nixos/boxes/colony/vms/shill/containers/middleman/auth.nix +++ b/nixos/boxes/colony/vms/shill/containers/middleman/auth.nix @@ -17,6 +17,7 @@ in "middleman/oauth2-proxy.env" = { }; # Client secrets shared with the boxes that run the apps "gitea/oidc-secret.txt" = { }; + "chatterbox/synapse-oidc-secret.txt" = { }; # Not deployed anywhere else: mailcow isn't NixOS, so it's pasted into its admin UI "mailcow/oidc-secret.txt" = { }; }; @@ -51,6 +52,14 @@ in secret.file = config.age.secrets."gitea/oidc-secret.txt".path; }; + matrix = { + name = "Matrix"; + callbackURLs = [ "https://matrix.${pubDomain}/_synapse/client/oidc/callback" ]; + launchURL = "https://element.${pubDomain}/"; + pkce = true; + secret.file = config.age.secrets."chatterbox/synapse-oidc-secret.txt".path; + }; + # mailcow's Generic-OIDC identity provider (`mail` VM), for mailbox sign-in mailcow = { name = "mailcow"; diff --git a/secrets/chatterbox/synapse-oidc-secret.txt.age b/secrets/chatterbox/synapse-oidc-secret.txt.age new file mode 100644 index 0000000..dc5bff5 --- /dev/null +++ b/secrets/chatterbox/synapse-oidc-secret.txt.age @@ -0,0 +1,18 @@ +-----BEGIN AGE ENCRYPTED FILE----- +YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IFpCM2U2USAwZG9S +UStBWHJGTjdYWG5kNkE0SFhObDBVVzRXcjBjaWdDMVNhQmN0aENRCm1xYnRURUtr +T3ZldWxxVjR3cFdoRlhLRzhYT250RWJFc3F1eDN1TlJMOGMKLT4gc3NoLWVkMjU1 +MTkgVkZjdzVnIDY1VDRNS1l5QTR5MnhCTHZmY1FkQ1pUNXJhdGtVWUtnUGpZUnJN +dnFmd2MKbVpzd21wcndEVnNOaTdVTkZ3ajZNZ2pMQTRueERJZitQREZyamRPcURv +awotPiBYMjU1MTkgM3ZQMTJjVGthb2JkL3VEUFRSSWJ5TWlYc0M1djFzVG41ckdF +SEQxemNBUQovK0YxZU0wOUxPSkZ2Z3BVb3RZSGRXOEltQXF5SUtoNDhwaWNKNU9u +TEp3Ci0+IFgyNTUxOSBOMEFXV3N1MS9LaCtGVzAvUUQ4bTF2a0o4WFJ1ekZTSHJR +NlBHR2NwbFdjCnNJTE1nTDFhQk9taHVoaUpyZURpTUN3YjdiemswKzVndGZlNE5u +eFpKcW8KLT4gdixScHxnNC1ncmVhc2UgdWB5YXhRIHYpTzRDMzwgMDNoNkJQKywg +JCZvZ3BqClQwYzVsTkxBcjFoa0JUUHRBb2dqZ2VvSW5XeUpVTlZZdFM5bmhCKzdP +Mks0YjBLSHlvdi9pK3QwK05veVpTZEYKN0lJd3NlSENRN1NPNG9vTy9UWTBhVm13 +dGx0Z3hRbWFxOWUvYWhVUEhicWdvM3N3TkFJbk9OSisvbnEwSnAyMwp2ejgKLS0t +IER6RFVDbllkTTJuOWZSVFFPajBCclUxRnlpOGs3Q20wTDZ2UFU0WHZkUVEK7JcZ ++Xezwqe4Ii4VCRF0iThr1EGRSUW826D0gVV48Wq9QwOy4O6HMdJs+fUWxG3buXc/ +5Bo/AmHfeGzM0HwwRAujea0TSPwVsLRsinswHsG0OvtVFFJIoKgvTgEiFc2y0Q== +-----END AGE ENCRYPTED FILE----- -- 2.56.0 From ab19c8a0e5abc0bec84bd53767282e444baf185b Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Sat, 28 Nov 2026 20:17:27 +0000 Subject: [PATCH 2/2] nixos/object: Add Pocket ID sign-in to HedgeDoc Restrict the OAuth2 client to a Pocket ID group and keep email login available. Document how existing users can link their accounts while retaining note ownership. --- .../colony/shill/containers/middleman.md | 2 +- docs/sites/colony/shill/containers/object.md | 29 ++++++++++++++++++- .../vms/shill/containers/middleman/auth.nix | 14 +++++++++ .../colony/vms/shill/containers/object.nix | 22 +++++++++++++- secrets/object/hedgedoc-oidc.env.age | 16 ++++++++++ 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 secrets/object/hedgedoc-oidc.env.age diff --git a/docs/sites/colony/shill/containers/middleman.md b/docs/sites/colony/shill/containers/middleman.md index c945f4e..96fba91 100644 --- a/docs/sites/colony/shill/containers/middleman.md +++ b/docs/sites/colony/shill/containers/middleman.md @@ -136,7 +136,7 @@ all vhosts are `onlySSL`, kTLS and HTTP/2. "SSO" = gated behind [oauth2-proxy](# | `paseo-relay.nul.ie` | `localhost:4000` | Paseo relay; websockets with long timeouts; `/metrics` blocked | | `slop.nul.ie` | static Paseo web app | falls back to `index.html`; precompressed files served as-is | | `approve.slop.nul.ie` | `palace.h.nul.ie:8095` | [`slop-broker`](../../../../slop-broker.md#approvals-web-app)'s approvals web app, which handles sign-in itself (Pocket ID) | -| `md.nul.ie` | `object-ctr:3000` | HedgeDoc; websockets | +| `md.nul.ie` | `object-ctr:3000` | [HedgeDoc](object.md#hedgedoc-sign-in); native Pocket ID sign-in; websockets | | `pb.nul.ie` | `object-ctr:8088` | wastebin | | `photos.nul.ie` | `jackflix-ctr:2342` | PhotoPrism; websockets | | `pront.nul.ie` | `stream-hi.h.nul.ie:5000` | OctoPrint on the home network ([`stream`](../../../home/stream.md)); `/webcam/` → `:5050`; **SSO** | diff --git a/docs/sites/colony/shill/containers/object.md b/docs/sites/colony/shill/containers/object.md index bfce7b3..8bf46ab 100644 --- a/docs/sites/colony/shill/containers/object.md +++ b/docs/sites/colony/shill/containers/object.md @@ -13,7 +13,7 @@ Object storage and the Nix binary cache, plus HedgeDoc and wastebin. | --- | --- | --- | | MinIO | `9000` (S3) / `9001` (console) | S3-compatible object storage, `s3.nul.ie` + `*.s3.nul.ie` (virtual-host style via `MINIO_DOMAIN`), console at `minio.nul.ie`; region `eu-central-1`; data on the `/mnt/minio` XFS volume | | Harmonia | `5000` | Nix binary cache at `nix-cache.nul.ie` — `harmonia-dev` cache serves `shill`'s `/nix/store` out of a dedicated store view rooted at `/var/lib/harmonia` (bind-mounted from `/mnt/nix-cache`), signed with the `nix-cache.key` secret; a `harmonia` user with authorized keys exists for cache pushes, including `slop-broker`'s on `palace`, which is restricted to the store protocol and GC roots (`services.slop-broker-cache`, see [`slop-broker.md`](../../../../slop-broker.md#binary-cache)) | -| HedgeDoc | `3000` | collaborative markdown notes at `md.nul.ie`; Postgres on [colony-psql](colony-psql.md); anonymous edits but no anonymous notes, email login, no open email registration | +| HedgeDoc | `3000` | collaborative markdown notes at `md.nul.ie`; Postgres on [colony-psql](colony-psql.md); anonymous edits but no anonymous notes, email and [Pocket ID sign-in](#hedgedoc-sign-in), no open email registration | | wastebin | `8088` | pastebin at `pb.nul.ie` | | atticd | `8069` | **currently disabled** (`services.atticd.enable = false`) — an alternative Nix cache that would store locally and sit behind `nix-cache.nul.ie`; config (including the `object/atticd.env` secret) is kept around | @@ -21,6 +21,33 @@ Everything public is fronted by [middleman](middleman.md) (see its vhost table). `minio-client` is installed and the user's `~/.mc/config.json` points at an age-secret config. `minio-2025-10-15T17-29-55Z` is allowlisted via `permittedInsecurePackages` (flagged as a TODO). +## HedgeDoc sign-in + +HedgeDoc uses the `hedgedoc` [Pocket ID](middleman.md#pocket-id) client with PKCE. Pocket ID +allows members of its `hedgedoc` group. Deploy `middleman` to register the client and group +before deploying `object`. + +Before granting an existing HedgeDoc user group membership, link their verified Pocket ID +subject (`sub`) to their existing row in the `hedgedoc` Postgres database. On first sign-in +HedgeDoc looks up the user by `profileid` and creates a user if that subject has no match. +Linking the existing row keeps its note ownership and email/password login. + +Verify the procedure on a copy of the database and take a backup before making the live change. +In `psql`, set `hedgedoc_user_id` to the existing user's UUID and `pocket_id_sub` to their +verified Pocket ID subject. Run the update in a transaction and commit only after it returns +exactly the expected row. If a Pocket ID login already created a separate row, resolve that +account before linking. + +```sql +UPDATE "Users" +SET profileid = :'pocket_id_sub' +WHERE id = :'hedgedoc_user_id' AND profileid IS NULL +RETURNING id, email; +``` + +Add the user to the `hedgedoc` group, then verify in a fresh browser session that both login +methods open the same account and its existing private notes. + ## Network assignments See the consolidated [network assignments](../../../../networking.md#box-assignments) table (this box: `object`). diff --git a/nixos/boxes/colony/vms/shill/containers/middleman/auth.nix b/nixos/boxes/colony/vms/shill/containers/middleman/auth.nix index aaa0415..6b1cc3e 100644 --- a/nixos/boxes/colony/vms/shill/containers/middleman/auth.nix +++ b/nixos/boxes/colony/vms/shill/containers/middleman/auth.nix @@ -18,6 +18,7 @@ in # Client secrets shared with the boxes that run the apps "gitea/oidc-secret.txt" = { }; "chatterbox/synapse-oidc-secret.txt" = { }; + "object/hedgedoc-oidc.env" = { }; # Not deployed anywhere else: mailcow isn't NixOS, so it's pasted into its admin UI "mailcow/oidc-secret.txt" = { }; }; @@ -28,6 +29,7 @@ in groups = { admins.friendlyName = "Admins"; + hedgedoc.friendlyName = "HedgeDoc"; }; clients = { @@ -60,6 +62,18 @@ in secret.file = config.age.secrets."chatterbox/synapse-oidc-secret.txt".path; }; + hedgedoc = { + name = "HedgeDoc"; + callbackURLs = [ "https://md.${pubDomain}/auth/oauth2/callback" ]; + launchURL = "https://md.${pubDomain}/"; + pkce = true; + allowedGroups = [ "hedgedoc" ]; + secret = { + file = config.age.secrets."object/hedgedoc-oidc.env".path; + key = "CMD_OAUTH2_CLIENT_SECRET"; + }; + }; + # mailcow's Generic-OIDC identity provider (`mail` VM), for mailbox sign-in mailcow = { name = "mailcow"; diff --git a/nixos/boxes/colony/vms/shill/containers/object.nix b/nixos/boxes/colony/vms/shill/containers/object.nix index 118d888..e745ecc 100644 --- a/nixos/boxes/colony/vms/shill/containers/object.nix +++ b/nixos/boxes/colony/vms/shill/containers/object.nix @@ -24,10 +24,12 @@ in configuration = { lib, pkgs, pkgsFlakes, config, assignments, ... }: let - inherit (lib) mkMerge mkIf mkForce; + inherit (lib) mkAfter mkMerge mkIf mkForce; inherit (config.my.user.homeConfig.lib.file) mkOutOfStoreSymlink; inherit (lib.my) networkdAssignment systemdAwaitPostgres; + pocketId = "https://id.${pubDomain}"; + # TODO: Migrate the object store and remove this MinIO compatibility pin. minioPkgs = import pkgsFlakes.mine-stable { inherit (pkgs.stdenv.hostPlatform) system; @@ -84,6 +86,7 @@ in "object/atticd.env" = {}; "nix-cache.key" = {}; "object/hedgedoc.env" = {}; + "object/hedgedoc-oidc.env" = {}; "object/wastebin.env" = {}; }; }; @@ -138,6 +141,10 @@ in awaitPostgres = systemdAwaitPostgres pkgs.postgresql "colony-psql"; in { + hedgedoc.serviceConfig.EnvironmentFile = mkAfter [ + config.age.secrets."object/hedgedoc-oidc.env".path + ]; + minio = { environment = { MINIO_ROOT_USER = "minioadmin"; @@ -250,6 +257,19 @@ in allowAnonymousEdits = true; email = true; allowEmailRegister = false; + oauth2 = { + providerName = "Pocket ID"; + clientID = "hedgedoc"; + authorizationURL = "${pocketId}/authorize"; + tokenURL = "${pocketId}/api/oidc/token"; + userProfileURL = "${pocketId}/api/oidc/userinfo"; + userProfileIdAttr = "sub"; + userProfileUsernameAttr = "sub"; + userProfileDisplayNameAttr = "name"; + userProfileEmailAttr = "email"; + scope = "openid profile email"; + pkce = true; + }; }; }; diff --git a/secrets/object/hedgedoc-oidc.env.age b/secrets/object/hedgedoc-oidc.env.age new file mode 100644 index 0000000..66e3ed7 --- /dev/null +++ b/secrets/object/hedgedoc-oidc.env.age @@ -0,0 +1,16 @@ +-----BEGIN AGE ENCRYPTED FILE----- +YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IFZGY3c1ZyAvK2t2 +Mkd0cWlnQ1NjNkYzQWZhdVprRjVYS0oyd0dTRWVmL1Y4YUk0aGhNCnJzaGlOajNF +OE1CbzdGbDRnMDZTcTdveXBrYnFGazh0R2FuSklzeHVLc0kKLT4gc3NoLWVkMjU1 +MTkgaGtidHZnIFFhL3I4VHVxbzg0R2sxSmhaaHV1Lzh0a2JJdXdwWGk4STl0Q1JE +RWFwRWcKL0J0SVdSTDB6UWhSOXNWc2NKakJLanU1SlNDK2IwSjZSNytSZ2tJZ1E1 +QQotPiBYMjU1MTkgUGxXTkh6VUt5L3l3NXVRN3kzTm4zSGF2VTlqYzBnM2RvejNK +N1NNZEExYwp0ZDF3RWtibmRNZnpWNTM4RW0rUDdqcGRERk9NTWY4KzZESWY3bDNo +TkNNCi0+IFgyNTUxOSBNMkNoencrN3loUmdmMGZXYUhyaDJUSkU1dSswVG5nODhX +ZE5nSEV6TlYwCjdtZXJwNEJvY1N2SmpaSGtlZlpwT0dwM3ZvSjlKbzNaTHBDMkt3 +OWUvSHcKLT4gOy4tZ3JlYXNlIGtUJ15rRHxSIE4gQnoKZFh5NGZrMjR6d0xEczNm +NgotLS0gRUs1NFdCL01Oc01JcmdkNmNyOXNpRXpyL3RZNExQM0RWQTZvYk0rckt6 +VQptmipZPk+F8euA2UNfb7h9MRSkCUfLeopA8L1af1cxr3X7rf/bLnmExqdDXbc+ +0Y9CAU1wUusZtxbh0gJHhBfYFJVjtnWxghMOaJYOq7sJY3CX9/XEo8KRfb1Uju9J +iRVNvzcAEoxo7YQwRm7NylJdEh2voo/e4VZUIQ== +-----END AGE ENCRYPTED FILE----- -- 2.56.0