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.
This commit is contained in:
1 parent
0a8c98f76f
commit
529342ab39
5 files changed
+92
-4
No files matched your search
@@ -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/<matrix-id>`.
|
||||
2. Send a `PUT` for that account with the existing `external_ids` plus
|
||||
`{"auth_provider":"oidc-pocket-id","external_id":"<Pocket ID subject>"}`.
|
||||
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
|
||||
|
||||
@@ -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` | `<host>.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** |
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
-----BEGIN AGE ENCRYPTED FILE-----
|
||||
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IFpCM2U2USAwZG9S
|
||||
UStBWHJGTjdYWG5kNkE0SFhObDBVVzRXcjBjaWdDMVNhQmN0aENRCm1xYnRURUtr
|
||||
T3ZldWxxVjR3cFdoRlhLRzhYT250RWJFc3F1eDN1TlJMOGMKLT4gc3NoLWVkMjU1
|
||||
MTkgVkZjdzVnIDY1VDRNS1l5QTR5MnhCTHZmY1FkQ1pUNXJhdGtVWUtnUGpZUnJN
|
||||
dnFmd2MKbVpzd21wcndEVnNOaTdVTkZ3ajZNZ2pMQTRueERJZitQREZyamRPcURv
|
||||
awotPiBYMjU1MTkgM3ZQMTJjVGthb2JkL3VEUFRSSWJ5TWlYc0M1djFzVG41ckdF
|
||||
SEQxemNBUQovK0YxZU0wOUxPSkZ2Z3BVb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