# Tomter Vel — infrastructure 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) + Rauthy (login) ├── RAUTHY_HOST ──► rauthy:8080 └── CHAT_HOST ────► cnats:3000 ``` 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 (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 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 ``` Then make the clients and portal's API key in Rauthy ([Rauthy](#rauthy)). ## Running on kasse (behind the host Caddy) 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` - 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) ## Accounts and groups 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`): - **The first person in.** The `SEED_ADMIN_EMAIL` secret: at start, 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 and a place in `RESPONSIBLE_GROUP` (`redaktor`). The groups are kept in Rauthy (`PEOPLE_BACKEND=rauthy`): an invite puts the person in the group there, and an invite is a case in `portal_invites` until they come. 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. Records in `portal_memberships` are left from before (Kanidm); nothing new is written there. ## 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`, `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 | `rauthy`, `redaktor` | | `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` | 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: `/