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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L5fbDmSQSb6u27EiEuwzoM
This commit is contained in:
11 files changed
+121
-576
No files matched your search
@@ -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
|
||||
|
||||
```
|
||||
<PORTAL_HOST> {
|
||||
reverse_proxy localhost:3050
|
||||
}
|
||||
<ID_HOST> {
|
||||
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_<group>`, 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: `<owner>/<style>`; unset, `mapbox/streets-v12` |
|
||||
| `DNSCONTROL_VERSION` | variable | repo | the DNS workflow's dnscontrol |
|
||||
| `RAUTHY_HOST` | variable | repo | optional, Rauthy (see [Rauthy](#rauthy)): `konto.tomtervel.no` |
|
||||
| `RAUTHY_ENC_KEY`, `RAUTHY_SECRET_RAFT`, `RAUTHY_SECRET_API` | secret | repo | optional, Rauthy's own: made once, never changed (the key encrypts its database) |
|
||||
| `OIDC_ISSUER` | variable | repo | optional: `https://konto.tomtervel.no/auth/v1/` moves the site's and the chat's sign-in to Rauthy; unset, Kanidm |
|
||||
| `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 and the chat sign 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 |
|
||||
| `RAUTHY_API_KEY`, `RAUTHY_LANGUAGE` | secret, variable | repo | optional: portal makes accounts in Rauthy (`<name>$<secret>`, made in Rauthy's admin), in `nb` |
|
||||
| `RAUTHY_API_KEY`, `RAUTHY_LANGUAGE` | secret, variable | repo | portal makes accounts in Rauthy (`<name>$<secret>`, made in Rauthy's admin), in `nb` |
|
||||
|
||||
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.
|
||||
|
||||
What is not a value stays on the host, made there once: Kanidm's config
|
||||
and internal certificate (`bootstrap.sh`), and Garage's node secret.
|
||||
`kanidm/server.toml` takes `ID_HOST` once: Kanidm's domain is renamed on
|
||||
purpose, not by a variable changed (see dns/README.md).
|
||||
What is not a value stays on the host, made there once: Garage's node
|
||||
secret.
|
||||
|
||||
## Rauthy
|
||||
|
||||
Kanidm has no Norwegian: its sign-in, its account pages and its mail
|
||||
are in English. [Rauthy](https://github.com/sebadob/rauthy) has
|
||||
Norwegian (`nb`) in all three, and portal (from the release after
|
||||
0.14.2) and the chat can sign in through it. It is here as a compose
|
||||
profile, off until it is asked for, so the vel can try it beside
|
||||
Kanidm and move when it is ready. Portal keeps the groups either way
|
||||
(`PEOPLE_BACKEND=memberships`), so moving takes no groups along.
|
||||
[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.
|
||||
|
||||
Trying it, beside Kanidm:
|
||||
On a new host:
|
||||
|
||||
1. The secrets, made once and never changed:
|
||||
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
|
||||
gt variable set RAUTHY_HOST --body konto.tomtervel.no -R tomtervel/infrastructure
|
||||
gt variable set COMPOSE_PROFILES --body chat,rauthy -R tomtervel/infrastructure
|
||||
```
|
||||
2. DNS: `konto` is in `dns/dnsconfig.js`; run the dns workflow. Install
|
||||
`host-caddy/tomtervel.no` on kasse (it has the `konto` block) and
|
||||
reload Caddy. Reinstall `deploy-tomtervel` on kasse too: it now puts
|
||||
`rauthy.env` in place.
|
||||
3. Deploy. The first admin is `SEED_ADMIN_EMAIL`; its password is in the
|
||||
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`.
|
||||
4. In Rauthy's admin (`https://konto.tomtervel.no/auth/v1/admin`): a
|
||||
client for the site (`authorization_code`, `S256`, scopes `openid
|
||||
profile email`, redirect `https://tomtervel.no/auth/callback`) and
|
||||
one for the chat (also `refresh_token`, redirect
|
||||
`https://samtaler.tomtervel.no/auth/callback`), and an API key with read
|
||||
and create on users.
|
||||
5. Moving the sign-in over is then values: `OIDC_ISSUER`,
|
||||
`OAUTH2_CLIENT_ID`/`OAUTH2_CLIENT_SECRET` and the chat's pair set to
|
||||
Rauthy's clients, `RAUTHY_API_KEY`, `RAUTHY_LANGUAGE=nb`, and a
|
||||
portal release that knows them. Back is the same values unset.
|
||||
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`, redirect
|
||||
`https://tomtervel.no/auth/callback`) and `chat` (also
|
||||
`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 and groups into `RAUTHY_API_KEY`.
|
||||
|
||||
Rauthy's mail leaves through kasse's postfix like gdo's, and Rauthy
|
||||
stops if it cannot reach it. Its database is in the `rauthy_data`
|
||||
volume, which wants the same backups as NATS.
|
||||
stops if it cannot reach it.
|
||||
|
||||
## Backups
|
||||
|
||||
- Kanidm writes a nightly backup into its volume (`/data/backups`,
|
||||
seven kept); copy that directory off the host.
|
||||
- Rauthy's database is the `rauthy_data` volume: the accounts, passkeys
|
||||
and clients. Snapshot it with NATS's.
|
||||
- NATS JetStream data is the `nats_data` volume: every record ever
|
||||
submitted and every state change. Snapshot the volume.
|
||||
submitted and every state change, the memberships and the chat's
|
||||
history. Snapshot the volume.
|
||||
- Caddy's certificates regenerate; nothing to keep.
|
||||
|
||||
## What is not here
|
||||
@@ -260,51 +205,6 @@ 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.
|
||||
|
||||
## How the login page looks
|
||||
|
||||
Out of the box Kanidm presents itself: its own name, its own mark. A
|
||||
neighbour arriving at a login page that belongs to nobody in particular
|
||||
is right to hesitate, so `kanidm-setup.sh` sets the vel's name and mark
|
||||
on both the instance and the portal client:
|
||||
|
||||
```sh
|
||||
kanidm -D idm_admin -H https://$ID_HOST system domain set-displayname "Tomter Vel"
|
||||
kanidm -D idm_admin -H https://$ID_HOST system domain set-image logo.svg svg
|
||||
```
|
||||
|
||||
The logo is fetched from the content repo - the same `images/logo.svg`
|
||||
that `site.yaml` uses as the favicon - so the login page and the site
|
||||
are branded from one place. png, jpg, gif, svg and webp all work.
|
||||
|
||||
Two things the setup script deliberately leaves alone, because they are
|
||||
decisions rather than branding:
|
||||
|
||||
- `system domain set-allow-account-recovery true` lets someone who has
|
||||
lost their credentials get a reset link by proving one of their own
|
||||
email addresses, instead of asking the board. Worth having for a vel;
|
||||
it is still a door, so it is turned on knowingly or not at all.
|
||||
- `system domain set-allow-easter-eggs` - seasonal icons and birthday
|
||||
surprises. Off in production builds, and this is somebody's vel.
|
||||
|
||||
## Keep the CLI and the server on the same version
|
||||
|
||||
The `kanidm` CLI on the host and the `kanidm/server` image in
|
||||
`compose.yml` must match. They are not merely fussy about it: a 1.11.2
|
||||
client against a 1.11.1 server looks up the domain entry at a UUID the
|
||||
older server does not have, so `system domain set-displayname` and
|
||||
`set-image` fail with "Item not found" - a message that says nothing
|
||||
about versions. The CLI warns on every call; the warning is worth
|
||||
reading.
|
||||
|
||||
The same "Item not found" also comes back when the versions do match
|
||||
and the account is `idm_admin`: the instance's own name and logo are
|
||||
system settings only `admin` may change. `kanidm-setup.sh` sets them
|
||||
when an `admin` session exists and says so when it does not.
|
||||
|
||||
The host's CLI comes from pacman and moves on its own, so the image is
|
||||
what to bump: `image: kanidm/server:<version>` in `compose.yml`, then
|
||||
`podman compose up -d kanidm`.
|
||||
|
||||
## Mail leaving the host
|
||||
|
||||
gdo hands the vel's mail to kasse's own postfix over the container
|
||||
|
||||
Reference in new issue
Block a user