From ee0ab982a18f979117d2d05b66bff84771153a35 Mon Sep 17 00:00:00 2001 From: Bendik Aagaard Lynghaug Date: Sun, 8 Nov 2026 13:32:28 +0100 Subject: [PATCH] Uten Kanidm: Rauthy er innloggingen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kanidm ut av stacken, bootstrap.sh, kanidm-setup.sh og kanidm/ borte. Rauthy er en vanlig tjeneste, ikke en profil, og deployen krever dens verdier i stedet for ID_HOST og KANIDM_API_TOKEN. Portalen får ingen KANIDM_* lenger, så kontoene lages i Rauthy. id.tomtervel.no sender videre til konto. Volumet kanidm_data blir liggende på kasse urørt. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01L5fbDmSQSb6u27EiEuwzoM --- .gitea/workflows/deploy.yml | 34 ++--- .gitignore | 4 - Caddyfile | 14 +- README.md | 250 +++++++++++------------------------- bootstrap.sh | 51 -------- compose.yml | 62 +++------ dns/README.md | 8 +- dns/dnsconfig.js | 13 +- host-caddy/tomtervel.no | 29 +---- kanidm-setup.sh | 202 ----------------------------- kanidm/server.toml.tpl | 30 ----- 11 files changed, 121 insertions(+), 576 deletions(-) delete mode 100755 bootstrap.sh delete mode 100755 kanidm-setup.sh delete mode 100644 kanidm/server.toml.tpl diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 2b7cf17..dff0502 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -20,7 +20,6 @@ on: - portal/** - gdo/** - nats/nats.conf - - kanidm/server.toml.tpl - rauthy/config.toml - deploy-tomtervel - .gitea/workflows/deploy.yml @@ -34,7 +33,6 @@ jobs: STAGE: /var/lib/gitea-runner/tomtervel-env # What the stack is. PORTAL_HOST: ${{ vars.PORTAL_HOST }} - ID_HOST: ${{ vars.ID_HOST }} CHAT_HOST: ${{ vars.CHAT_HOST }} PORTAL_RELEASE: ${{ vars.PORTAL_RELEASE }} GDO_RELEASE: ${{ vars.GDO_RELEASE }} @@ -55,7 +53,6 @@ jobs: NATS_PASSWORD: ${{ secrets.NATS_PASSWORD }} OAUTH2_CLIENT_SECRET: ${{ secrets.OAUTH2_CLIENT_SECRET }} CHAT_OAUTH2_CLIENT_SECRET: ${{ secrets.CHAT_OAUTH2_CLIENT_SECRET }} - KANIDM_API_TOKEN: ${{ secrets.KANIDM_API_TOKEN }} GARAGE_ACCESS_KEY: ${{ secrets.GARAGE_ACCESS_KEY }} GARAGE_SECRET_KEY: ${{ secrets.GARAGE_SECRET_KEY }} SEED_ADMIN_EMAIL: ${{ secrets.SEED_ADMIN_EMAIL }} @@ -64,10 +61,9 @@ jobs: # location field is two numbers). MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }} MAPBOX_STYLE: ${{ vars.MAPBOX_STYLE }} - # Optional: Rauthy beside or instead of Kanidm (README.md, "Rauthy"). - # RAUTHY_HOST and the three secrets run it (with `rauthy` in - # COMPOSE_PROFILES); OIDC_ISSUER moves portal's and the chat's - # sign-in to it; RAUTHY_API_KEY lets portal make accounts there. + # Who is who: Rauthy (README.md, "Rauthy"). RAUTHY_HOST and the + # three secrets run it; portal and the chat sign in at OIDC_ISSUER; + # RAUTHY_API_KEY lets portal make accounts there. RAUTHY_HOST: ${{ vars.RAUTHY_HOST }} RAUTHY_ENC_KEY: ${{ secrets.RAUTHY_ENC_KEY }} RAUTHY_SECRET_RAFT: ${{ secrets.RAUTHY_SECRET_RAFT }} @@ -86,12 +82,13 @@ jobs: - name: Write the env files run: | missing= - for v in PORTAL_HOST ID_HOST CHAT_HOST PORTAL_RELEASE GDO_RELEASE CNATS_TAG \ + for v in PORTAL_HOST CHAT_HOST RAUTHY_HOST OIDC_ISSUER PORTAL_RELEASE GDO_RELEASE CNATS_TAG \ KRON_RELEASE CONTENT_REPO CONTENT_BRANCH SITE_NAME PEOPLE_BACKEND \ RESPONSIBLE_GROUP OAUTH2_CLIENT_ID CHAT_OAUTH2_CLIENT_ID \ GARAGE_S3_ENDPOINT GARAGE_UPLOADS_BUCKET \ NATS_PASSWORD OAUTH2_CLIENT_SECRET CHAT_OAUTH2_CLIENT_SECRET \ - KANIDM_API_TOKEN GARAGE_ACCESS_KEY GARAGE_SECRET_KEY SEED_ADMIN_EMAIL; do + RAUTHY_ENC_KEY RAUTHY_SECRET_RAFT RAUTHY_SECRET_API RAUTHY_API_KEY \ + GARAGE_ACCESS_KEY GARAGE_SECRET_KEY SEED_ADMIN_EMAIL; do [ -n "${!v}" ] || missing="$missing $v" done [ -z "$missing" ] || { echo "not set as an Actions variable or secret:$missing"; exit 1; } @@ -101,7 +98,6 @@ jobs: # Interpolated by compose: hosts, versions, profiles. No secret. cat > "$STAGE/.env" < "$STAGE/portal.env" < "$STAGE/rauthy.env" < "$STAGE/rauthy.env" <> "$STAGE/rauthy.env" - fi + if [ -n "$RAUTHY_BOOTSTRAP_API_KEY" ]; then + printf 'BOOTSTRAP_API_KEY=%s\nBOOTSTRAP_API_KEY_SECRET=%s\n' \ + "$RAUTHY_BOOTSTRAP_API_KEY" "$RAUTHY_BOOTSTRAP_API_KEY_SECRET" >> "$STAGE/rauthy.env" fi - name: Pull and bring the stack up diff --git a/.gitignore b/.gitignore index 4b6f3ff..29a5ef3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,7 @@ .env portal.env chat.env -kanidm/server.toml -certs/ -.kanidm-recovered gitea-oauth.secret dns/cloudflare.env nats.env -kanidm-setup.secrets rauthy.env diff --git a/Caddyfile b/Caddyfile index a6653b5..e3fdef4 100644 --- a/Caddyfile +++ b/Caddyfile @@ -1,17 +1,11 @@ # Public TLS for both hosts, real certificates from Let's Encrypt over -# HTTP-01: the DNS A records for ${PORTAL_HOST} and ${ID_HOST} must +# HTTP-01: the DNS A records for ${PORTAL_HOST} and ${RAUTHY_HOST} must # point at this host before the first start. -{$ID_HOST} { - # Kanidm serves its own (internal, self-signed) TLS; verification is - # skipped on the inside hop only. - reverse_proxy kanidm:8443 { - transport http { - tls_insecure_skip_verify - } - } +{$RAUTHY_HOST} { + reverse_proxy rauthy:8080 log { - output file /data/id.log + output file /data/konto.log } } diff --git a/README.md b/README.md index 06427bf..d393edd 100644 --- a/README.md +++ b/README.md @@ -1,118 +1,71 @@ # Tomter Vel — infrastructure -Everything the vel's own site needs on one host, as containers: Caddy -for TLS, NATS with JetStream for the records, Kanidm for who is who, -and portal, the site itself. The content (pages, forms, desks) lives -in [tomtervel/questions](https://prosjekt.klingenbergbygg.no/tomtervel/questions) +Everything the vel's own site needs on one host, as containers: NATS +with JetStream for the records, Rauthy for who is who, portal, the site +itself, and the chat. The content (pages, forms, desks) lives in +[tomtervel/questions](https://prosjekt.klingenbergbygg.no/tomtervel/questions) and is fetched from there; this repo owns the host. ``` Internet ──► Caddy (Let's Encrypt) - ├── PORTAL_HOST ──► portal:3000 ──► NATS (records) + Kanidm (login) - └── ID_HOST ─────► kanidm:8443 (internal TLS) + ├── PORTAL_HOST ──► portal:3000 ──► NATS (records) + Rauthy (login) + ├── RAUTHY_HOST ──► rauthy:8080 + └── CHAT_HOST ────► cnats:3000 ``` -Today the vel's draft site runs on Klingenberg Bygg's host as -vel.klingenbergbygg.no, sharing that host's Kanidm and NATS. This repo -is the same site on a host of the vel's own, with a Kanidm of its own, -so nothing about the vel's members or records depends on anyone else. +Nothing about the vel's members or records depends on anyone else's +host: the login, the bus and the site are the vel's own. ## First start -On a fresh Linux host with podman + podman-compose and openssl (run rootful, -i.e. as root, so Caddy can bind 80/443 and Kanidm sees a stable source IP), -with a Gitea runner on it, and the variables and secrets below set -(`NATS_PASSWORD` is any long random string: `openssl rand -hex 24`): +On a fresh Linux host with podman + podman-compose (run rootful, so Caddy +can bind 80/443 and Rauthy sees a stable source IP), with a Gitea runner +on it, and the variables and secrets below set (`NATS_PASSWORD` is any +long random string: `openssl rand -hex 24`; Rauthy's are under +[Rauthy](#rauthy)): ```sh git clone https://prosjekt.klingenbergbygg.no/tomtervel/infrastructure /srv/tomtervel/infrastructure -cd /srv/tomtervel/infrastructure -sudo install -m 0755 deploy-tomtervel /usr/local/bin/deploy-tomtervel # and the sudoers line in it -sudo ID_HOST=id.tomtervel.no sh bootstrap.sh # Kanidm's config and certificate -# Actions -> deploy -> Run workflow # the env files, and the stack up -sudo sh bootstrap.sh # recovers the Kanidm admins, once -sh kanidm-setup.sh # the portal client and desk groups; set the two secrets it names +sudo install -m 0755 /srv/tomtervel/infrastructure/deploy-tomtervel /usr/local/bin/deploy-tomtervel # and the sudoers line in it +# Actions -> deploy -> Run workflow # the env files, and the stack up ``` -`bootstrap.sh` prints the `admin` and `idm_admin` passwords once; -write them down. After `kanidm-setup.sh`, https://PORTAL_HOST serves the -site and https://ID_HOST is the login. +Then make the clients and portal's API key in Rauthy ([Rauthy](#rauthy)). ## Running on kasse (behind the host Caddy) -The vel keeps its **own** Kanidm and NATS here so it can later lift onto a host -of its own unchanged — on kasse it just runs in isolation, fronted by kasse's -existing host Caddy (which owns 80/443). So the bundled Caddy stays off (it's -behind `profiles: [edge]`); run the default `podman compose up -d --build`. -The services publish loopback-only ports for the host Caddy to reach: +On kasse the host Caddy already owns 80/443, so the bundled Caddy stays +off (`profiles: [edge]`). The services publish loopback-only ports for +it, and `host-caddy/tomtervel.no` is its file for them +(`/etc/caddy/conf.d/tomtervel.no`): - portal → `127.0.0.1:3050` -- kanidm → `127.0.0.1:8443` (internal self-signed TLS) +- rauthy → `127.0.0.1:8090` +- cnats → `127.0.0.1:3070` - nats → `127.0.0.1:4223` (kasse's shared platform NATS owns 4222) -Add two host-Caddy site blocks in `/etc/caddy/conf.d/`, using the vel's `.env` -hosts (`vel.klingenbergbygg.no → :3050` already exists): +## Accounts and groups -``` - { - reverse_proxy localhost:3050 -} - { - reverse_proxy https://localhost:8443 { - transport http { tls_insecure_skip_verify } - } -} -``` +Rauthy holds the accounts: sign-in, passkeys, the account pages and the +account mail, in Norwegian. Portal and the chat sign in there +(`OIDC_ISSUER`), and portal makes the accounts there itself +(`RAUTHY_API_KEY`): -Then `sudo systemctl reload caddy`, point the content repo's `lint-and-reload` -reload step at `nats://127.0.0.1:4223`, and retire the old systemd portal: -`sudo systemctl disable --now app@tomtervel-portal`. - -## Accounts, all the way - -`kanidm-setup.sh` sets up everything portal needs from this Kanidm, -and is safe to rerun: - -- **Desk groups, named as the content names them.** Read from every - `qualifies:` under `questions/` in the content repo, so the list - cannot drift from the pages. This Kanidm is the vel's own, so there is - no prefix: the board's group is `styret`. Groups from before are - renamed in place (`tomtervel_styret` → `styret`), members and all. -- **Sign-in.** The OAuth2 client's scope map is `idm_all_persons`: - everyone here is the vel's, and what they see is decided by their - desk groups in the `groups` claim. -- **Onboarding.** The `portal-onboarding` service account manages - every desk group, so an invite from a desk and a `grants:` can add - people to them. Its token goes into `portal.env`. - **The first person in.** The `SEED_ADMIN_EMAIL` secret: at start, - portal invites them into the most privileged group (the board) and - mails the link, once. Everyone else they invite from their desk. + portal gives them the most privileged group (the board) and makes + their account; Rauthy mails them how to set a password or a passkey. + The same address is Rauthy's first admin. +- **Everyone else** is invited from a desk, or given a place by a case + (`grants:`). Portal makes the account if there is none, and Rauthy + mails the way in. - **The people who ask the questions.** Everyone a page names as - `responsible` gets an account at start, a mail saying they are listed - as responsible for asking that question, and a place in - `RESPONSIBLE_GROUP` (`redaktor`). Signed in, they can suggest changes - to their own pages. -- **The project Gitea.** With `GITEA_URL` set, `redaktor` may sign in - to it with the same account: its own OAuth2 client, only for that - group. Run on the Gitea host, the script adds the sign-in source - itself (and requires the `redaktor` claim there too); elsewhere it - leaves the secret in `gitea-oauth.secret` and prints the one command. + `responsible` gets an account at start and a place in + `RESPONSIBLE_GROUP` (`redaktor`). -## People and desks - -Each group in the content (`qualifies:` under `questions/`) is a -Kanidm group `tomtervel_`, all members of `tomtervel_members`. -Someone in `tomtervel_styret` logs in and sees the board's desk. - -```sh -kanidm -D idm_admin -H https://ID_HOST person create kari "Kari Lien" -kanidm -D idm_admin -H https://ID_HOST person update kari --mail kari@example.no -kanidm -D idm_admin -H https://ID_HOST person credential create-reset-token kari -kanidm -D idm_admin -H https://ID_HOST group add-members tomtervel_styret kari -``` - -Membership is read at login; someone added while logged in logs out -and in again. +The groups are portal's (`PEOPLE_BACKEND=memberships`): who is in +`styret` is on the board's desk, "Medlemmer og invitasjoner", where a +person is taken out or invited again. Portal decides what a group may +do, on the site and in the chat's rooms alike. ## Content changes @@ -144,86 +97,78 @@ Run workflow**. Set them with `gt` (`gt variable set NAME --body ...`, | name | kind | where | what | |---|---|---|---| -| `PORTAL_HOST`, `ID_HOST`, `CHAT_HOST` | variable | repo | the site, the login, the chat; each needs DNS (`dns/`) and a kasse Caddy block | +| `PORTAL_HOST`, `RAUTHY_HOST`, `CHAT_HOST` | variable | repo | the site, the login, the chat; each needs DNS (`dns/`) and a kasse Caddy block | | `PORTAL_RELEASE` | variable | **org** | a uhhm/portal tag; the content repo's lint reads the same one | | `GDO_RELEASE`, `CNATS_TAG`, `KRON_RELEASE` | variable | repo | the mailer, the chat, the money service | | `COMPOSE_PROFILES` | variable | repo | `chat` | | `CONTENT_REPO`, `CONTENT_BRANCH` | variable | repo | the content this site serves | | `SITE_NAME` | variable | repo | `tomtervel`; never changed (a new name is a new, empty site) | | `PEOPLE_BACKEND`, `RESPONSIBLE_GROUP` | variable | repo | `memberships`, `redaktor` | -| `OAUTH2_CLIENT_ID`, `CHAT_OAUTH2_CLIENT_ID` | variable | repo | the Kanidm clients of the site and the chat | +| `OAUTH2_CLIENT_ID`, `CHAT_OAUTH2_CLIENT_ID` | variable | repo | the Rauthy clients of the site and the chat: `portal`, `chat` | | `NATS_ADOPT_LEGACY` | variable | repo | `sole` | | `GARAGE_S3_ENDPOINT`, `GARAGE_UPLOADS_BUCKET` | variable | repo | uploads | | `NATS_PASSWORD` | secret | **org** | the stack's NATS; the content repo's reload uses it too | -| `OAUTH2_CLIENT_SECRET`, `KANIDM_API_TOKEN` | secret | repo | made by `kanidm-setup.sh`, which says how to set them | -| `CHAT_OAUTH2_CLIENT_SECRET` | secret | repo | the chat's Kanidm client | +| `OAUTH2_CLIENT_SECRET` | secret | repo | the site's Rauthy client | +| `CHAT_OAUTH2_CLIENT_SECRET` | secret | repo | the chat's Rauthy client | | `GARAGE_ACCESS_KEY`, `GARAGE_SECRET_KEY` | secret | repo | uploads | | `SEED_ADMIN_EMAIL`, `SEED_ADMIN_NAME` | secret | repo | the first person in; an address, so not a variable | | `CLOUDFLARE_API_TOKEN` | secret | repo | DNS edit for tomtervel.no only (`dns/`) | | `MAPBOX_TOKEN` | secret | repo | optional: the map tiles portal proxies (the landing hero, location fields); unset, maps are off | | `MAPBOX_STYLE` | variable | repo | optional: `/