diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 1cd6e44..aa7f51b 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -2,7 +2,8 @@ # Actions variable (vars.*: hosts, versions, where the content comes from) # or secret (secrets.*: passwords, tokens, the first person's address) of # this repo, or of the tomtervel org for what other repos share -# (NATS_PASSWORD, which the content repo's reload uses too). The table is +# (LOAD_TOKEN, which the content repo's reload posts to the site, and +# PORTAL_RELEASE, which its lint runs). The table is # in README.md. A new host name or a portal bump is a variable changed and # then Run workflow; a change to the files here deploys on push. # @@ -21,7 +22,6 @@ on: - gdo/** - rauthy-providers.sh - rauthy-theme.sh - - nats/nats.conf - rauthy/config.toml - deploy-tomtervel - .gitea/workflows/deploy.yml @@ -35,11 +35,9 @@ jobs: STAGE: /var/lib/gitea-runner/tomtervel-env # What the stack is. PORTAL_HOST: ${{ vars.PORTAL_HOST }} - CHAT_HOST: ${{ vars.CHAT_HOST }} PAY_HOST: ${{ vars.PAY_HOST }} PORTAL_RELEASE: ${{ vars.PORTAL_RELEASE }} GDO_RELEASE: ${{ vars.GDO_RELEASE }} - CNATS_TAG: ${{ vars.CNATS_TAG }} KRON_RELEASE: ${{ vars.KRON_RELEASE }} COMPOSE_PROFILES: ${{ vars.COMPOSE_PROFILES }} CONTENT_REPO: ${{ vars.CONTENT_REPO }} @@ -48,14 +46,24 @@ jobs: PEOPLE_BACKEND: ${{ vars.PEOPLE_BACKEND }} RESPONSIBLE_GROUP: ${{ vars.RESPONSIBLE_GROUP }} OAUTH2_CLIENT_ID: ${{ vars.OAUTH2_CLIENT_ID }} - CHAT_OAUTH2_CLIENT_ID: ${{ vars.CHAT_OAUTH2_CLIENT_ID }} - NATS_ADOPT_LEGACY: ${{ vars.NATS_ADOPT_LEGACY }} GARAGE_S3_ENDPOINT: ${{ vars.GARAGE_S3_ENDPOINT }} GARAGE_UPLOADS_BUCKET: ${{ vars.GARAGE_UPLOADS_BUCKET }} + # The programs beside the site (README.md, "The site's own + # network"): each one's key and what it may do, and the site's own + # key and where it listens. Public keys, said in the logs; set + # once, from what move-1.0/move.sh prints. + DHD_KEYS: ${{ vars.DHD_KEYS }} + PORTAL_DHD: ${{ vars.PORTAL_DHD }} + # Optional: sealed copies of the site's store, every six hours + # (README.md, "Backups"). PORTAL_BACKUP_TO is an age public key + # whose private half is kept off this host. + PORTAL_BACKUP_TO: ${{ vars.PORTAL_BACKUP_TO }} + GARAGE_BACKUPS_BUCKET: ${{ vars.GARAGE_BACKUPS_BUCKET }} # What it runs with. - NATS_PASSWORD: ${{ secrets.NATS_PASSWORD }} + # The token the content repo's reload posts; the site is given + # its hash alone. + LOAD_TOKEN: ${{ secrets.LOAD_TOKEN }} OAUTH2_CLIENT_SECRET: ${{ secrets.OAUTH2_CLIENT_SECRET }} - CHAT_OAUTH2_CLIENT_SECRET: ${{ secrets.CHAT_OAUTH2_CLIENT_SECRET }} GARAGE_ACCESS_KEY: ${{ secrets.GARAGE_ACCESS_KEY }} GARAGE_SECRET_KEY: ${{ secrets.GARAGE_SECRET_KEY }} SEED_ADMIN_EMAIL: ${{ secrets.SEED_ADMIN_EMAIL }} @@ -65,7 +73,7 @@ jobs: MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }} MAPBOX_STYLE: ${{ vars.MAPBOX_STYLE }} # Who is who: Rauthy (README.md, "Rauthy"). RAUTHY_HOST and the - # three secrets run it; portal and the chat sign in at OIDC_ISSUER; + # three secrets run it; portal signs in at OIDC_ISSUER; # RAUTHY_API_KEY lets portal make accounts there. RAUTHY_HOST: ${{ vars.RAUTHY_HOST }} RAUTHY_ENC_KEY: ${{ secrets.RAUTHY_ENC_KEY }} @@ -80,10 +88,8 @@ jobs: RAUTHY_API_KEY: ${{ secrets.RAUTHY_API_KEY }} RAUTHY_LANGUAGE: ${{ vars.RAUTHY_LANGUAGE }} # The money service (README.md, "Payments"): Vipps's keys for the - # Medlemskap sales unit, read by kron alone. Unset, kron starts - # without them and asks for them on the treasurer's desk - # ("Tjenester som venter"), sealed to its own identity; set, they - # are kron's from the env. VIPPS_WEBHOOK_SECRET may wait, kron + # Medlemskap sales unit, read by kron alone, from its env: with + # all four set kron asks the site for nothing. VIPPS_WEBHOOK_SECRET may wait, kron # then settles by asking Vipps every minute instead. VIPPS_MSN: ${{ vars.VIPPS_MSN }} VIPPS_CLIENT_ID: ${{ secrets.VIPPS_CLIENT_ID }} @@ -101,11 +107,11 @@ jobs: - name: Write the env files run: | missing= - for v in PORTAL_HOST CHAT_HOST RAUTHY_HOST OIDC_ISSUER PORTAL_RELEASE GDO_RELEASE CNATS_TAG \ + for v in PORTAL_HOST RAUTHY_HOST OIDC_ISSUER PORTAL_RELEASE GDO_RELEASE \ KRON_RELEASE CONTENT_REPO CONTENT_BRANCH SITE_NAME PEOPLE_BACKEND \ - RESPONSIBLE_GROUP OAUTH2_CLIENT_ID CHAT_OAUTH2_CLIENT_ID \ + RESPONSIBLE_GROUP OAUTH2_CLIENT_ID \ GARAGE_S3_ENDPOINT GARAGE_UPLOADS_BUCKET \ - NATS_PASSWORD OAUTH2_CLIENT_SECRET CHAT_OAUTH2_CLIENT_SECRET \ + DHD_KEYS PORTAL_DHD LOAD_TOKEN OAUTH2_CLIENT_SECRET \ 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" @@ -125,20 +131,21 @@ jobs: # Interpolated by compose: hosts, versions, profiles. No secret. cat > "$STAGE/.env" < "$STAGE/portal.env" <> "$STAGE/portal.env" + echo "PAY_URL=http://127.0.0.1:3080" >> "$STAGE/portal.env" fi - # NATS itself (nats.conf reads NATS_PASSWORD), gdo and the chat. - cat > "$STAGE/nats.env" < "$STAGE/chat.env" <> "$STAGE/portal.env" + fi + # kron: Vipps's keys for the Medlemskap sales unit (kron refuses + # some set and some not). Written even without the profile, so + # the file compose names is there. { echo "WEBHOOK_SECRET=$VIPPS_WEBHOOK_SECRET" for name in VIPPS_MSN VIPPS_CLIENT_ID VIPPS_CLIENT_SECRET VIPPS_SUBSCRIPTION_KEY; do @@ -208,7 +207,7 @@ jobs: # "$$" is compose's literal "$". Without this, RAUTHY_API_KEY reached # portal as "portal" alone, Rauthy answered 401, and every invite # failed. .env is left alone: it is what compose.yml interpolates. - sed -i 's/\$/$$/g' "$STAGE/portal.env" "$STAGE/nats.env" "$STAGE/chat.env" "$STAGE/rauthy.env" "$STAGE/kron.env" + sed -i 's/\$/$$/g' "$STAGE/portal.env" "$STAGE/rauthy.env" "$STAGE/kron.env" - name: Pull and bring the stack up run: sudo /usr/local/bin/deploy-tomtervel diff --git a/README.md b/README.md index c27028d..a3deef9 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,34 @@ # 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 +Everything the vel's own site needs on one host, as containers: portal, +the site itself, which keeps its records in one file of its own; Rauthy +for who is who; gdo for its mail and kron for Vipps. 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 + ├── PORTAL_HOST ──► portal:3000 ──► its store (portal_data) + Rauthy (login) + ├── RAUTHY_HOST ──► rauthy:8080 ▲ dhd/1, on loopback + └── PAY_HOST ─────► kron:3080 ───────────┤ + gdo ─────────────────┘──► the host's mail server ``` 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. +host: the login and the site are the vel's own. + +The site ran portal 0.19 on NATS until the move to 1.0, which +`move-1.0/` is. The chat (cnats) spoke to portal over NATS and went +with it; the one that dials a 1.0 site (uhhm/kino) has no image yet. ## 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 +on it, and the variables and secrets below set (`LOAD_TOKEN` is any long random string: `openssl rand -hex 24`; Rauthy's are under -[Rauthy](#rauthy)): +[Rauthy](#rauthy); the keys are under [The site's own network](#the-sites-own-network)): ```sh git clone https://prosjekt.klingenbergbygg.no/tomtervel/infrastructure /srv/tomtervel/infrastructure @@ -40,14 +46,13 @@ it, and `host-caddy/tomtervel.no` is its file for them (`/etc/caddy/conf.d/tomtervel.no`): - portal → `127.0.0.1:3050` +- kron → `127.0.0.1:3080` - 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 +account mail, in Norwegian. Portal signs in there (`OIDC_ISSUER`), and portal makes the accounts there itself (`RAUTHY_API_KEY`): @@ -72,15 +77,36 @@ rooms alike. Records in `portal_memberships` are left from before ## 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. +A push to tomtervel/questions is linted, and its CI then asks the site +to load that commit: `POST https:///dhd/1/load` with the +org secret `LOAD_TOKEN`. The site fetches the commit, checks it whole +and swaps it in; if anything fails, the last good content goes on +serving, and the answer says why. The site is given the token's hash +alone (`DHD_TOKENS`, written by the deploy). It also reads the branch's +head every time it starts. + +## The site's own network + +gdo and kron dial the site over `dhd/1`; the site dials no one. They +know each other by key: + +- **The site's key** is `site.key` beside its store, made the first + time a program is named. gdo and kron are told it, and where the site + listens, as `PORTAL_DHD=@127.0.0.1:4300`. +- **Each program's key** is in its own volume (`gdo_data`, `kron_data`), + made the first time it starts. The site names them, and what each may + do, in `DHD_KEYS==mail,note;=payments`. + +Both are Actions variables (public keys; every start says them in the +log). `move-1.0/move.sh` makes the keys and prints the two values. A +program whose volume is lost gets a new key, which the site does not +know until `DHD_KEYS` names it: read it from the program's log. + +They dial from loopback to loopback, so portal, gdo and kron share one +network namespace, which the `net` container holds (`compose.yml` says +why it is not portal's own). Tried on kasse, 2026-11-24: after a restart +of portal, and after it was made anew, gdo and kron dialled again within +half a minute and the mail and the payment that had waited went through. ## Upgrading portal @@ -93,26 +119,26 @@ two cannot drift apart. 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 +(`.env`, `portal.env`, `kron.env`, `rauthy.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_HOST`, `RAUTHY_HOST` | variable | repo | the site, the login; 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` | +| `GDO_RELEASE`, `KRON_RELEASE` | variable | repo | the mailer, a tag or a commit of uhhm/gdo that the image is built from (`gdo/Dockerfile` says why), and the money service's image tag (`0.3.0` and on): the ones that dial a 1.0 site | +| `COMPOSE_PROFILES` | variable | repo | `pay` | +| `DHD_KEYS`, `PORTAL_DHD` | variable | repo | the programs' keys and what each may do, and the site's key and address ([The site's own network](#the-sites-own-network)) | +| `PORTAL_BACKUP_TO`, `GARAGE_BACKUPS_BUCKET` | variable | repo | optional: an age public key and a bucket, for sealed copies of the store ([Backups](#backups)) | | `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) | +| `SITE_NAME` | variable | repo | `tomtervel`; never changed (kron and the mail name the site by it) | | `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` | +| `OAUTH2_CLIENT_ID` | variable | repo | the site's Rauthy client: `portal` | | `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 | +| `LOAD_TOKEN` | secret | **org** | what the content repo's reload posts to the site; the site gets its hash | | `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/`) | @@ -120,13 +146,13 @@ Run workflow**. Set them with `gt` (`gt variable set NAME --body ...`, | `MAPBOX_STYLE` | variable | repo | optional: `/