Files
infrastructure/README.md
T

360 lines
19 KiB
Markdown
Raw Normal View History

# Tomter Vel — infrastructure
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
2026-11-08 13:32:28 +01:00
[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 ──► its store (portal_data) + Rauthy (login)
├── RAUTHY_HOST ──► rauthy:8080 ▲ dhd/1, on loopback
└── PAY_HOST ─────► kron:3080 ───────────┤
gdo ─────────────────┘──► the host's mail server
```
2026-11-08 13:32:28 +01:00
Nothing about the vel's members or records depends on anyone else's
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
2026-11-08 13:32:28 +01:00
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 (`LOAD_TOKEN` is any
2026-11-08 13:32:28 +01:00
long random string: `openssl rand -hex 24`; Rauthy's are under
[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
2026-11-08 13:32:28 +01:00
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
```
2026-11-08 13:32:28 +01:00
Then make the clients and portal's API key in Rauthy ([Rauthy](#rauthy)).
## Running on kasse (behind the host Caddy)
2026-11-08 13:32:28 +01:00
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`
- kron → `127.0.0.1:3080`
2026-11-08 13:32:28 +01:00
- rauthy → `127.0.0.1:8090`
2026-11-08 13:32:28 +01:00
## Accounts and groups
2026-11-08 13:32:28 +01:00
Rauthy holds the accounts: sign-in, passkeys, the account pages and the
account mail, in Norwegian. Portal signs in there
2026-11-08 13:32:28 +01:00
(`OIDC_ISSUER`), and portal makes the accounts there itself
(`RAUTHY_API_KEY`):
- **The first person in.** The `SEED_ADMIN_EMAIL` secret: at start,
2026-11-08 13:32:28 +01:00
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
2026-11-08 13:32:28 +01:00
`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, and its CI then asks the site
to load that commit: `POST https://<PORTAL_HOST>/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=<site key>@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=<gdo's key>=mail,note;<kron's key>=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
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`, `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` | 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`, `KRON_RELEASE` | variable | repo | the mailer's version as the [uhhm] registry has it (`v0.4.0` and on; the build fails when the registry's is another), 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 (kron and the mail name the site by it) |
| `PEOPLE_BACKEND`, `RESPONSIBLE_GROUP` | variable | repo | `rauthy`, `redaktor` |
| `OAUTH2_CLIENT_ID` | variable | repo | the site's Rauthy client: `portal` |
| `GARAGE_S3_ENDPOINT`, `GARAGE_UPLOADS_BUCKET` | variable | repo | uploads |
| `LOAD_TOKEN` | secret | **org** | what the content repo's reload posts to the site; the site gets its hash |
2026-11-08 13:32:28 +01:00
| `OAUTH2_CLIENT_SECRET` | secret | repo | the site'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: `<owner>/<style>`; unset, `mapbox/streets-v12` |
| `DNSCONTROL_VERSION` | variable | repo | the DNS workflow's dnscontrol |
2026-11-08 13:32:28 +01:00
| `RAUTHY_ENC_KEY`, `RAUTHY_SECRET_RAFT`, `RAUTHY_SECRET_API` | secret | repo | Rauthy's own: made once, never changed (the key encrypts its database) |
| `OIDC_ISSUER` | variable | repo | where the site signs in: `https://konto.tomtervel.no/auth/v1/` |
| `RAUTHY_BOOTSTRAP_API_KEY`, `RAUTHY_BOOTSTRAP_API_KEY_SECRET` | secret | repo | optional, Rauthy's first start only: a short-lived key (base64 of `{"name","exp","access"}`, secret 64+ alphanumerics) that makes the OIDC clients through the API; read into an empty database, ignored after |
2026-11-08 13:32:28 +01:00
| `RAUTHY_API_KEY`, `RAUTHY_LANGUAGE` | secret, variable | repo | portal makes accounts in Rauthy (`<name>$<secret>`, made in Rauthy's admin), in `nb` |
| `VIPPS_LOGIN_CLIENT_ID`, `VIPPS_LOGIN_CLIENT_SECRET` | variable, secret | repo | Vipps Login (the login sales unit's keys from portal.vippsmobilepay.no): the deploy keeps Vipps as a sign-in provider in Rauthy with them (`rauthy-providers.sh`) |
| `PAY_HOST` | variable | repo | where the money service answers: `betaling.tomtervel.no` (DNS in `dns/`, a kasse Caddy block) |
| `VIPPS_MSN` | variable | repo | the Medlemskap sales unit's merchant serial number, `1192072` |
| `VIPPS_CLIENT_ID`, `VIPPS_CLIENT_SECRET`, `VIPPS_SUBSCRIPTION_KEY` | secret | repo | the Medlemskap sales unit's ePayment keys (For developers, API keys, production), read by kron alone. With all four set kron asks the site for nothing |
| `VIPPS_WEBHOOK_SECRET` | secret | repo | what Vipps signs its webhooks with, from `vipps-webhook.sh register`; unset, kron refuses webhooks and asks Vipps about each open payment every minute instead |
A variable is printed wherever a workflow echoes it, and this repo's run
logs are public: a value that must not be read is a secret.
2026-11-08 13:32:28 +01:00
What is not a value stays on the host, made there once: Garage's node
secret.
## Colours in Rauthy
`rauthy-theme.sh` puts the site's palette (custom.css in the content
repo) on Rauthy's sign-in, account and admin pages, for Rauthy's own
client and the portal's, on every deploy. It needs the portal API key to
have Clients read and update; until it does, the step says so and
changes nothing, and the theme can be set by hand in the admin
(Clients, the client, Branding).
## Payments
The money service is [kron](https://project.uhhm.no/uhhm/kron), in the
stack under the `pay` profile (`COMPOSE_PROFILES=pay`). Portal
decides when money is owed: a household entering `open` or `fornyes` in
the content's aggregates owes the fee, and the request waits in the
site's `payments` outbox. kron dials the site, takes it, and answers
with a link of its own,
`https://betaling.tomtervel.no/pay/<reference>`, which portal shows on
the person's own page and mails; opening it makes a Vipps payment for
the Medlemskap sales unit and sends the person into Vipps, and a fresh
one each time the last ran out (Vipps's own expire after ten minutes).
Once they have paid, kron captures the reserved amount and tells the
site `paid`; portal moves the household to `betalt`, grants
`medlemmer`, and mails them. Vipps's keys live in `kron.env`: with all
four set kron asks the site for nothing. (kron can ask the site's
owners for them instead; that way is not tried here.) Portal never
holds a value and never calls Vipps. kron's ledger of what is being
paid is `kron.redb` in the `kron_data` volume. `PAY_URL` in
`portal.env` is what lets the content leave `by_hand: true` out of a
`payment:`; portal never calls that address either.
Going live, in order:
1. Set `PAY_HOST`, and the keys: `VIPPS_MSN` and the three key
secrets (table above; in `pass` as `tomtervel/vipps/medlemskap`). The host
script must know `kron.env` (this repo's `deploy-tomtervel`, optional
files): on kasse, `sudo install -m 0755 -o root -g root
/srv/tomtervel/infrastructure/deploy-tomtervel /usr/local/bin/deploy-tomtervel`
after the pull, since the installed copy does not update itself.
2. Merge the DNS record (`dns/dnsconfig.js`, `betaling`) and run the DNS
workflow; add the `betaling.tomtervel.no` block from
`host-caddy/tomtervel.no` to kasse's Caddy.
3. Set `COMPOSE_PROFILES=pay` and `KRON_RELEASE` (a uhhm/kron
version, `0.1.0`: the image is project.uhhm.no/uhhm/kron), then Run
workflow. `https://betaling.tomtervel.no/healthz`
answers `ok`.
4. Register the webhook: `./vipps-webhook.sh register` on a machine with
`pass` (it puts the secret in pass), then `gt secret set
VIPPS_WEBHOOK_SECRET` as it says, and Run workflow once more. Until
then kron settles by polling, a minute behind.
5. Drop `by_hand: true` from the content's `payment:` states (the
content repo's lint reads `PAY_URL` the same way).
Nothing here touches the Vippsnummer (500396): people may keep paying
there, and the treasurer marks those by hand as before.
## Rauthy
2026-11-08 13:32:28 +01:00
[Rauthy](https://github.com/sebadob/rauthy) at `RAUTHY_HOST`
(`konto.tomtervel.no`): sign-in, passkeys, account pages and account
mail, in Norwegian (`nb`) and English. A passkey belongs to the name it
was made on, so `RAUTHY_HOST` stays: a new name means new passkeys for
everyone.
2026-11-08 13:32:28 +01:00
On a new host:
2026-11-08 13:32:28 +01:00
1. The secrets, made once and never changed (the key encrypts its
database):
```sh
echo "$(openssl rand -hex 4)/$(openssl rand -base64 32)" | gt secret set RAUTHY_ENC_KEY -R tomtervel/infrastructure
openssl rand -hex 24 | gt secret set RAUTHY_SECRET_RAFT -R tomtervel/infrastructure
openssl rand -hex 24 | gt secret set RAUTHY_SECRET_API -R tomtervel/infrastructure
```
2026-11-08 13:32:28 +01:00
Optionally a short-lived key for making the clients through the API
(`RAUTHY_BOOTSTRAP_API_KEY`, see the table), read on the first start
only.
2. Deploy. The first admin is `SEED_ADMIN_EMAIL`; its password is in the
log once: `podman compose logs rauthy | grep -A2 -i password`.
2026-11-08 13:32:28 +01:00
Signed in, it sets up a passkey.
3. In Rauthy's admin (`https://konto.tomtervel.no/auth/v1/admin`), or
with the bootstrap key: the client `portal` (`authorization_code`,
`S256`, scopes `openid profile email groups`, redirect
`https://tomtervel.no/auth/callback`; without `groups` Rauthy leaves
the groups out of the sign-in, and portal sees everyone in none: no
board, no committee) and `chat` (also
2026-11-08 13:32:28 +01:00
`refresh_token`, redirect `https://samtaler.tomtervel.no/auth/callback`),
their secrets into `OAUTH2_CLIENT_SECRET` and
`CHAT_OAUTH2_CLIENT_SECRET`, and an API key `portal` with read,
create and update on users, groups, roles and auth providers into `RAUTHY_API_KEY`
(a committee's leaders get a role that goes with managing it). A key
Rauthy no longer knows, or one past its expiry, answers 401 to
everything, and every invite fails ("the account could not be made
just now"; `rauthy: reading the groups: http 401` in the log).
Rauthy's mail leaves through kasse's postfix like gdo's, and Rauthy
2026-11-08 13:32:28 +01:00
stops if it cannot reach it.
## Previews
Every content branch pushed to tomtervel/questions gets its own preview
before it is merged, on `https://<branch>.forhandsvisning.tomtervel.no`,
for five days after its last push; `forhandsvisning.tomtervel.no` lists
the ones there are. The content repo runs them
(`.gitea/preview/preview.sh`, from `lint-and-reload` once the lint
passes): a container `tomtervel-preview-<branch>` from this site's own
image (`localhost/tomtervel-portal:<PORTAL_RELEASE>`), beside a throwaway
NATS (`tomtervel-preview-nats`) where each branch has a `SITE_NAME` of its
own, and a small Caddy, `tomtervel-preview-router` on 127.0.0.1:3066, that
picks the container by the name asked for. At most five run at once; the
one that expires first goes when a sixth arrives. The content repo's
`preview-cleanup` workflow removes them when they expire (hourly) and when
their branch is deleted.
A preview has no gdo, so nothing mails anyone, and no sign-in, so desks
stay shut and the public pages show. A form sent on it lands in the
throwaway NATS and nowhere else. The commit gets a "forhåndsvisning"
status with the link, which a PR shows among its checks. Main is never
previewed: it is the site.
On kasse this needs the DNS records in `dns/dnsconfig.js` (the bare name
and `*.forhandsvisning`), the two blocks in `host-caddy/tomtervel.no`, and
the `on_demand_tls` global option described there, in
`/etc/caddy/Caddyfile`.
## Backups
- **The site's store** is one file, `site.redb` in the `portal_data`
volume: every record and its history, the mail and payments that
wait, the sessions. With `PORTAL_BACKUP_TO` (an age public key, made
with `age-keygen` on a machine that is not this host; the private
half never comes here) and `GARAGE_BACKUPS_BUCKET` (a bucket the
site's garage key may write), the site seals a copy of it every six
hours and keeps the newest fourteen. **Neither is set yet**: until
they are, the volume is the only copy. To restore, stop the site and
put the opened copy in the store's place
(`age -d -i backup-key.txt <copy>.redb.age > site.redb`).
2026-11-08 13:32:28 +01:00
- Rauthy's database is the `rauthy_data` volume: the accounts, passkeys
and clients. Snapshot the volume.
- kron's ledger is the `kron_data` volume; gdo's key the `gdo_data`
one. A lost key is a new one named in `DHD_KEYS`.
- The uploads are the `garage_data` volume.
- `nats_data` is what portal 0.19 kept: it stays until going back is no
longer wanted (`move-1.0/README.md`).
- Caddy's certificates regenerate; nothing to keep.
## What is not here
Mail (a person's reset link is a token you hand them), monitoring, and
the vel's current website at tomtervel.no, which stays where it is
until the vel points the apex at PORTAL_HOST.
## DNS
tomtervel.no's records are `dns/dnsconfig.js`, applied to Cloudflare
with DNSControl: the site, the login and the chat pointing here, Zoho's
mail, and SPF, DKIM and DMARC for the mail the site sends. How to run
it, the token it needs, and the order of a move are in
[dns/README.md](dns/README.md).
## Mail
Portal decides what to send - a `mail:` on a state in the content, or an
invite - and keeps it in its `mail` outbox. `gdo` dials the site, is
handed what waits there, and hands it to a mail server, and it runs here, in the vel's own stack, so the vel's mail
leaves on the vel's own terms.
It has no mail server of its own. It relays through the host's, which on
kasse is Klingenberg Bygg's postfix on port 25, reached from the container
as `host.containers.internal`. That is the one thing in this stack the vel
borrows, and the one thing that changes if the vel ever moves to a host of
its own: point `SMTP_HOST` at whatever that host runs.
`site.yaml` in the content repo needs a `mail.from`, or portal has nothing
to send from and says so in its log.
Replies are not read yet: `JMAP_URL`, `JMAP_TOKEN` and `MAIL_REPLY_DOMAIN`
turn a reply into a note on the record it answers, and none of them are set
here.
2026-09-28 21:43:17 +02:00
## Mail leaving the host
gdo hands the vel's mail to kasse's own postfix over the container
network, so postfix has to be willing to relay from it: `mynetworks`
on kasse includes `172.16.0.0/12` and `10.88.0.0/16` (set 2026-09-30,
the original is in `/etc/postfix/main.cf.before-containers`). Without
it every address outside the host's own domains is refused with
"Relay access denied", and gdo retries a minute apart until it is.
## Uploads
Pictures and documents a desk attaches, and what `portal import` brings
in, go to Garage in this project. `go-live.sh garage` renders
`garage/garage.toml` with this node's own rpc secret (gitignored), makes
the bucket `tomtervel-attachments` and the key `tomtervel-portal-uploads`,
and puts `GARAGE_S3_ENDPOINT`, `GARAGE_ACCESS_KEY`, `GARAGE_SECRET_KEY` and
`GARAGE_UPLOADS_BUCKET` in `portal.env`. Without them an upload field
fails closed. Nothing of Garage is published on the host.