middleman: Replace nginx-sso with Pocket ID SSO
Gate the vhosts without their own sign-in with oauth2-proxy, which signs in with Pocket ID and allows members of the `admins` group. Each gated vhost serves its own `/oauth2/` endpoints with a host-only session cookie, so other `.nul.ie` sites never receive it. Sessions last a week, and a refresh token lets oauth2-proxy check back with Pocket ID every hour without a passkey. Add `my.pocket-id`, which declares Pocket ID groups and OIDC clients in Nix; `pocket-id-sync` applies them through the API with a static API key that nginx keeps from outside requests. This lets apps move to Pocket ID with their client defined next to them, with secrets from `slop secret generate`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #12.
This commit is contained in:
1 parent
a3950b9bb3
commit
eeb1f2d15c
14 files changed
+514
-325
No files matched your search
+1
-1
@@ -42,7 +42,7 @@ Physical host and public-infrastructure hub — see [`sites/colony/README.md`](s
|
||||
```
|
||||
colony (physical VM host, ams1)
|
||||
├── estuary ── edge router: WAN, firewall/NAT, DNS, BGP (AS211024), WireGuard
|
||||
├── shill ──── NixOS container host ──┬── middleman (reverse proxy, ACME, nginx-sso, librespeed)
|
||||
├── shill ──── NixOS container host ──┬── middleman (reverse proxy, ACME, Pocket ID, librespeed)
|
||||
│ ├── vaultwarden (password manager)
|
||||
│ ├── colony-psql (shared PostgreSQL)
|
||||
│ ├── chatterbox (Matrix Synapse + bridges)
|
||||
|
||||
@@ -187,7 +187,7 @@ descriptions) see [`reference/nixos-options.md`](reference/nixos-options.md).
|
||||
| `vms` | `my.vms.instances` — QEMU/KVM VMs as systemd units: TAP/bridge networking, LVM-backed disks, VFIO host-device passthrough (with udev tagging), UEFI, SPICE/TTY/QMP unix sockets under `/run/vms/`, clean shutdown via QMP `system_powerdown`. |
|
||||
| `network` | Baseline networking: networkd only (`useDHCP = false`), IPv6 on, resolved domain/negative-cache settings; dev VMs get DHCP on `eth0` and an SSH port forward. |
|
||||
| `pdns` | `my.pdns` — PowerDNS: authoritative server driven by BIND-style zone files (with templating and serial management) and recursor extra-settings wiring. |
|
||||
| `nginx-sso` | `my.nginx-sso` — runs `nginx-sso` (instead of the stock NixOS module) and generates per-instance nginx `auth_request` include files. |
|
||||
| `pocket-id` | `my.pocket-id` — Pocket ID with user groups and OIDC clients declared in Nix; `pocket-id-sync` applies them through the API with a static API key. |
|
||||
| `gui` | `my.gui.enable` (default on) — desktop baseline: graphics, polkit, swaylock PAM entry, Android udev rules, screenshot tmpdir. |
|
||||
| `l2mesh` | Consumes `nixos.vpns.l2` — builds the VXLAN + IPsec layer-2 meshes between edge routers; see [networking.md](networking.md). |
|
||||
| `borgthin` | `my.borgthin.jobs` — borg backups of thin-LVM snapshots to local or SSH repos on a systemd timer, with pruning. |
|
||||
|
||||
@@ -48,7 +48,7 @@ their current addresses. Each container has its own page:
|
||||
|
||||
| Container | Role |
|
||||
|---|---|
|
||||
| [`middleman`](containers/middleman.md) | Reverse proxy, ACME, nginx-sso, librespeed, Paseo relay |
|
||||
| [`middleman`](containers/middleman.md) | Reverse proxy, ACME, Pocket ID and SSO, librespeed, Paseo relay |
|
||||
| [`vaultwarden`](containers/vaultwarden.md) | Password manager |
|
||||
| [`colony-psql`](containers/colony-psql.md) | Shared PostgreSQL (14) |
|
||||
| [`chatterbox`](containers/chatterbox.md) | Matrix Synapse + bridges |
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
The front-end reverse proxy for the colony's public web services — the single ingress that
|
||||
`estuary` DNATs HTTP/HTTPS (and Matrix federation on `:8448`) to. Terminates TLS with wildcard
|
||||
certificates it issues itself, provides nginx-sso for gated vhosts, and runs the Pocket ID
|
||||
identity provider, a librespeed backend and a Paseo relay.
|
||||
certificates it issues itself, runs the Pocket ID identity provider with oauth2-proxy in front of
|
||||
gated vhosts, and runs a librespeed backend and a Paseo relay.
|
||||
|
||||
- **Source:** [`shill/containers/middleman/`](../../../../../nixos/boxes/colony/vms/shill/containers/middleman)
|
||||
(`default.nix`, `vhosts.nix`)
|
||||
(`default.nix`, `auth.nix`, `vhosts.nix`)
|
||||
- **Host:** NixOS container on [`shill`](../README.md) (`my.containers` ephemeral nspawn on the
|
||||
`ctrs` bridge; bind-mounts `/mnt/media` read-only for the static file vhosts)
|
||||
- **nixpkgs:** `mine`
|
||||
@@ -32,24 +32,51 @@ also waits for `colony-psql` through `systemdAwaitPostgres`, avoiding an early-b
|
||||
`mailcow-ssl-reload` there.
|
||||
- Renewal reloads nginx; the `acme` group owns the secret files and includes the nginx user.
|
||||
|
||||
### nginx-sso
|
||||
|
||||
The `generic` SSO instance at `sso.nul.ie` uses Google OAuth by default and also offers a simple
|
||||
username/password provider. Its cookie domain is `.nul.ie`; gated vhosts include the generated
|
||||
`server-generic.conf` / `location-generic.conf` snippets from `/etc/nginx/includes/sso/`.
|
||||
|
||||
### Pocket ID
|
||||
|
||||
[Pocket ID](https://pocket-id.org) (`services.pocket-id`) is a passkey-only OpenID Connect
|
||||
provider at `id.nul.ie`, for apps that sign in with OIDC (first the `slop-broker` approvals web
|
||||
app, see [`slop-broker.md`](../../../../slop-broker.md#approvals-web-app)). It is meant to replace nginx-sso's
|
||||
Google sign-in later, with oauth2-proxy in front of apps that lack OIDC.
|
||||
provider at `id.nul.ie`. Apps with OIDC support sign in with it directly (such as the
|
||||
[`slop-broker` approvals web app](../../../../slop-broker.md#approvals-web-app)); the rest go
|
||||
through [oauth2-proxy](#sso).
|
||||
|
||||
- Listens on `127.0.0.1:1411` behind nginx and keeps its SQLite database in `/var/lib/pocket-id`
|
||||
(persisted by `my.tmproot`). The `middleman/pocket-id-encryption-key` secret encrypts it.
|
||||
- The first admin is created at `/setup`; nginx only allows that page and its API from
|
||||
internal networks (`lib.my.c.internalNets`). Further users are added from the admin UI.
|
||||
|
||||
**Declared groups and clients.** `my.pocket-id` (in
|
||||
[`auth.nix`](../../../../../nixos/boxes/colony/vms/shill/containers/middleman/auth.nix)) declares
|
||||
user groups and OIDC clients; `pocket-id-sync` creates and updates them through the API on every
|
||||
switch.
|
||||
|
||||
- It authenticates with the static API key `middleman/pocket-id-api-key`. nginx strips
|
||||
`X-API-Key` from outside requests, so API keys only work from inside the container.
|
||||
- Clients and groups that aren't declared are left alone, as is group membership: add users to
|
||||
groups in the admin UI.
|
||||
- A client's secret is an age file shared with the box that runs the app (or a key of an env
|
||||
file). Generate it with `slop secret generate`; after rotating one, restart `pocket-id-sync`.
|
||||
|
||||
### SSO
|
||||
|
||||
[oauth2-proxy](https://oauth2-proxy.github.io/oauth2-proxy/) signs users in with Pocket ID (client
|
||||
`sso`) for vhosts with no sign-in of their own.
|
||||
|
||||
- `ssoServer [ <groups> ]` in `vhosts.nix` gates a vhost with nginx `auth_request`, allowing
|
||||
members of any of the given Pocket ID groups. The gated vhosts currently allow `admins`.
|
||||
- Each gated vhost serves oauth2-proxy's `/oauth2/` endpoints itself. Its session cookie is
|
||||
host-only, so other `.nul.ie` sites (including `*.slop.nul.ie` previews) never receive it.
|
||||
Pocket ID's own session turns signing in to another gated vhost into a redirect.
|
||||
- The `sso` client's callback URLs are derived from the gated vhosts.
|
||||
- Sessions last a week. Every hour, oauth2-proxy uses a refresh token to check back with Pocket
|
||||
ID without a passkey, and picks up the user's current groups. A disabled user is signed out at
|
||||
the next check; someone removed from a group loses access once their access token expires (an
|
||||
hour at most, Pocket ID's default).
|
||||
- A location in a gated vhost with its own `add_header` would drop the refreshed session cookie
|
||||
that `ssoServer` passes on.
|
||||
- Its client secret and cookie secret are in the env file `middleman/oauth2-proxy.env`.
|
||||
- `id.nul.ie` resolves to the container itself, so oauth2-proxy reaches Pocket ID through the
|
||||
local nginx.
|
||||
|
||||
### librespeed
|
||||
|
||||
The frontend and backend are published as `speed.nul.ie` and `librespeed.ams1.int.nul.ie`, both
|
||||
@@ -80,14 +107,13 @@ rewrites outbound IPv6 to the container's own address on `host0`.
|
||||
## Published vhosts
|
||||
|
||||
Everything is under `*.nul.ie` with the public wildcard cert unless noted; defaults applied to
|
||||
all vhosts are `onlySSL`, kTLS and HTTP/2. "SSO" = gated behind nginx-sso (`generic` instance).
|
||||
all vhosts are `onlySSL`, kTLS and HTTP/2. "SSO" = gated behind [oauth2-proxy](#sso).
|
||||
|
||||
| Host | Upstream | Notes |
|
||||
| --- | --- | --- |
|
||||
| `nul.ie` (`_`, default) | static | landing page (`index.html`, CV PDF, SSH pubkey); serves Matrix `.well-known`s and redirects `webfinger`/`nodeinfo`/`host-meta` → `toot.nul.ie`, `atproto-did` → `pds.nul.ie`; `forceSSL` (plain HTTP redirects to HTTPS) |
|
||||
| `localhost` | — | loopback-only VTS status page at `/status` (scraped by netdata); plain HTTP |
|
||||
| `sso.nul.ie` | `localhost:8082` | nginx-sso endpoint |
|
||||
| `id.nul.ie` | `localhost:1411` | Pocket ID; `/setup` only from internal networks |
|
||||
| `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 |
|
||||
@@ -122,6 +148,7 @@ all vhosts are `onlySSL`, kTLS and HTTP/2. "SSO" = gated behind nginx-sso (`gene
|
||||
|
||||
## Notable config files
|
||||
|
||||
- [`nixos/boxes/colony/vms/shill/containers/middleman/default.nix`](../../../../../nixos/boxes/colony/vms/shill/containers/middleman/default.nix) — container definition: nginx, ACME, nginx-sso, Pocket ID, librespeed, Paseo relay, secrets
|
||||
- [`nixos/boxes/colony/vms/shill/containers/middleman/vhosts.nix`](../../../../../nixos/boxes/colony/vms/shill/containers/middleman/vhosts.nix) — all virtual hosts, the SSO include helpers, and the `.well-known` tree
|
||||
- [`nixos/boxes/colony/vms/shill/containers/middleman/default.nix`](../../../../../nixos/boxes/colony/vms/shill/containers/middleman/default.nix) — container definition: nginx, ACME, librespeed, Paseo relay, secrets
|
||||
- [`nixos/boxes/colony/vms/shill/containers/middleman/auth.nix`](../../../../../nixos/boxes/colony/vms/shill/containers/middleman/auth.nix) — Pocket ID, its declared groups and clients, oauth2-proxy
|
||||
- [`nixos/boxes/colony/vms/shill/containers/middleman/vhosts.nix`](../../../../../nixos/boxes/colony/vms/shill/containers/middleman/vhosts.nix) — all virtual hosts, the `ssoServer` helper, and the `.well-known` tree
|
||||
- [`nixos/boxes/colony/vms/shill/containers/middleman/default.html`](../../../../../nixos/boxes/colony/vms/shill/containers/middleman/default.html) — default vhost landing page
|
||||
Reference in new issue
Block a user