Author SHA1 Message Date
blandClaude Opus 5.5 69489e7e42 Previews: one name per branch under forhandsvisning.tomtervel.no
dns / dns (push) Successful in 6s
The content repo now runs one preview per branch, for five days after its
last push, behind its own router on 127.0.0.1:3066
(tomtervel/questions, .gitea/preview/). This is kasse's side of it:

- dns: *.forhandsvisning beside the bare name, both unproxied to kasse.
- host-caddy: the bare name and *.forhandsvisning go to 3066 instead of
  the single preview on 3065. A branch's name gets its certificate on
  demand, and only after the router says the branch has a preview, so
  made-up names cannot use up Let's Encrypt's limits. That needs the
  on_demand_tls ask option in kasse's global Caddyfile, described in the
  file. Also brings the file back in line with what kasse runs.
- README: the Previews section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 08:58:30 +01:00
bl 100002baa2 Merge pull request 'Forhåndsvisningen på port 3065 (3060 er gullberg sin)' (#9) from forhandsvisning-port into main
Reviewed-on: #9
2026-11-08 16:10:40 +01:00
blandClaude Opus 5.5 1943482d74 Forhåndsvisningen på 3065: 3060 er gullberg sin
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L5fbDmSQSb6u27EiEuwzoM
2026-11-08 16:09:09 +01:00
bl dc29f02caa Merge pull request 'Forhåndsvisning av innholdsgrener: forhandsvisning.tomtervel.no' (#8) from forhandsvisning into main
dns / dns (push) Successful in 5s
deploy / deploy (push) Successful in 21s
Reviewed-on: #8
2026-11-08 15:55:15 +01:00
blandClaude Opus 5.5 07c632c1ee Forhåndsvisning: navn på portalbildet, DNS og Caddy for forhandsvisning.tomtervel.no
dns / dns (push) Successful in 5s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L5fbDmSQSb6u27EiEuwzoM
2026-11-08 15:52:45 +01:00
bl 19873965cd Merge pull request 'Uten Kanidm: Rauthy er innloggingen' (#7) from uten-kanidm into main
dns / dns (push) Successful in 5s
deploy / deploy (push) Successful in 22s
Reviewed-on: #7
2026-11-08 13:33:55 +01:00
blandClaude Opus 5.5 ee0ab982a1 Uten Kanidm: Rauthy er innloggingen
dns / dns (push) Successful in 4s
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
2026-11-08 13:32:28 +01:00
bl 7620cd15fb Merge pull request 'Samtalene på samtaler.tomtervel.no' (#6) from samtaler into main
dns / dns (push) Successful in 5s
Reviewed-on: #6
2026-11-08 13:23:45 +01:00
blandClaude Opus 5.5 5f69b217e9 Samtalene på samtaler.tomtervel.no, chat. sender videre
dns / dns (push) Successful in 5s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L5fbDmSQSb6u27EiEuwzoM
2026-11-08 13:21:27 +01:00
bl 94eade5707 Merge pull request 'Rauthy: en kortlivet nøkkel ved første start, til klientene' (#5) from rauthy-provision into main
deploy / deploy (push) Successful in 38s
Reviewed-on: #5
2026-11-08 12:31:52 +01:00
blandClaude Opus 5.5 1ef375a21c Write the bootstrap key only when it is set
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L5fbDmSQSb6u27EiEuwzoM
2026-11-08 12:07:53 +01:00
blandClaude Opus 5.5 9e986bfde4 Rauthy's first start may bootstrap a short-lived key for the clients
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L5fbDmSQSb6u27EiEuwzoM
2026-11-08 12:07:30 +01:00
bl 572e6dc2ea Merge pull request 'Rauthy som valg ved siden av Kanidm (innlogging på norsk)' (#4) from rauthy into main
deploy / deploy (push) Successful in 22s
dns / dns (push) Successful in 5s
2026-11-08 11:59:10 +01:00
11 changed files with 202 additions and 569 deletions

No files matched your search

+16 -19
View File
@@ -20,7 +20,6 @@ on:
- portal/**
- gdo/**
- nats/nats.conf
- kanidm/server.toml.tpl
- rauthy/config.toml
- deploy-tomtervel
- .gitea/workflows/deploy.yml
@@ -34,7 +33,6 @@ jobs:
STAGE: /var/lib/gitea-runner/tomtervel-env
# What the stack is.
PORTAL_HOST: ${{ vars.PORTAL_HOST }}
ID_HOST: ${{ vars.ID_HOST }}
CHAT_HOST: ${{ vars.CHAT_HOST }}
PORTAL_RELEASE: ${{ vars.PORTAL_RELEASE }}
GDO_RELEASE: ${{ vars.GDO_RELEASE }}
@@ -55,7 +53,6 @@ jobs:
NATS_PASSWORD: ${{ secrets.NATS_PASSWORD }}
OAUTH2_CLIENT_SECRET: ${{ secrets.OAUTH2_CLIENT_SECRET }}
CHAT_OAUTH2_CLIENT_SECRET: ${{ secrets.CHAT_OAUTH2_CLIENT_SECRET }}
KANIDM_API_TOKEN: ${{ secrets.KANIDM_API_TOKEN }}
GARAGE_ACCESS_KEY: ${{ secrets.GARAGE_ACCESS_KEY }}
GARAGE_SECRET_KEY: ${{ secrets.GARAGE_SECRET_KEY }}
SEED_ADMIN_EMAIL: ${{ secrets.SEED_ADMIN_EMAIL }}
@@ -64,14 +61,18 @@ jobs:
# location field is two numbers).
MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }}
MAPBOX_STYLE: ${{ vars.MAPBOX_STYLE }}
# Optional: Rauthy beside or instead of Kanidm (README.md, "Rauthy").
# RAUTHY_HOST and the three secrets run it (with `rauthy` in
# COMPOSE_PROFILES); OIDC_ISSUER moves portal's and the chat's
# sign-in to it; RAUTHY_API_KEY lets portal make accounts there.
# Who is who: Rauthy (README.md, "Rauthy"). RAUTHY_HOST and the
# three secrets run it; portal and the chat sign in at OIDC_ISSUER;
# RAUTHY_API_KEY lets portal make accounts there.
RAUTHY_HOST: ${{ vars.RAUTHY_HOST }}
RAUTHY_ENC_KEY: ${{ secrets.RAUTHY_ENC_KEY }}
RAUTHY_SECRET_RAFT: ${{ secrets.RAUTHY_SECRET_RAFT }}
RAUTHY_SECRET_API: ${{ secrets.RAUTHY_SECRET_API }}
# Optional, for Rauthy's very first start only: a short-lived key
# (base64 JSON, README.md "Rauthy") that makes the clients. Rauthy
# reads it into an empty database and never again.
RAUTHY_BOOTSTRAP_API_KEY: ${{ secrets.RAUTHY_BOOTSTRAP_API_KEY }}
RAUTHY_BOOTSTRAP_API_KEY_SECRET: ${{ secrets.RAUTHY_BOOTSTRAP_API_KEY_SECRET }}
OIDC_ISSUER: ${{ vars.OIDC_ISSUER }}
RAUTHY_API_KEY: ${{ secrets.RAUTHY_API_KEY }}
RAUTHY_LANGUAGE: ${{ vars.RAUTHY_LANGUAGE }}
@@ -81,12 +82,13 @@ jobs:
- name: Write the env files
run: |
missing=
for v in PORTAL_HOST ID_HOST CHAT_HOST PORTAL_RELEASE GDO_RELEASE CNATS_TAG \
for v in PORTAL_HOST CHAT_HOST RAUTHY_HOST OIDC_ISSUER PORTAL_RELEASE GDO_RELEASE CNATS_TAG \
KRON_RELEASE CONTENT_REPO CONTENT_BRANCH SITE_NAME PEOPLE_BACKEND \
RESPONSIBLE_GROUP OAUTH2_CLIENT_ID CHAT_OAUTH2_CLIENT_ID \
GARAGE_S3_ENDPOINT GARAGE_UPLOADS_BUCKET \
NATS_PASSWORD OAUTH2_CLIENT_SECRET CHAT_OAUTH2_CLIENT_SECRET \
KANIDM_API_TOKEN GARAGE_ACCESS_KEY GARAGE_SECRET_KEY SEED_ADMIN_EMAIL; do
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"
done
[ -z "$missing" ] || { echo "not set as an Actions variable or secret:$missing"; exit 1; }
@@ -96,7 +98,6 @@ jobs:
# Interpolated by compose: hosts, versions, profiles. No secret.
cat > "$STAGE/.env" <<EOF
PORTAL_HOST=$PORTAL_HOST
ID_HOST=$ID_HOST
CHAT_HOST=$CHAT_HOST
PORTAL_RELEASE=$PORTAL_RELEASE
GDO_RELEASE=$GDO_RELEASE
@@ -109,11 +110,9 @@ jobs:
cat > "$STAGE/portal.env" <<EOF
NATS_URL=nats://portal:$NATS_PASSWORD@nats:4222
PUBLIC_URL=https://$PORTAL_HOST
KANIDM_URL=https://$ID_HOST
CHAT_URL=https://$CHAT_HOST
OAUTH2_CLIENT_ID=$OAUTH2_CLIENT_ID
OAUTH2_CLIENT_SECRET=$OAUTH2_CLIENT_SECRET
KANIDM_API_TOKEN=$KANIDM_API_TOKEN
COOKIE_SECURE=true
CONTENT_REPO=$CONTENT_REPO
CONTENT_BRANCH=$CONTENT_BRANCH
@@ -143,13 +142,8 @@ jobs:
OAUTH2_CLIENT_ID=$CHAT_OAUTH2_CLIENT_ID
OAUTH2_CLIENT_SECRET=$CHAT_OAUTH2_CLIENT_SECRET
EOF
# Rauthy's secrets, only where it runs. The first admin is the
# vel's first person.
if [ -n "$RAUTHY_ENC_KEY" ]; then
for v in RAUTHY_HOST RAUTHY_SECRET_RAFT RAUTHY_SECRET_API; do
[ -n "${!v}" ] || { echo "RAUTHY_ENC_KEY is set, but not $v"; exit 1; }
done
cat > "$STAGE/rauthy.env" <<EOF
# Rauthy's secrets. The first admin is the vel's first person.
cat > "$STAGE/rauthy.env" <<EOF
ENC_KEYS=$RAUTHY_ENC_KEY
ENC_KEY_ACTIVE=${RAUTHY_ENC_KEY%%/*}
HQL_SECRET_RAFT=$RAUTHY_SECRET_RAFT
@@ -158,6 +152,9 @@ jobs:
RAUTHY_ADMIN_EMAIL=$SEED_ADMIN_EMAIL
EVENT_EMAIL=$SEED_ADMIN_EMAIL
EOF
if [ -n "$RAUTHY_BOOTSTRAP_API_KEY" ]; then
printf 'BOOTSTRAP_API_KEY=%s\nBOOTSTRAP_API_KEY_SECRET=%s\n' \
"$RAUTHY_BOOTSTRAP_API_KEY" "$RAUTHY_BOOTSTRAP_API_KEY_SECRET" >> "$STAGE/rauthy.env"
fi
- name: Pull and bring the stack up
-4
View File
@@ -1,11 +1,7 @@
.env
portal.env
chat.env
kanidm/server.toml
certs/
.kanidm-recovered
gitea-oauth.secret
dns/cloudflare.env
nats.env
kanidm-setup.secrets
rauthy.env
+4 -10
View File
@@ -1,17 +1,11 @@
# Public TLS for both hosts, real certificates from Let's Encrypt over
# HTTP-01: the DNS A records for ${PORTAL_HOST} and ${ID_HOST} must
# HTTP-01: the DNS A records for ${PORTAL_HOST} and ${RAUTHY_HOST} must
# point at this host before the first start.
{$ID_HOST} {
# Kanidm serves its own (internal, self-signed) TLS; verification is
# skipped on the inside hop only.
reverse_proxy kanidm:8443 {
transport http {
tls_insecure_skip_verify
}
}
{$RAUTHY_HOST} {
reverse_proxy rauthy:8080
log {
output file /data/id.log
output file /data/konto.log
}
}
+103 -175
View File
@@ -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,85 +97,105 @@ 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_API_KEY`, `RAUTHY_LANGUAGE` | secret, variable | repo | optional: portal makes accounts in Rauthy (`<name>$<secret>`, made in Rauthy's admin), in `nb` |
| `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 | 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://chat.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.
## 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
- 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
@@ -259,51 +232,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
-51
View File
@@ -1,51 +0,0 @@
#!/bin/sh
# What a fresh host needs before the first deploy, and what only exists
# after it. Everything the stack runs with is an Actions variable or
# secret (README.md), written onto the host by the deploy workflow; this
# makes the two things that are not values: Kanidm's config and its
# internal certificate. Idempotent: rerunning skips what exists.
#
# sudo ID_HOST=id.tomtervel.no sh bootstrap.sh # before the first deploy
# (Actions -> deploy -> Run workflow)
# sudo sh bootstrap.sh # after: Kanidm admin recovery
#
# Run rootful (as root) so Kanidm sees a stable source IP.
set -eu
cd "$(dirname "$0")"
[ -f .env ] && . ./.env
: "${ID_HOST:?ID_HOST=id.<the vel's domain> sh bootstrap.sh, or run the deploy workflow first}"
# Kanidm's domain is fixed here, once: renaming it later is Kanidm's own
# `domain rename`, not a variable changed.
[ -f kanidm/server.toml ] || {
sed "s|\${ID_HOST}|$ID_HOST|g" kanidm/server.toml.tpl > kanidm/server.toml
echo "kanidm/server.toml made for $ID_HOST"
}
# Kanidm's internal certificate: Caddy holds the public one.
mkdir -p certs
if [ ! -f certs/kanidm-key.pem ]; then
openssl req -x509 -newkey rsa:2048 -nodes -days 3650 \
-subj "/CN=kanidm" -addext "subjectAltName=DNS:kanidm,DNS:$ID_HOST" \
-keyout certs/kanidm-key.pem -out certs/kanidm-chain.pem >/dev/null 2>&1
chmod 600 certs/kanidm-key.pem
echo "internal Kanidm certificate made"
fi
# The Kanidm admin accounts exist only after the first start; their
# passwords are set by recovery. Once; the output is the password, shown
# once.
if ! podman compose ps --format '{{.Names}}' 2>/dev/null | grep -q kanidm; then
echo "Kanidm is not running yet: run the deploy workflow, then this again."
exit 0
fi
if [ ! -f .kanidm-recovered ]; then
echo
echo "=== Kanidm admin recovery (write these passwords down) ==="
podman compose exec kanidm kanidmd recover-account admin
podman compose exec kanidm kanidmd recover-account idm_admin
touch .kanidm-recovered
fi
echo
echo "Next: sh kanidm-setup.sh (log in as idm_admin, create the portal client and desk groups)"
+20 -45
View File
@@ -1,4 +1,4 @@
# Tomter Vel's own platform: portal + its own Kanidm and NATS as podman
# Tomter Vel's own platform: portal + its own Rauthy and NATS as podman
# containers. The content (pages, forms, desks) is not here: portal fetches
# it from tomtervel/questions on prosjekt.klingenbergbygg.no and hot-reloads
# it over NATS. This repo owns identity, the bus, and which portal version
@@ -6,11 +6,9 @@
# (`--profile edge`) terminates it; on kasse the host Caddy already owns
# 80/443 and reverse-proxies vel.klingenbergbygg.no -> portal (127.0.0.1:3050).
#
# bootstrap.sh first time on a fresh host: renders configs from
# .env, makes Kanidm's internal cert, starts it all,
# recovers the Kanidm admin, creates the portal client
# and desk groups.
# podman compose up -d --build every time after that.
# Everything it runs with is an Actions variable or secret, written by
# the deploy workflow (README.md); `podman compose up -d --build` is
# what deploy-tomtervel runs.
name: tomtervel
@@ -29,14 +27,14 @@ services:
- "443:443/udp"
environment:
PORTAL_HOST: ${PORTAL_HOST}
ID_HOST: ${ID_HOST}
RAUTHY_HOST: ${RAUTHY_HOST}
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
- portal
- kanidm
- rauthy
nats:
image: nats:2.14.6-alpine
@@ -60,35 +58,12 @@ services:
timeout: 5s
retries: 3
kanidm:
image: kanidm/server:1.11.2
restart: unless-stopped
environment:
KANIDM_CONFIG_PATH: /data/server.toml
volumes:
- kanidm_data:/data
- ./kanidm/server.toml:/data/server.toml:ro
# Internal self-signed TLS: Caddy terminates the public
# certificate and proxies here without verification.
- ./certs/kanidm-chain.pem:/data/chain.pem:ro
- ./certs/kanidm-key.pem:/data/key.pem:ro
# Standalone (--profile edge): only the bundled Caddy talks to Kanidm.
# On kasse the host Caddy fronts it, so publish loopback-only for a conf.d
# entry: id.<vel> { reverse_proxy https://localhost:8443 {
# transport http { tls_insecure_skip_verify } } }
# (Kanidm's internal self-signed cert; 8443 is free on kasse — its shared
# Kanidm is on 8310.)
ports:
- "127.0.0.1:8443:8443"
# Rauthy: sign-in, account pages and account mail in Norwegian, as an
# alternative to Kanidm (which has no Norwegian). A profile, off unless
# COMPOSE_PROFILES has `rauthy`; with it, portal and the chat sign in
# here when OIDC_ISSUER is set, and portal makes accounts here with
# RAUTHY_API_KEY. Its database is embedded (hiqlite), in rauthy_data.
# Host-published for kasse's host Caddy (RAUTHY_HOST -> here).
# Rauthy: who is who. Sign-in, account pages and account mail, in
# Norwegian; portal and the chat sign in here (OIDC_ISSUER) and portal
# makes accounts here (RAUTHY_API_KEY). Its database is embedded
# (hiqlite), in rauthy_data. Host-published for kasse's host Caddy
# (RAUTHY_HOST -> here).
rauthy:
profiles: ["rauthy"]
image: ghcr.io/sebadob/rauthy:${RAUTHY_TAG:-0.37.2}
restart: unless-stopped
env_file:
@@ -112,6 +87,9 @@ services:
context: ./portal
args:
PORTAL_RELEASE: ${PORTAL_RELEASE}
# Named, so the content repo's preview (tomtervel/questions,
# lint-and-reload.yml) runs the very image this site runs.
image: localhost/tomtervel-portal:${PORTAL_RELEASE}
restart: unless-stopped
# Written by the deploy workflow from the Actions variables and
# secrets (README.md has the table).
@@ -135,7 +113,7 @@ services:
depends_on:
nats:
condition: service_healthy
kanidm:
rauthy:
condition: service_started
# The mailer. Portal decides what to send - a `mail:` on a state in the
@@ -188,10 +166,8 @@ services:
environment:
# Must be the portal's own: a new name is a new, empty chat.
SITE_NAME: tomtervel
KANIDM_URL: https://${ID_HOST}
# Set, the chat signs in through it instead of Kanidm (Rauthy:
# https://<RAUTHY_HOST>/auth/v1/). Empty is unset.
OIDC_ISSUER: ${OIDC_ISSUER:-}
# Rauthy: https://<RAUTHY_HOST>/auth/v1/
OIDC_ISSUER: ${OIDC_ISSUER}
PUBLIC_URL: https://${CHAT_HOST}
COOKIE_SECURE: "true"
ports:
@@ -217,13 +193,12 @@ volumes:
caddy_data:
caddy_config:
nats_data:
kanidm_data:
rauthy_data:
learn_cache:
# Pin the project network subnet inside 172.16/12 so Kanidm's X-Forwarded-For
# trust (kanidm/server.toml.tpl) stays valid under Podman — its default pool
# hands out 10.89.x addresses that Caddy's forwarded client IP can't match.
# Pin the project network subnet inside 172.16/12 so Rauthy's trusted
# proxies (rauthy/config.toml) stay valid under Podman — its default pool
# hands out 10.89.x addresses that the forwarded client IP can't match.
networks:
default:
ipam:
+4 -4
View File
@@ -60,10 +60,10 @@ Nothing about Zoho's MX should appear.
prints its public half. Put it in `KASSE_DKIM`.
2. Actions -> dns -> Run workflow on main (or `dnscontrol push`). The apex
leaves the old website at this moment.
3. The Actions variables `PORTAL_HOST=tomtervel.no`, `ID_HOST=id.tomtervel.no`,
`CHAT_HOST=chat.tomtervel.no`, the deploy workflow run, and the Caddy blocks in
`host-caddy/` on kasse; Kanidm's domain is renamed before anyone
but the first person has a passkey.
3. The Actions variables `PORTAL_HOST=tomtervel.no`, `RAUTHY_HOST=konto.tomtervel.no`,
`CHAT_HOST=samtaler.tomtervel.no`, the deploy workflow run, and the Caddy blocks in
`host-caddy/` on kasse. `RAUTHY_HOST` is chosen once: a passkey belongs
to the name it was made on.
4. Only then `mail.from: post@tomtervel.no` in the content repo's
`site.yaml`; before step 2 that mail fails every check.
+11 -3
View File
@@ -12,7 +12,7 @@ var REG_NONE = NewRegistrar("none");
var DSP_CLOUDFLARE = NewDnsProvider("cloudflare");
// kasse: Klingenberg Bygg's host, where the vel's stack runs (portal,
// Kanidm, chat, gdo) behind kasse's own Caddy, and whose postfix sends
// Rauthy, chat, gdo) behind kasse's own Caddy, and whose postfix sends
// the vel's mail. Move the vel to a host of its own: change this.
var KASSE = "195.159.177.252";
@@ -30,10 +30,18 @@ D("tomtervel.no", REG_NONE, DnsProvider(DSP_CLOUDFLARE),
// websockets reach it as they are.
A("@", KASSE, CF_PROXY_OFF),
CNAME("www", "tomtervel.no.", CF_PROXY_OFF),
A("konto", KASSE, CF_PROXY_OFF),
A("samtaler", KASSE, CF_PROXY_OFF),
// The old names, kept so links from before still land: Caddy sends
// id on to konto (the login) and chat on to samtaler.
A("id", KASSE, CF_PROXY_OFF),
A("chat", KASSE, CF_PROXY_OFF),
// Rauthy, the Norwegian sign-in, beside Kanidm while the vel tries it.
A("konto", KASSE, CF_PROXY_OFF),
// The content repo's previews: the list of them, and one name per
// branch before it is merged (<branch>.forhandsvisning). Caddy gets a
// certificate for a branch's name the first time it is asked for, and
// only for a branch that has a preview (host-caddy/tomtervel.no).
A("forhandsvisning", KASSE, CF_PROXY_OFF),
A("*.forhandsvisning", KASSE, CF_PROXY_OFF),
// The old website, kept for now so the move can be undone: what the
// apex and web. pointed at before (Netlify, through Cloudflare). The
+44 -26
View File
@@ -12,38 +12,56 @@ www.tomtervel.no {
redir https://tomtervel.no{uri} permanent
}
# Tomter Vel's own Kanidm. Caddy holds the public certificate; Kanidm
# speaks TLS internally with a self-signed one, on a loopback port, so
# that hop is not verified. The @brand files are the vel's: the name in
# the tab, the icons, and the stylesheet Kanidm serves empty for a site
# to fill (written by go-live.sh brand into /srv/tomtervel/brand).
# The old login, Kanidm, is gone: its name sends people on to Rauthy.
id.tomtervel.no {
@brand path /pkg/override.css /manifest.webmanifest /pkg/img/favicon.png /pkg/img/logo.svg /pkg/img/logo-square.svg /pkg/img/logo-180.png /pkg/img/logo-192.png /pkg/img/logo-256.png /pkg/img/logo-512.png /pkg/img/kani-warning.svg /pkg/img/kani-waving.svg
handle @brand {
root * /srv/tomtervel/brand
uri strip_prefix /pkg/img
uri strip_prefix /pkg
header Cache-Control "public, max-age=3600"
@manifest path /manifest.webmanifest
header @manifest Content-Type application/manifest+json
file_server
}
handle {
reverse_proxy https://127.0.0.1:8443 {
transport http {
tls_insecure_skip_verify
}
}
}
redir https://konto.tomtervel.no permanent
}
chat.tomtervel.no {
# The vel's conversations (cnats). Its old name sends people on, so a
# link or a bookmark from before still lands.
samtaler.tomtervel.no {
reverse_proxy 127.0.0.1:3070
}
# Rauthy (compose profile `rauthy`): sign-in and account pages in
# Norwegian, beside Kanidm until the vel moves over (README.md, "Rauthy").
# Plain http on a loopback port; Caddy holds the certificate.
chat.tomtervel.no {
redir https://samtaler.tomtervel.no{uri} permanent
}
# Rauthy: sign-in, passkeys and account pages, in Norwegian (README.md,
# "Rauthy"). Plain http on a loopback port; Caddy holds the certificate.
konto.tomtervel.no {
reverse_proxy 127.0.0.1:8090
}
# The content repo's previews (tomtervel/questions, .gitea/preview/): one
# portal per branch on <branch>.forhandsvisning.tomtervel.no, for five days
# after its last push, and the list of them on the bare name. Every name
# goes to the previews' own router on 3066, which picks the branch's
# container by name. Kept out of search engines.
#
# A branch's name has no certificate until someone opens it: Caddy gets one
# on demand, and first asks the router whether that name has a preview, so
# made-up names cannot use up Let's Encrypt's limits. That needs this in the
# global options of /etc/caddy/Caddyfile (kasse's, shared with the other
# sites there; nothing else on kasse uses on-demand TLS):
#
# on_demand_tls {
# ask http://127.0.0.1:3066/ask
# }
#
# Port 3066: 3060 is gullberg.klingenbergbygg.no's, 3065 was the single
# preview before, and podman's own published ports (3050, 3065, 3066, 3070,
# 8090) do not show in `ss`, so a port is chosen against this directory's
# upstreams as well.
forhandsvisning.tomtervel.no {
header X-Robots-Tag "noindex, nofollow"
reverse_proxy 127.0.0.1:3066
}
*.forhandsvisning.tomtervel.no {
tls {
on_demand
}
header X-Robots-Tag "noindex, nofollow"
reverse_proxy 127.0.0.1:3066
}
-202
View File
@@ -1,202 +0,0 @@
#!/bin/sh
# Everything portal needs from this Kanidm, all the way: the OAuth2
# client people sign in through, one group per desk named exactly as
# the content names it, and the service account portal onboards people
# with - so that inviting someone from a desk, a decision that grants a
# group, and the first person in (SEED_ADMIN_EMAIL) all simply work.
# Rerunnable: each step skips what is already there.
#
# Logs in first if needed (interactive, idm_admin's password from
# bootstrap.sh), writes the client secret and the onboarding token into
# portal.env, and restarts portal. Needs the kanidm CLI and curl.
set -eu
cd "$(dirname "$0")"
. ./.env
. ./portal.env
# The project Gitea that RESPONSIBLE_GROUP signs in to. Not an Actions
# variable: Gitea refuses names starting GITEA_. Empty: no Gitea.
GITEA_URL=${GITEA_URL-https://prosjekt.klingenbergbygg.no}
GITEA_AUTH_NAME=${GITEA_AUTH_NAME:-tomtervel}
K="kanidm -D idm_admin -H https://$ID_HOST"
C=$OAUTH2_CLIENT_ID
SA=portal-onboarding
# What a person reads on the sign-in pages. Not SITE_NAME, which from portal
# 0.9 is the site's namespace, `tomtervel`.
SITE_TITLE=${SITE_TITLE:-Tomter Vel}
# Already signed in? Then do not ask again: this script is meant to be
# rerunnable, and the session outlives a single run.
$K self whoami >/dev/null 2>&1 || $K login
has_client() { $K system oauth2 get "$1" 2>/dev/null | grep -q '^name:'; }
has_group() { $K group get "$1" 2>/dev/null | grep -q '^name:'; }
has_account() { $K service-account get "$1" 2>/dev/null | grep -q '^name:'; }
# The desk groups are whatever the content gates pages on: every
# `qualifies:` under questions/ in the content repo. Read from the repo,
# so this list cannot drift from the pages. This Kanidm is the vel's
# own, so a group is called exactly what the content calls it.
host=$(printf '%s' "$CONTENT_REPO" | sed -E 's|^(https?://[^/]+)/.*|\1|')
path=$(printf '%s' "$CONTENT_REPO" | sed -E 's|^https?://[^/]+/||')
tree=$(curl -sf "$host/api/v1/repos/$path/git/trees/$CONTENT_BRANCH?recursive=true&per_page=1000") || {
echo "could not read the content repo's file list ($CONTENT_REPO)" >&2; exit 1; }
groups=$(printf '%s' "$tree" | grep -oE '"path":"questions/[^"]+\.yaml"' | sed -E 's/^"path":"//; s/"$//' | while read -r f; do
curl -sf "$CONTENT_REPO/raw/branch/$CONTENT_BRANCH/$f" | sed -nE 's/^qualifies:[[:space:]]*"?([a-z0-9_-]+)"?[[:space:]]*$/\1/p'
done | sort -u)
[ -n "$groups" ] || { echo "the content gates no page on a group - nothing for a desk to sign in to" >&2; exit 1; }
echo "desk groups from the content: $(echo $groups)"
# The onboarding account. In idm_people_on_boarding it may create a
# person and issue a first credential reset and nothing else, so its
# token cannot touch anyone's existing credentials; idm_people_pii_read
# lets an invite find someone who already has an account by their
# email and add them instead of making a second account. Portal creates
# the person with their address in the same call, because this account
# may create but not modify.
if ! has_account $SA; then
$K service-account create $SA "Portal onboarding" idm_admin
fi
$K group add-members idm_people_on_boarding $SA >/dev/null
$K group add-members idm_people_pii_read $SA >/dev/null || true
# One group per desk, managed by the onboarding account: adding a
# member to a group takes the right to manage that group, and a desk
# invite or a `grants:` does exactly that. Groups made before this
# script dropped its old `tomtervel_` prefix are renamed in place, so
# their members and claim maps come along.
for g in $groups; do
if ! has_group "$g" && has_group "tomtervel_$g"; then
$K group rename "tomtervel_$g" "$g"
fi
has_group "$g" || $K group create "$g" $SA
$K group set-entry-manager "$g" $SA >/dev/null
done
# The people who ask the questions: everyone a page names as
# responsible. Portal puts them here itself at start (RESPONSIBLE_GROUP);
# the group only has to exist and be portal's to fill. Kanidm names are
# ASCII, so "Redaktør" is its description.
if [ -n "${RESPONSIBLE_GROUP:-}" ]; then
has_group "$RESPONSIBLE_GROUP" || $K group create "$RESPONSIBLE_GROUP" $SA
$K group set-entry-manager "$RESPONSIBLE_GROUP" $SA >/dev/null
$K group set-description "$RESPONSIBLE_GROUP" "${RESPONSIBLE_GROUP_LABEL:-Redaktør}: står som ansvarlig for et spørsmål på siden" >/dev/null || true
fi
# The OAuth2 client. Everyone in this Kanidm is the vel's, so anyone
# may sign in; what they see is decided by their desk groups, which
# arrive in the `groups` claim under their own names.
has_client $C || $K system oauth2 create $C "$SITE_TITLE" "https://$PORTAL_HOST"
$K system oauth2 add-redirect-url $C "https://$PORTAL_HOST/auth/callback" 2>/dev/null || true
$K system oauth2 update-scope-map $C idm_all_persons openid profile email
for g in $groups; do
$K system oauth2 update-claim-map $C groups "$g" "$g"
done
$K system oauth2 update-claim-map-join $C groups array
# The old umbrella group the scope map used to name, if this Kanidm
# still has it: idm_all_persons does its job now.
if has_group tomtervel_members; then
$K system oauth2 delete-scope-map $C tomtervel_members 2>/dev/null || true
$K group delete tomtervel_members
fi
# What a member sees when they land on the login page. Out of the box
# Kanidm says "kanidm" and shows its own mark, which tells a neighbour
# nothing about whose site they are signing in to. The logo comes from
# the content repo, the same file site.yaml uses as the favicon.
#
# The client's name and logo are idm_admin's to set. The instance's own
# (the login page's heading and mark) are system settings only `admin`
# may change - idm_admin gets a bare "Item not found" - so that half
# runs when an admin session exists, and otherwise says what to run.
A="kanidm -D admin -H https://$ID_HOST"
$K system oauth2 set-displayname $C "$SITE_TITLE" >/dev/null || true
logo=$(mktemp --suffix=.svg)
if curl -sfL "$CONTENT_REPO/raw/branch/$CONTENT_BRANCH/images/logo.svg" -o "$logo" && [ -s "$logo" ]; then
$K system oauth2 set-image $C "$logo" svg >/dev/null || echo "note: could not set the client logo"
else
echo "note: no images/logo.svg in the content repo - leaving the default mark"
: > "$logo"
fi
if $A self whoami >/dev/null 2>&1; then
$A system domain set-displayname "$SITE_TITLE" >/dev/null || echo "note: could not set the login page's name"
[ -s "$logo" ] && { $A system domain set-image "$logo" svg >/dev/null || echo "note: could not set the login page's logo"; }
else
echo "note: the login page's own name and logo need the admin account (bootstrap.sh printed its password):"
echo " $A login # then rerun this script"
fi
rm -f "$logo"
# Sign-in to a project Gitea for the people who ask the questions: its
# own OAuth2 client, which only RESPONSIBLE_GROUP may use, carrying that
# group in the `groups` claim so Gitea can require it as well. Gitea
# does not do PKCE (Kanidm's own Gitea example turns it off), and short
# usernames keep Gitea accounts "kari", not "kari@id.vel...".
if [ -n "${GITEA_URL:-}" ] && [ -n "${RESPONSIBLE_GROUP:-}" ]; then
G=${GITEA_OAUTH2_CLIENT_ID:-prosjekt}
N=${GITEA_AUTH_NAME:-tomtervel}
has_client $G || $K system oauth2 create $G "${GITEA_LABEL:-Prosjekt}" "$GITEA_URL/user/login"
$K system oauth2 add-redirect-url $G "$GITEA_URL/user/oauth2/$N/callback" 2>/dev/null || true
$K system oauth2 update-scope-map $G "$RESPONSIBLE_GROUP" openid profile email >/dev/null
$K system oauth2 update-claim-map $G groups "$RESPONSIBLE_GROUP" "$RESPONSIBLE_GROUP" >/dev/null
$K system oauth2 update-claim-map-join $G groups array >/dev/null
$K system oauth2 warning-insecure-client-disable-pkce $G >/dev/null
$K system oauth2 prefer-short-username $G >/dev/null
gsecret=$($K system oauth2 show-basic-secret $G 2>/dev/null | tail -1)
discover="https://$ID_HOST/oauth2/openid/$G/.well-known/openid-configuration"
# On the host that runs that Gitea, add or update its source here;
# anywhere else, leave the secret in a file only this user can read.
# As root (this script is usually run under sudo) become the gitea
# user directly: on kasse root is not in sudoers.
as_gitea=""
if [ "$(id -u)" = 0 ]; then as_gitea="runuser -u gitea --"; elif sudo -n -u gitea true 2>/dev/null; then as_gitea="sudo -n -u gitea"; fi
if command -v gitea >/dev/null 2>&1 && [ -n "$as_gitea" ]; then
GT="$as_gitea gitea --config ${GITEA_CONFIG:-/etc/gitea/app.ini} admin auth"
id=$($GT list 2>/dev/null | awk -v n="$N" '$2 == n { print $1 }')
if [ -n "$id" ]; then
$GT update-oauth --id "$id" --key "$G" --secret "$gsecret" --auto-discover-url "$discover" \
--required-claim-name groups --required-claim-value "$RESPONSIBLE_GROUP" --scopes "openid profile email" >/dev/null
echo "Gitea sign-in source '$N' updated"
else
$GT add-oauth --name "$N" --provider openidConnect --key "$G" --secret "$gsecret" --auto-discover-url "$discover" \
--required-claim-name groups --required-claim-value "$RESPONSIBLE_GROUP" --scopes "openid profile email" >/dev/null
echo "Gitea sign-in source '$N' added: $GITEA_URL/user/login has a 'Sign in with $N' button"
fi
else
umask 077; printf '%s\n' "$gsecret" > gitea-oauth.secret
echo "note: no gitea CLI here - on the Gitea host, add the source with the secret in gitea-oauth.secret:"
echo " gitea admin auth add-oauth --name $N --provider openidConnect --key $G --secret \"\$(cat gitea-oauth.secret)\" \\"
echo " --auto-discover-url $discover --required-claim-name groups --required-claim-value $RESPONSIBLE_GROUP --scopes 'openid profile email'"
fi
fi
# The two secrets Kanidm makes, never printed: into portal.env so portal
# has them now, and into kanidm-setup.secrets for the repo's Actions
# secrets, which the next deploy writes portal.env from. The token is
# shown once, by Kanidm, at creation; a rerun keeps the one there is.
setenv() { if grep -q "^$1=" portal.env; then sed -i "s|^$1=.*|$1=$2|" portal.env; else printf '%s=%s\n' "$1" "$2" >> portal.env; fi; }
(umask 077; : > kanidm-setup.secrets)
secret=$($K system oauth2 show-basic-secret $C 2>/dev/null | tail -1)
setenv OAUTH2_CLIENT_SECRET "$secret"
printf 'OAUTH2_CLIENT_SECRET=%s\n' "$secret" >> kanidm-setup.secrets
if ! grep -q '^KANIDM_API_TOKEN=.' portal.env 2>/dev/null; then
token=$($K service-account api-token generate $SA "portal" --readwrite 2>/dev/null | tail -1)
if [ -n "$token" ]; then
setenv KANIDM_API_TOKEN "$token"
printf 'KANIDM_API_TOKEN=%s\n' "$token" >> kanidm-setup.secrets
echo "onboarding token written to portal.env"
else
echo "warning: could not generate the onboarding token - invites will fail closed until it is set" >&2
echo " retry by hand: $K service-account api-token generate $SA portal --readwrite" >&2
fi
fi
podman compose up -d portal
echo "portal restarted: signs in through $C, onboards through $SA, desks: $(echo $groups)"
echo
echo "Into the repo's Actions secrets, or the next deploy undoes them (from a"
echo "machine with gt; kanidm-setup.secrets is root's, here):"
echo " ssh kasse sudo cat $(pwd)/kanidm-setup.secrets | gt secret set -R tomtervel/infrastructure --env-file -"
echo "then remove it: sudo rm $(pwd)/kanidm-setup.secrets"
if [ -n "${SEED_ADMIN_EMAIL:-}" ]; then echo "the first person, $SEED_ADMIN_EMAIL, gets their invite from portal now (once)"; fi
echo
echo "Everyone after that is invited from a desk. By hand, if ever needed:"
echo " $K group add-members styret <person>"
-30
View File
@@ -1,30 +0,0 @@
# Kanidm server configuration. bootstrap.sh renders this into
# server.toml from .env; edit the template, not the rendered file.
# Reference: https://kanidm.github.io/kanidm/stable/server_configuration.html
version = "2"
bindaddress = "0.0.0.0:8443"
# Internal self-signed pair made by bootstrap.sh; Caddy terminates the
# public certificate and proxies here with verification disabled.
tls_chain = "/data/chain.pem"
tls_key = "/data/key.pem"
db_path = "/data/kanidm.db"
db_fs_type = "other"
db_arc_size = 2048
log_level = "info"
# domain must equal the DNS name Kanidm is served at.
domain = "${ID_HOST}"
origin = "https://${ID_HOST}"
# Trust X-Forwarded-For from Caddy on the compose network.
[http_client_address_info]
x-forward-for = ["172.16.0.0/12"]
[online_backup]
path = "/data/backups/"
schedule = "00 22 * * *"
versions = 7