# 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) 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) ``` 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. ## 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`): ```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 ``` `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. ## 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: - portal → `127.0.0.1:3050` - kanidm → `127.0.0.1:8443` (internal self-signed TLS) - 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): ``` { reverse_proxy localhost:3050 } { reverse_proxy https://localhost:8443 { transport http { tls_insecure_skip_verify } } } ``` 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. - **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. ## 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. ## Content changes A push to tomtervel/questions is linted on push and tells the portal to reload over NATS. That reload reaches the host it runs on: today Klingenberg Bygg's. On this host the runner is a **host service** (`pacman -S gitea-runner`, registered against prosjekt.klingenbergbygg.no) — not an in-compose container — so it reaches NATS on the published `127.0.0.1:4222`. Give the content repo's `lint-and-reload.yml` a reload job whose `runs-on` matches that runner's host label, running `nats --server nats://portal:$NATS_PASSWORD@127.0.0.1:4222 pub portal.content.reload ""`. Until then, `podman compose restart portal` picks up new content. ## Upgrading portal Set the org variable `PORTAL_RELEASE` (a tag of uhhm/portal) and run the deploy workflow. The content repo's lint reads the same variable, so the two cannot drift apart. ## Variables and secrets Every value the stack runs with is an Actions variable or secret in Gitea, never a file in the repo (it is public) and never edited on the host. The deploy workflow writes them into the env files on kasse (`.env`, `portal.env`, `nats.env`, `chat.env`) on every run, so a host name or a version is changed in Gitea, and then **Actions -> deploy -> Run workflow**. Set them with `gt` (`gt variable set NAME --body ...`, `gt secret set NAME`, `-o tomtervel` for the org's). | 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_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 | | `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 | | `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: `/