1 Commits
Author SHA1 Message Date
blandClaude Fable 5.1 a93f35792f kron beside portal: the money service, Vipps MobilePay, wired but not started
A `kron:` service on the vel's own NATS, its keys in kron.env and
nowhere else, published on 127.0.0.1:3080 for the host Caddy
(host-caddy/kron.vel.klingenbergbygg.no), and PAY_URL on portal so the
lint allows `payment:` without `by_hand`. kron.env.example names the
five settings; register-vipps-webhook.sh registers <PUBLIC_URL>/webhook
with Vipps and writes the secret it answers with into kron.env without
showing it. The README's Money section is the order to do it in.

On a branch, not main: deploy-tomtervel resets the checkout to
origin/main and brings the whole project up, and a kron service whose
env_file is not on the host yet would stop everything else with it.
Merge once kron.env is in place and bendik/kron has a tag to pin.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L5fbDkR5YogvJGebPtogQT
2026-11-04 18:05:26 +01:00
26 changed files with 674 additions and 1060 deletions

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
# Copy to .env and fill in. Everything rendered from this (nats.conf,
# kanidm/server.toml, portal.env) is gitignored.
# Where the site and the identity provider are served. Both need an A
# record pointing at this host before the first start (Caddy gets the
# certificates over HTTP-01). tomtervel.no itself stays where it is
# until the vel decides to point the apex here.
PORTAL_HOST=vel.klingenbergbygg.no
ID_HOST=id.vel.klingenbergbygg.no
# The portal version to run: a tag of https://project.uhhm.no/uhhm/portal
PORTAL_RELEASE=v0.10.2
# The content this instance serves, and reloads live on every push.
CONTENT_REPO=https://prosjekt.klingenbergbygg.no/tomtervel/questions
CONTENT_BRANCH=main
SITE_NAME=tomtervel
# Generated once by bootstrap.sh if left empty.
NATS_PASSWORD=
# The first person in: portal invites this address into the site's most
# privileged group (the board, on the vel - the group whose desk may
# invite into the most groups) and mails them the one-time link, once.
# Everyone else they invite themselves, from their desk.
SEED_ADMIN_EMAIL=
SEED_ADMIN_NAME=
# The people who ask the questions: everyone a page names as
# responsible gets an account (portal makes it at start and mails them)
# and joins this group. Kanidm names are ASCII: redaktor, "Redaktør".
RESPONSIBLE_GROUP=redaktor
# Where the groups live. `memberships`: portal keeps them itself, a person
# is their phone number first, and Kanidm only makes the account (until a
# sign-in everyone already has, like Vipps, takes over). Unset: Kanidm
# holds the groups too.
PEOPLE_BACKEND=memberships
# A project Gitea they may sign in to with the same account: kanidm-setup
# makes its OAuth2 client (only RESPONSIBLE_GROUP may use it) and, on the
# host that runs that Gitea, adds the sign-in source. Empty: no Gitea.
GITEA_URL=https://prosjekt.klingenbergbygg.no
GITEA_AUTH_NAME=tomtervel
# The vel's conversations, on their own address. go-live.sh sets the two
# below once chat.env (the sign-in client's secret, gitignored) is there;
# without them `up` leaves the chat out. 0.4.0 and older say the wrong
# name on their sign-in page: use a tag above it.
#CNATS_TAG=0.4.1
#COMPOSE_PROFILES=chat
CHAT_HOST=chat.vel.klingenbergbygg.no
# Filled in by bootstrap.sh after it creates the Kanidm client.
OAUTH2_CLIENT_ID=tomtervel-portal
OAUTH2_CLIENT_SECRET=
# Only for the optional runner profile: a registration token from
# prosjekt.klingenbergbygg.no -> tomtervel org -> Settings -> Actions -> Runners.
RUNNER_REGISTRATION_TOKEN=
# The gdo version to run: a tag of https://project.uhhm.no/uhhm/gdo,
# installed from the [uhhm] Arch registry. gdo hands the vel's mail to
# the host's mail server; on kasse that is Klingenberg Bygg's postfix.
GDO_RELEASE=v0.2.0
# kron, the money service: a bendik/kron tag on Docker Hub.
KRON_RELEASE=0.1.0
+11 -201
View File
@@ -1,15 +1,13 @@
# Deploy this stack onto kasse. Every value the stack runs with is an # Deploy this stack onto the host it runs on. A push that changes the
# Actions variable (vars.*: hosts, versions, where the content comes from) # compose file, a Dockerfile or a rendered config pulls and brings the
# or secret (secrets.*: passwords, tokens, the first person's address) of # stack up; a portal or gdo upgrade is a commit that bumps the version in
# this repo, or of the tomtervel org for what other repos share # .env.example and, on the host, in .env.
# (NATS_PASSWORD, which the content repo's reload uses too). The table is
# in README.md. A new host name or a portal bump is a variable changed and
# then Run workflow; a change to the files here deploys on push.
# #
# Runs on kasse's host runner, which is not root. It writes the env files # Runs on kasse's host runner. It is not root: it may run one script,
# into its own directory, and may run one script as root, # /usr/local/bin/deploy-tomtervel, which pulls this repo under
# /usr/local/bin/deploy-tomtervel (deploy-tomtervel here), which pulls # /srv/tomtervel and runs `podman compose up -d --build` and nothing
# main, puts those files in place and runs `podman compose up -d --build`. # else. The .env on the host - the NATS password, the OAuth2 secret, the
# Kanidm token - is never in this repo and is not touched by a deploy.
name: deploy name: deploy
on: on:
push: push:
@@ -19,202 +17,14 @@ on:
- Caddyfile - Caddyfile
- portal/** - portal/**
- gdo/** - gdo/**
- rauthy-providers.sh - kanidm/server.toml.tpl
- rauthy-theme.sh - nats/nats.conf.tpl
- nats/nats.conf
- rauthy/config.toml
- deploy-tomtervel
- .gitea/workflows/deploy.yml - .gitea/workflows/deploy.yml
workflow_dispatch: workflow_dispatch:
jobs: jobs:
deploy: deploy:
if: github.ref == 'refs/heads/main'
runs-on: fish runs-on: fish
env:
STAGE: /var/lib/gitea-runner/tomtervel-env
# What the stack is.
PORTAL_HOST: ${{ vars.PORTAL_HOST }}
CHAT_HOST: ${{ vars.CHAT_HOST }}
PAY_HOST: ${{ vars.PAY_HOST }}
PORTAL_RELEASE: ${{ vars.PORTAL_RELEASE }}
GDO_RELEASE: ${{ vars.GDO_RELEASE }}
CNATS_TAG: ${{ vars.CNATS_TAG }}
KRON_RELEASE: ${{ vars.KRON_RELEASE }}
COMPOSE_PROFILES: ${{ vars.COMPOSE_PROFILES }}
CONTENT_REPO: ${{ vars.CONTENT_REPO }}
CONTENT_BRANCH: ${{ vars.CONTENT_BRANCH }}
SITE_NAME: ${{ vars.SITE_NAME }}
PEOPLE_BACKEND: ${{ vars.PEOPLE_BACKEND }}
RESPONSIBLE_GROUP: ${{ vars.RESPONSIBLE_GROUP }}
OAUTH2_CLIENT_ID: ${{ vars.OAUTH2_CLIENT_ID }}
CHAT_OAUTH2_CLIENT_ID: ${{ vars.CHAT_OAUTH2_CLIENT_ID }}
NATS_ADOPT_LEGACY: ${{ vars.NATS_ADOPT_LEGACY }}
GARAGE_S3_ENDPOINT: ${{ vars.GARAGE_S3_ENDPOINT }}
GARAGE_UPLOADS_BUCKET: ${{ vars.GARAGE_UPLOADS_BUCKET }}
# What it runs with.
NATS_PASSWORD: ${{ secrets.NATS_PASSWORD }}
OAUTH2_CLIENT_SECRET: ${{ secrets.OAUTH2_CLIENT_SECRET }}
CHAT_OAUTH2_CLIENT_SECRET: ${{ secrets.CHAT_OAUTH2_CLIENT_SECRET }}
GARAGE_ACCESS_KEY: ${{ secrets.GARAGE_ACCESS_KEY }}
GARAGE_SECRET_KEY: ${{ secrets.GARAGE_SECRET_KEY }}
SEED_ADMIN_EMAIL: ${{ secrets.SEED_ADMIN_EMAIL }}
SEED_ADMIN_NAME: ${{ secrets.SEED_ADMIN_NAME }}
# Optional: unset, maps are off (the landing hero is empty, a
# location field is two numbers).
MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }}
MAPBOX_STYLE: ${{ vars.MAPBOX_STYLE }}
# Who is who: Rauthy (README.md, "Rauthy"). RAUTHY_HOST and the
# three secrets run it; portal and the chat sign in at OIDC_ISSUER;
# 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 }}
# The money service (README.md, "Payments"): Vipps's keys for the
# Medlemskap sales unit, read by kron alone. All five are needed
# once COMPOSE_PROFILES has `pay`; VIPPS_WEBHOOK_SECRET may wait,
# kron then settles by asking Vipps every minute instead.
VIPPS_MSN: ${{ vars.VIPPS_MSN }}
VIPPS_CLIENT_ID: ${{ secrets.VIPPS_CLIENT_ID }}
VIPPS_CLIENT_SECRET: ${{ secrets.VIPPS_CLIENT_SECRET }}
VIPPS_SUBSCRIPTION_KEY: ${{ secrets.VIPPS_SUBSCRIPTION_KEY }}
VIPPS_WEBHOOK_SECRET: ${{ secrets.VIPPS_WEBHOOK_SECRET }}
steps: steps:
# A missing value stops here, by name, before anything on the host
# is touched. Only names are printed: the log is public.
- name: Write the env files
run: |
missing=
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 \
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; }
pay=
case ",$COMPOSE_PROFILES," in *,pay,*) pay=1;; esac
if [ -n "$pay" ]; then
for v in PAY_HOST VIPPS_MSN VIPPS_CLIENT_ID VIPPS_CLIENT_SECRET VIPPS_SUBSCRIPTION_KEY; do
[ -n "${!v}" ] || missing="$missing $v"
done
[ -z "$missing" ] || { echo "COMPOSE_PROFILES has pay, but not set:$missing"; exit 1; }
fi
umask 077
mkdir -p "$STAGE"
# Interpolated by compose: hosts, versions, profiles. No secret.
cat > "$STAGE/.env" <<EOF
PORTAL_HOST=$PORTAL_HOST
CHAT_HOST=$CHAT_HOST
PORTAL_RELEASE=$PORTAL_RELEASE
GDO_RELEASE=$GDO_RELEASE
CNATS_TAG=$CNATS_TAG
KRON_RELEASE=$KRON_RELEASE
COMPOSE_PROFILES=$COMPOSE_PROFILES
PAY_HOST=$PAY_HOST
RAUTHY_HOST=$RAUTHY_HOST
OIDC_ISSUER=$OIDC_ISSUER
EOF
cat > "$STAGE/portal.env" <<EOF
NATS_URL=nats://portal:$NATS_PASSWORD@nats:4222
PUBLIC_URL=https://$PORTAL_HOST
CHAT_URL=https://$CHAT_HOST
OAUTH2_CLIENT_ID=$OAUTH2_CLIENT_ID
OAUTH2_CLIENT_SECRET=$OAUTH2_CLIENT_SECRET
COOKIE_SECURE=true
CONTENT_REPO=$CONTENT_REPO
CONTENT_BRANCH=$CONTENT_BRANCH
SITE_NAME=$SITE_NAME
PEOPLE_BACKEND=$PEOPLE_BACKEND
RESPONSIBLE_GROUP=$RESPONSIBLE_GROUP
SEED_ADMIN_EMAIL=$SEED_ADMIN_EMAIL
SEED_ADMIN_NAME=$SEED_ADMIN_NAME
NATS_ADOPT_LEGACY=$NATS_ADOPT_LEGACY
GARAGE_S3_ENDPOINT=$GARAGE_S3_ENDPOINT
GARAGE_ACCESS_KEY=$GARAGE_ACCESS_KEY
GARAGE_SECRET_KEY=$GARAGE_SECRET_KEY
GARAGE_UPLOADS_BUCKET=$GARAGE_UPLOADS_BUCKET
MAPBOX_TOKEN=$MAPBOX_TOKEN
MAPBOX_STYLE=$MAPBOX_STYLE
OIDC_ISSUER=$OIDC_ISSUER
RAUTHY_URL=${RAUTHY_HOST:+https://$RAUTHY_HOST}
RAUTHY_API_KEY=$RAUTHY_API_KEY
RAUTHY_LANGUAGE=$RAUTHY_LANGUAGE
EOF
# With the money service in the stack, portal may ask for
# payments without `by_hand`; the address itself is never
# called (the two talk over NATS), the lint only reads that it
# is set. The content repo's lint sets it the same way.
if [ -n "$pay" ]; then
echo "PAY_URL=http://kron:3000" >> "$STAGE/portal.env"
fi
# NATS itself (nats.conf reads NATS_PASSWORD), gdo and the chat.
cat > "$STAGE/nats.env" <<EOF
NATS_PASSWORD=$NATS_PASSWORD
NATS_URL=nats://portal:$NATS_PASSWORD@nats:4222
EOF
cat > "$STAGE/chat.env" <<EOF
OAUTH2_CLIENT_ID=$CHAT_OAUTH2_CLIENT_ID
OAUTH2_CLIENT_SECRET=$CHAT_OAUTH2_CLIENT_SECRET
EOF
# kron: Vipps's keys for the Medlemskap sales unit. Written even
# without the profile, so the file compose names is there.
cat > "$STAGE/kron.env" <<EOF
VIPPS_MSN=$VIPPS_MSN
VIPPS_CLIENT_ID=$VIPPS_CLIENT_ID
VIPPS_CLIENT_SECRET=$VIPPS_CLIENT_SECRET
VIPPS_SUBSCRIPTION_KEY=$VIPPS_SUBSCRIPTION_KEY
WEBHOOK_SECRET=$VIPPS_WEBHOOK_SECRET
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
HQL_SECRET_API=$RAUTHY_SECRET_API
BOOTSTRAP_ADMIN_EMAIL=$SEED_ADMIN_EMAIL
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
# Compose reads an env_file the way it reads compose.yml: "$name" in
# a value is a variable to fill in, and one that is not set comes
# out empty. Every value above is the secret itself, so a "$" left
# in one is literal (Rauthy's API keys are "<name>$<secret>"), and
# "$$" is compose's literal "$". Without this, RAUTHY_API_KEY reached
# portal as "portal" alone, Rauthy answered 401, and every invite
# failed. .env is left alone: it is what compose.yml interpolates.
sed -i 's/\$/$$/g' "$STAGE/portal.env" "$STAGE/nats.env" "$STAGE/chat.env" "$STAGE/rauthy.env" "$STAGE/kron.env"
- name: Pull and bring the stack up - name: Pull and bring the stack up
run: sudo /usr/local/bin/deploy-tomtervel run: sudo /usr/local/bin/deploy-tomtervel
# The sign-in providers Rauthy offers (Vipps Login), kept by the
# deploy through Rauthy's API: rauthy-providers.sh. Unset values
# change nothing.
- name: Sign-in providers in Rauthy
env:
VIPPS_LOGIN_CLIENT_ID: ${{ vars.VIPPS_LOGIN_CLIENT_ID }}
VIPPS_LOGIN_CLIENT_SECRET: ${{ secrets.VIPPS_LOGIN_CLIENT_SECRET }}
run: ./rauthy-providers.sh
# The vel's colours on Rauthy's pages: rauthy-theme.sh. Needs the
# API key to have Clients read and update; without, it says so.
- name: Colours in Rauthy
run: ./rauthy-theme.sh
-63
View File
@@ -1,63 +0,0 @@
# tomtervel.no's DNS: dns/dnsconfig.js, applied to Cloudflare by
# DNSControl on kasse's host runner. A push that touches dns/, on any
# branch, shows what would change (`preview`) and changes nothing. The
# change itself is a person's: Actions -> dns -> Run workflow, on main.
# So merging is not the cutover; pressing the button is.
#
# Push only, never pull_request: the repo is public, and a stranger's pull
# request must not run on kasse with the token. The token is the repo
# secret CLOUDFLARE_API_TOKEN, DNS edit for tomtervel.no only
# (dns/README.md).
name: dns
on:
push:
paths:
- dns/**
- .gitea/workflows/dns.yml
workflow_dispatch:
jobs:
dns:
runs-on: fish
env:
DNSCONTROL_VERSION: ${{ vars.DNSCONTROL_VERSION }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
steps:
- uses: actions/checkout@v4
# The release binary, fetched once per version into the runner's
# own cache (its built-in cache server) and checked against the
# release's checksums when it is.
- name: Cache dnscontrol
id: cache
uses: actions/cache@v4
with:
path: ~/.cache/dnscontrol
key: dnscontrol-${{ vars.DNSCONTROL_VERSION }}-linux-amd64
- name: Fetch dnscontrol
if: steps.cache.outputs.cache-hit != 'true'
run: |
[ -n "$DNSCONTROL_VERSION" ] || { echo "the DNSCONTROL_VERSION variable is not set"; exit 1; }
mkdir -p ~/.cache/dnscontrol
cd "$(mktemp -d)"
base="https://github.com/StackExchange/dnscontrol/releases/download/v$DNSCONTROL_VERSION"
tar="dnscontrol_${DNSCONTROL_VERSION}_linux_amd64.tar.gz"
curl -sfLO "$base/$tar"
curl -sfLO "$base/checksums.txt"
grep " $tar\$" checksums.txt | sha256sum -c -
tar -xzf "$tar" dnscontrol
install -m 0755 dnscontrol ~/.cache/dnscontrol/dnscontrol
- name: check
working-directory: dns
run: ~/.cache/dnscontrol/dnscontrol check
- name: preview
working-directory: dns
run: ~/.cache/dnscontrol/dnscontrol preview
- name: push
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main'
working-directory: dns
run: ~/.cache/dnscontrol/dnscontrol push
+4 -3
View File
@@ -1,8 +1,9 @@
.env .env
portal.env portal.env
chat.env chat.env
kanidm/server.toml
nats/nats.conf
certs/
.kanidm-recovered
gitea-oauth.secret gitea-oauth.secret
dns/cloudflare.env
nats.env
rauthy.env
kron.env kron.env
+10 -4
View File
@@ -1,11 +1,17 @@
# Public TLS for both hosts, real certificates from Let's Encrypt over # Public TLS for both hosts, real certificates from Let's Encrypt over
# HTTP-01: the DNS A records for ${PORTAL_HOST} and ${RAUTHY_HOST} must # HTTP-01: the DNS A records for ${PORTAL_HOST} and ${ID_HOST} must
# point at this host before the first start. # point at this host before the first start.
{$RAUTHY_HOST} { {$ID_HOST} {
reverse_proxy rauthy:8080 # 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
}
}
log { log {
output file /data/konto.log output file /data/id.log
} }
} }
+164 -222
View File
@@ -1,74 +1,114 @@
# Tomter Vel — infrastructure # Tomter Vel — infrastructure
Everything the vel's own site needs on one host, as containers: NATS Everything the vel's own site needs on one host, as containers: Caddy
with JetStream for the records, Rauthy for who is who, portal, the site for TLS, NATS with JetStream for the records, Kanidm for who is who,
itself, and the chat. The content (pages, forms, desks) lives in and portal, the site itself. The content (pages, forms, desks) lives
[tomtervel/questions](https://prosjekt.klingenbergbygg.no/tomtervel/questions) in [tomtervel/questions](https://prosjekt.klingenbergbygg.no/tomtervel/questions)
and is fetched from there; this repo owns the host. and is fetched from there; this repo owns the host.
``` ```
Internet ──► Caddy (Let's Encrypt) Internet ──► Caddy (Let's Encrypt)
├── PORTAL_HOST ──► portal:3000 ──► NATS (records) + Rauthy (login) ├── PORTAL_HOST ──► portal:3000 ──► NATS (records) + Kanidm (login)
├── RAUTHY_HOST ──► rauthy:8080 └── ID_HOST ─────► kanidm:8443 (internal TLS)
└── CHAT_HOST ────► cnats:3000
``` ```
Nothing about the vel's members or records depends on anyone else's Today the vel's draft site runs on Klingenberg Bygg's host as
host: the login, the bus and the site are the vel's own. 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.
## First start ## First start
On a fresh Linux host with podman + podman-compose (run rootful, so Caddy On a fresh Linux host with podman + podman-compose and openssl (run rootful,
can bind 80/443 and Rauthy sees a stable source IP), with a Gitea runner i.e. as root, so Caddy can bind 80/443 and Kanidm sees a stable source IP):
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 ```sh
git clone https://prosjekt.klingenbergbygg.no/tomtervel/infrastructure /srv/tomtervel/infrastructure git clone https://prosjekt.klingenbergbygg.no/tomtervel/infrastructure /srv/tomtervel/infrastructure
sudo install -m 0755 /srv/tomtervel/infrastructure/deploy-tomtervel /usr/local/bin/deploy-tomtervel # and the sudoers line in it cd /srv/tomtervel/infrastructure
# Actions -> deploy -> Run workflow # the env files, and the stack up cp .env.example .env # set PORTAL_HOST and ID_HOST; DNS must point here
sudo sh bootstrap.sh # renders configs, makes the internal cert, starts, recovers Kanidm admin
sh kanidm-setup.sh # logs in, creates the portal client and desk groups, restarts portal
``` ```
Then make the clients and portal's API key in Rauthy ([Rauthy](#rauthy)). `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.
## Running on kasse (behind the host Caddy) ## Running on kasse (behind the host Caddy)
On kasse the host Caddy already owns 80/443, so the bundled Caddy stays The vel keeps its **own** Kanidm and NATS here so it can later lift onto a host
off (`profiles: [edge]`). The services publish loopback-only ports for of its own unchanged — on kasse it just runs in isolation, fronted by kasse's
it, and `host-caddy/tomtervel.no` is its file for them existing host Caddy (which owns 80/443). So the bundled Caddy stays off (it's
(`/etc/caddy/conf.d/tomtervel.no`): behind `profiles: [edge]`); run the default `podman compose up -d --build`.
The services publish loopback-only ports for the host Caddy to reach:
- portal → `127.0.0.1:3050` - portal → `127.0.0.1:3050`
- rauthy → `127.0.0.1:8090` - kanidm → `127.0.0.1:8443` (internal self-signed TLS)
- cnats → `127.0.0.1:3070`
- nats → `127.0.0.1:4223` (kasse's shared platform NATS owns 4222) - nats → `127.0.0.1:4223` (kasse's shared platform NATS owns 4222)
## Accounts and groups Add two host-Caddy site blocks in `/etc/caddy/conf.d/`, using the vel's `.env`
hosts (`vel.klingenbergbygg.no → :3050` already exists):
Rauthy holds the accounts: sign-in, passkeys, the account pages and the ```
account mail, in Norwegian. Portal and the chat sign in there <PORTAL_HOST> {
(`OIDC_ISSUER`), and portal makes the accounts there itself reverse_proxy localhost:3050
(`RAUTHY_API_KEY`): }
<ID_HOST> {
reverse_proxy https://localhost:8443 {
transport http { tls_insecure_skip_verify }
}
}
```
- **The first person in.** The `SEED_ADMIN_EMAIL` secret: at start, Then `sudo systemctl reload caddy`, point the content repo's `lint-and-reload`
portal gives them the most privileged group (the board) and makes reload step at `nats://127.0.0.1:4223`, and retire the old systemd portal:
their account; Rauthy mails them how to set a password or a passkey. `sudo systemctl disable --now app@tomtervel-portal`.
The same address is Rauthy's first admin.
- **Everyone else** is invited from a desk, or given a place by a case ## Accounts, all the way
(`grants:`). Portal makes the account if there is none, and Rauthy
mails the way in. `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.** `SEED_ADMIN_EMAIL` in `.env`: at start,
portal invites them into the most privileged group (the board) and
mails the link, once. Everyone else they invite from their desk.
- **The people who ask the questions.** Everyone a page names as - **The people who ask the questions.** Everyone a page names as
`responsible` gets an account at start and a place in `responsible` gets an account at start, a mail saying they are listed
`RESPONSIBLE_GROUP` (`redaktor`). 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.
The groups are kept in Rauthy (`PEOPLE_BACKEND=rauthy`): an invite ## People and desks
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 Each group in the content (`qualifies:` under `questions/`) is a
desk, "Medlemmer og invitasjoner", where a person is taken out or invited Kanidm group `tomtervel_<group>`, all members of `tomtervel_members`.
again. Portal decides what a group may do, on the site and in the chat's Someone in `tomtervel_styret` logs in and sees the board's desk.
rooms alike. Records in `portal_memberships` are left from before
(Kanidm); nothing new is written there. ```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.
## Content changes ## Content changes
@@ -82,182 +122,47 @@ whose `runs-on` matches that runner's host label, running
`nats --server nats://portal:$NATS_PASSWORD@127.0.0.1:4222 pub portal.content.reload ""`. `nats --server nats://portal:$NATS_PASSWORD@127.0.0.1:4222 pub portal.content.reload ""`.
Until then, `podman compose restart portal` picks up new content. Until then, `podman compose restart portal` picks up new content.
## Money: kron and Vipps MobilePay
Portal decides what is owed - a `payment:` on a state in the content -
and kron, the money service in this stack, asks Vipps MobilePay for
it, pushes it to the person's app, and reports back over NATS. Portal
then moves the record on (`then:`) by itself, as if the treasurer had
pressed the button. The treasurer's desk still works: money that came
to the account some other way is registered there as before.
To bring it up, once per environment:
1. `cp kron.env.example kron.env`, `chmod 600 kron.env`, and fill in
the four keys from the Vipps MobilePay portal (API-nøkler). Test
keys first: `VIPPS_ENV=test`, MSN 563326.
2. Host Caddy: copy `host-caddy/kron.vel.klingenbergbygg.no` into
`/etc/caddy/conf.d/` and `systemctl reload caddy`. Wildcard DNS
already points the name here.
3. `sh register-vipps-webhook.sh` - registers the webhook with Vipps
and writes `WEBHOOK_SECRET` into `kron.env`. Needs `jq`.
4. `podman compose up -d kron`, then `curl 127.0.0.1:3080/healthz`.
5. The content says what is owed: a `payment:` on the paying state in
`aggregates.yaml` in tomtervel/questions, without `by_hand`. The
content repo's lint needs `PAY_URL` set to allow that, the same as
the `portal` service here.
Production is the same five steps with the production keys and
`VIPPS_ENV=prod`. `KRON_RELEASE` in `.env` is a bendik/kron tag on
Docker Hub; bumping it is the upgrade.
## Upgrading portal ## Upgrading portal
Set the org variable `PORTAL_RELEASE` (a tag of uhhm/portal) and run the Bump `PORTAL_RELEASE` in `.env` (a tag of uhhm/portal) and
deploy workflow. The content repo's lint reads the same variable, so the `podman compose up -d --build portal`. Keep `IRIS_RELEASE` in the
two cannot drift apart. content repo's workflow matched to it.
## Variables and secrets
Every value the stack runs with is an Actions variable or secret in
Gitea, never a file in the repo (it is public) and never edited on the
host. The deploy workflow writes them into the env files on kasse
(`.env`, `portal.env`, `nats.env`, `chat.env`) on every run, so a host
name or a version is changed in Gitea, and then **Actions -> deploy ->
Run workflow**. Set them with `gt` (`gt variable set NAME --body ...`,
`gt secret set NAME`, `-o tomtervel` for the org's).
| name | kind | where | what |
|---|---|---|---|
| `PORTAL_HOST`, `RAUTHY_HOST`, `CHAT_HOST` | variable | repo | the site, the login, the chat; each needs DNS (`dns/`) and a kasse Caddy block |
| `PORTAL_RELEASE` | variable | **org** | a uhhm/portal tag; the content repo's lint reads the same one |
| `GDO_RELEASE`, `CNATS_TAG`, `KRON_RELEASE` | variable | repo | the mailer, the chat, the money service |
| `COMPOSE_PROFILES` | variable | repo | `chat` |
| `CONTENT_REPO`, `CONTENT_BRANCH` | variable | repo | the content this site serves |
| `SITE_NAME` | variable | repo | `tomtervel`; never changed (a new name is a new, empty site) |
| `PEOPLE_BACKEND`, `RESPONSIBLE_GROUP` | variable | repo | `rauthy`, `redaktor` |
| `OAUTH2_CLIENT_ID`, `CHAT_OAUTH2_CLIENT_ID` | variable | repo | the Rauthy clients of the site and the chat: `portal`, `chat` |
| `NATS_ADOPT_LEGACY` | variable | repo | `sole` |
| `GARAGE_S3_ENDPOINT`, `GARAGE_UPLOADS_BUCKET` | variable | repo | uploads |
| `NATS_PASSWORD` | secret | **org** | the stack's NATS; the content repo's reload uses it too |
| `OAUTH2_CLIENT_SECRET` | secret | repo | the site's Rauthy client |
| `CHAT_OAUTH2_CLIENT_SECRET` | secret | repo | the chat's Rauthy client |
| `GARAGE_ACCESS_KEY`, `GARAGE_SECRET_KEY` | secret | repo | uploads |
| `SEED_ADMIN_EMAIL`, `SEED_ADMIN_NAME` | secret | repo | the first person in; an address, so not a variable |
| `CLOUDFLARE_API_TOKEN` | secret | repo | DNS edit for tomtervel.no only (`dns/`) |
| `MAPBOX_TOKEN` | secret | repo | optional: the map tiles portal proxies (the landing hero, location fields); unset, maps are off |
| `MAPBOX_STYLE` | variable | repo | optional: `<owner>/<style>`; unset, `mapbox/streets-v12` |
| `DNSCONTROL_VERSION` | variable | repo | the DNS workflow's dnscontrol |
| `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` |
| `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 |
| `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.
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=chat,pay`). Portal
decides when money is owed: a household entering `open` or `fornyes` in
the content's aggregates owes the fee, and portal publishes one request
on this stack's NATS. kron answers at once 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 says `paid`
on the bus; portal moves the household to `betalt`, grants `medlemmer`,
and mails them. Vipps's keys live in `kron.env` and nowhere else; portal
never calls Vipps. `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`, `VIPPS_MSN` and the three key secrets (table above).
The keys are in `pass` as `tomtervel/vipps/medlemskap`.
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=chat,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
[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.
On a new host:
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
```
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`.
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
`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
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 ## Backups
- Rauthy's database is the `rauthy_data` volume: the accounts, passkeys - Kanidm writes a nightly backup into its volume (`/data/backups`,
and clients. Snapshot it with NATS's. seven kept); copy that directory off the host.
- NATS JetStream data is the `nats_data` volume: every record ever - NATS JetStream data is the `nats_data` volume: every record ever
submitted and every state change, the memberships and the chat's submitted and every state change. Snapshot the volume.
history. Snapshot the volume.
- Caddy's certificates regenerate; nothing to keep. - Caddy's certificates regenerate; nothing to keep.
## What is not here ## What is not here
@@ -266,14 +171,6 @@ 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 the vel's current website at tomtervel.no, which stays where it is
until the vel points the apex at PORTAL_HOST. 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 ## Mail
Portal decides what to send - a `mail:` on a state in the content, or an Portal decides what to send - a `mail:` on a state in the content, or an
@@ -294,6 +191,51 @@ 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 turn a reply into a note on the record it answers, and none of them are set
here. 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 ## Mail leaving the host
gdo hands the vel's mail to kasse's own postfix over the container gdo hands the vel's mail to kasse's own postfix over the container
Executable
+69
View File
@@ -0,0 +1,69 @@
#!/bin/sh
# First start on a fresh host. Idempotent: rerunning renders configs
# again and skips what exists. Needs podman + podman-compose and openssl,
# and DNS for PORTAL_HOST and ID_HOST already pointing here. Run rootful
# (as root) so Caddy can bind 80/443 and Kanidm sees a stable source IP.
#
# cp .env.example .env # fill in the hosts
# sudo sh bootstrap.sh
set -eu
cd "$(dirname "$0")"
[ -f .env ] || { echo "copy .env.example to .env and fill it in first"; exit 1; }
. ./.env
# A NATS password, once.
if [ -z "${NATS_PASSWORD:-}" ]; then
NATS_PASSWORD=$(openssl rand -base64 36 | tr -d '/+=' | cut -c1-40)
sed -i "s|^NATS_PASSWORD=.*|NATS_PASSWORD=$NATS_PASSWORD|" .env
echo "NATS_PASSWORD generated into .env"
fi
# Rendered configs (gitignored).
sed "s|\${ID_HOST}|$ID_HOST|g" kanidm/server.toml.tpl > kanidm/server.toml
sed "s|\${NATS_PASSWORD}|$NATS_PASSWORD|g" nats/nats.conf.tpl > nats/nats.conf
# The onboarding token is written by kanidm-setup.sh, once; a rerun of
# this script must not lose it, or every invite fails closed again.
kept_token=$(grep '^KANIDM_API_TOKEN=' portal.env 2>/dev/null | head -1 || true)
cat > portal.env <<EOF
NATS_URL=nats://portal:$NATS_PASSWORD@nats:4222
KANIDM_URL=https://$ID_HOST
OAUTH2_CLIENT_ID=$OAUTH2_CLIENT_ID
OAUTH2_CLIENT_SECRET=${OAUTH2_CLIENT_SECRET:-}
PUBLIC_URL=https://$PORTAL_HOST
COOKIE_SECURE=true
CONTENT_REPO=$CONTENT_REPO
CONTENT_BRANCH=$CONTENT_BRANCH
SITE_NAME=$SITE_NAME
SEED_ADMIN_EMAIL=${SEED_ADMIN_EMAIL:-}
SEED_ADMIN_NAME=${SEED_ADMIN_NAME:-}
RESPONSIBLE_GROUP=${RESPONSIBLE_GROUP:-}
EOF
[ -n "$kept_token" ] && echo "$kept_token" >> portal.env
chmod 600 portal.env
# 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
podman compose up -d --build
echo "containers up; Caddy is fetching certificates for $PORTAL_HOST and $ID_HOST"
# The Kanidm admin accounts exist only after the first start; their
# passwords are set by recovery. Do this once; the output is the
# password, shown once.
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)"
+50 -61
View File
@@ -1,4 +1,4 @@
# Tomter Vel's own platform: portal + its own Rauthy and NATS as podman # Tomter Vel's own platform: portal + its own Kanidm and NATS as podman
# containers. The content (pages, forms, desks) is not here: portal fetches # containers. The content (pages, forms, desks) is not here: portal fetches
# it from tomtervel/questions on prosjekt.klingenbergbygg.no and hot-reloads # it from tomtervel/questions on prosjekt.klingenbergbygg.no and hot-reloads
# it over NATS. This repo owns identity, the bus, and which portal version # it over NATS. This repo owns identity, the bus, and which portal version
@@ -6,9 +6,11 @@
# (`--profile edge`) terminates it; on kasse the host Caddy already owns # (`--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). # 80/443 and reverse-proxies vel.klingenbergbygg.no -> portal (127.0.0.1:3050).
# #
# Everything it runs with is an Actions variable or secret, written by # bootstrap.sh first time on a fresh host: renders configs from
# the deploy workflow (README.md); `podman compose up -d --build` is # .env, makes Kanidm's internal cert, starts it all,
# what deploy-tomtervel runs. # recovers the Kanidm admin, creates the portal client
# and desk groups.
# podman compose up -d --build every time after that.
name: tomtervel name: tomtervel
@@ -27,21 +29,19 @@ services:
- "443:443/udp" - "443:443/udp"
environment: environment:
PORTAL_HOST: ${PORTAL_HOST} PORTAL_HOST: ${PORTAL_HOST}
RAUTHY_HOST: ${RAUTHY_HOST} ID_HOST: ${ID_HOST}
volumes: volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro - ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data - caddy_data:/data
- caddy_config:/config - caddy_config:/config
depends_on: depends_on:
- portal - portal
- rauthy - kanidm
nats: nats:
image: nats:2.14.6-alpine image: nats:2.14.6-alpine
restart: unless-stopped restart: unless-stopped
command: ["-c", "/etc/nats/nats.conf"] command: ["-c", "/etc/nats/nats.conf"]
# NATS_PASSWORD, which nats.conf reads from the environment.
env_file: nats.env
volumes: volumes:
- ./nats/nats.conf:/etc/nats/nats.conf:ro - ./nats/nats.conf:/etc/nats/nats.conf:ro
- nats_data:/data - nats_data:/data
@@ -58,41 +58,33 @@ services:
timeout: 5s timeout: 5s
retries: 3 retries: 3
# Rauthy: who is who. Sign-in, account pages and account mail, in kanidm:
# Norwegian; portal and the chat sign in here (OIDC_ISSUER) and portal image: kanidm/server:1.11.2
# 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:
image: ghcr.io/sebadob/rauthy:${RAUTHY_TAG:-0.37.2}
restart: unless-stopped restart: unless-stopped
env_file:
- path: rauthy.env
required: false
environment: environment:
PUB_URL: ${RAUTHY_HOST:-no-host-set} KANIDM_CONFIG_PATH: /data/server.toml
RP_ID: ${RAUTHY_HOST:-no-host-set}
# Rauthy wants the port spelled out.
RP_ORIGIN: https://${RAUTHY_HOST:-no-host-set}:443
extra_hosts:
- "host.containers.internal:host-gateway"
volumes: volumes:
- ./rauthy/config.toml:/app/config.toml:ro - kanidm_data:/data
- rauthy_data:/app/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: ports:
- "127.0.0.1:8090:8080" - "127.0.0.1:8443:8443"
portal: portal:
build: build:
context: ./portal context: ./portal
args: args:
PORTAL_RELEASE: ${PORTAL_RELEASE} 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 restart: unless-stopped
# Written by the deploy workflow from the Actions variables and
# secrets (README.md has the table).
env_file: portal.env env_file: portal.env
environment: environment:
LEPTOS_SITE_ADDR: 0.0.0.0:3000 LEPTOS_SITE_ADDR: 0.0.0.0:3000
@@ -103,6 +95,11 @@ services:
# The namespace of everything this site keeps on NATS from portal 0.9. # The namespace of everything this site keeps on NATS from portal 0.9.
# Must not change: a new name is a new, empty site. # Must not change: a new name is a new, empty site.
SITE_NAME: tomtervel SITE_NAME: tomtervel
# The money service is there: the lint then allows `payment:` without
# `by_hand: true`. Nothing at run time reads it - a request is
# published whenever the content did not say by_hand - so the same
# variable has to be set where the content repo's lint runs.
PAY_URL: http://kron:3000
volumes: volumes:
- learn_cache:/app/learn-cache - learn_cache:/app/learn-cache
ports: ports:
@@ -113,7 +110,7 @@ services:
depends_on: depends_on:
nats: nats:
condition: service_healthy condition: service_healthy
rauthy: kanidm:
condition: service_started condition: service_started
# The mailer. Portal decides what to send - a `mail:` on a state in the # The mailer. Portal decides what to send - a `mail:` on a state in the
@@ -129,9 +126,8 @@ services:
args: args:
GDO_RELEASE: ${GDO_RELEASE} GDO_RELEASE: ${GDO_RELEASE}
restart: unless-stopped restart: unless-stopped
# NATS_URL, with the password: made by bootstrap.sh, never committed.
env_file: nats.env
environment: environment:
NATS_URL: nats://portal:${NATS_PASSWORD}@nats:4222
# The host, from inside the container. Podman resolves this to the # The host, from inside the container. Podman resolves this to the
# gateway; the host's postfix listens on 0.0.0.0:25. # gateway; the host's postfix listens on 0.0.0.0:25.
SMTP_HOST: host.containers.internal SMTP_HOST: host.containers.internal
@@ -144,28 +140,22 @@ services:
nats: nats:
condition: service_healthy condition: service_healthy
# The money service (uhhm/kron): portal asks for a payment on this # The money service. Portal decides what is owed - a `payment:` on a
# NATS as a household owes its fee, kron gives it a link to pay by, # state in the content - and publishes the request on this NATS; kron
# talks to Vipps's ePayment API for the Medlemskap sales unit, and # is what asks Vipps MobilePay for it, pushes it to the person's app,
# says `paid` back on the same bus. Vipps's keys are in kron.env and # and says on the same NATS what became of it. One kron per site, its
# nowhere else; portal never calls Vipps. Host-published for kasse's # keys in kron.env and nowhere else. Host-published for kasse's host
# host Caddy (betaling.tomtervel.no -> here): the pay links, the page # Caddy (kron.vel.klingenbergbygg.no -> here): Vipps has to reach
# people come back to from Vipps, and Vipps's webhooks. A profile, since # /webhook over public HTTPS, and a person who paid by link lands on
# it needs kron.env: COMPOSE_PROFILES gains `pay` once the keys are set. # /returned/<id>.
kron: kron:
profiles: ["pay"] image: docker.io/bendik/kron:${KRON_RELEASE}
image: project.uhhm.no/uhhm/kron:${KRON_RELEASE:-no-tag-set}
restart: unless-stopped restart: unless-stopped
env_file: env_file: kron.env
- nats.env
- kron.env
environment: environment:
# Must be the portal's own: a request names its site. NATS_URL: nats://portal:${NATS_PASSWORD}@nats:4222
SITE_NAME: tomtervel SITE_NAME: tomtervel
PROVIDER: vipps PUBLIC_URL: https://kron.${PORTAL_HOST}
VIPPS_ENV: prod
PUBLIC_URL: https://${PAY_HOST:-no-host-set}
LISTEN_ADDR: 0.0.0.0:3000
ports: ports:
- "127.0.0.1:3080:3000" - "127.0.0.1:3080:3000"
depends_on: depends_on:
@@ -188,15 +178,14 @@ services:
image: docker.io/bendik/cnats:${CNATS_TAG:-no-tag-set} image: docker.io/bendik/cnats:${CNATS_TAG:-no-tag-set}
restart: unless-stopped restart: unless-stopped
env_file: env_file:
- nats.env
- path: chat.env - path: chat.env
required: false required: false
environment: environment:
# Must be the portal's own: a new name is a new, empty chat. # Must be the portal's own: a new name is a new, empty chat.
SITE_NAME: tomtervel SITE_NAME: tomtervel
# Rauthy: https://<RAUTHY_HOST>/auth/v1/ NATS_URL: nats://portal:${NATS_PASSWORD}@nats:4222
OIDC_ISSUER: ${OIDC_ISSUER} KANIDM_URL: https://${ID_HOST}
PUBLIC_URL: https://${CHAT_HOST} PUBLIC_URL: https://${CHAT_HOST:-chat.vel.klingenbergbygg.no}
COOKIE_SECURE: "true" COOKIE_SECURE: "true"
ports: ports:
- "127.0.0.1:3070:3000" - "127.0.0.1:3070:3000"
@@ -221,12 +210,12 @@ volumes:
caddy_data: caddy_data:
caddy_config: caddy_config:
nats_data: nats_data:
rauthy_data: kanidm_data:
learn_cache: learn_cache:
# Pin the project network subnet inside 172.16/12 so Rauthy's trusted # Pin the project network subnet inside 172.16/12 so Kanidm's X-Forwarded-For
# proxies (rauthy/config.toml) stay valid under Podman — its default pool # trust (kanidm/server.toml.tpl) stays valid under Podman — its default pool
# hands out 10.89.x addresses that the forwarded client IP can't match. # hands out 10.89.x addresses that Caddy's forwarded client IP can't match.
networks: networks:
default: default:
ipam: ipam:
-57
View File
@@ -1,57 +0,0 @@
#!/usr/bin/env bash
# Tomter Vel's stack, brought up from its own repo. This is the whole of
# what CI may do as root for the vel: pull main, put the env files the
# deploy workflow wrote in place, and bring the compose project up. It
# takes no arguments, so there is nothing for a workflow to point
# somewhere else.
#
# The env files come from the repo's and org's Actions variables and
# secrets: the workflow writes them, as the runner, into $stage (the
# runner's own, 0700), and this script moves them into the checkout as
# root's, 0600, and leaves nothing behind in $stage.
#
# Install: sudo install -m 0755 -o root -g root \
# deploy-tomtervel /usr/local/bin/deploy-tomtervel
# Grant: gitea-runner ALL=(root) NOPASSWD: /usr/local/bin/deploy-tomtervel
set -euo pipefail
root=/srv/tomtervel/infrastructure
stage=/var/lib/gitea-runner/tomtervel-env
files=(.env portal.env nats.env chat.env)
# Written only when the site runs what needs it (Rauthy).
optional=(rauthy.env)
[ -d "$root/.git" ] || { echo "no checkout at $root - bootstrap it first" >&2; exit 1; }
for f in "${files[@]}"; do
[ -s "$stage/$f" ] || { echo "no $stage/$f - the deploy workflow writes it" >&2; exit 1; }
done
cd "$root"
git fetch --quiet origin main
git reset --hard --quiet origin/main
for f in "${files[@]}"; do
install -m 0600 -o root -g root "$stage/$f" "$root/$f"
rm -f "$stage/$f"
done
for f in "${optional[@]}"; do
[ -s "$stage/$f" ] || continue
install -m 0600 -o root -g root "$stage/$f" "$root/$f"
rm -f "$stage/$f"
done
# --build so a bumped PORTAL_RELEASE or GDO_RELEASE is actually fetched.
podman compose up -d --build
# The vel's portal, reached the way the host Caddy reaches it. No
# forwarded header on purpose: a check that sends the one Caddy sends
# cannot tell you the site is broken for everything that is not Caddy.
code=000
for n in $(seq 1 30); do
code=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:3050/ || true)
[ "$code" = 200 ] && break
sleep 2
done
podman compose ps --format '{{.Names}} {{.State}}' || true
echo "portal http $code after $((n * 2))s"
[ "$code" = 200 ]
-71
View File
@@ -1,71 +0,0 @@
# tomtervel.no's DNS
The zone is `dnsconfig.js`, applied to Cloudflare with
[DNSControl](https://dnscontrol.org). No state file: every run compares
the file with the live zone, so it can be run by anyone with the token,
from any machine.
## From CI
`.gitea/workflows/dns.yml` runs on kasse's host runner. Every push that
touches `dns/`, on any branch, runs `check` and `preview`: the run's log
is the diff, and nothing changes. Applying it is a person pressing
**Actions -> dns -> Run workflow** on `main`, so merging is never the
cutover by accident. The token is the repo secret `CLOUDFLARE_API_TOKEN`.
## By hand
```sh
paru -S dnscontrol
cd dns
# The token in dns/cloudflare.env (gitignored, chmod 600), one line:
# CLOUDFLARE_API_TOKEN=...
set -a; . ./cloudflare.env; set +a # bash; in fish: export (cat cloudflare.env)
dnscontrol check # the file parses
dnscontrol preview # what would change, nothing changed
dnscontrol push # change it
```
`creds.json` names the token by its variable only, so it is in the repo.
The account ID is not needed (it is only for creating zones), and there
is no state to keep, so no S3 keys either.
## The token
tomtervel.no is in Bendik's father's Cloudflare account. He makes a token
for it (My Profile -> API Tokens -> Create Token -> "Edit zone DNS"),
with **Zone / DNS / Edit** for **tomtervel.no only**, and hands it over
outside of git. A token for one zone's DNS can do nothing else in the
account. Revoke it there when it is no longer needed.
## Before the first push
The file was written from what the zone publishes, which is not all of
it: a record Cloudflare holds that nobody looks up from outside would
not be in it, and `push` deletes what is not in the file. So once:
```sh
dnscontrol get-zones --format=js cloudflare - tomtervel.no > /tmp/tomtervel-live.js
```
and compare it with `dnsconfig.js`. Anything there that is still used
goes into the file. Then `preview`, and read every line of it: the
first push is meant to change the apex and `www` (from proxied to
kasse), add `id`, `chat` and `_dmarc`, and change the SPF record.
Nothing about Zoho's MX should appear.
## Order, when the vel moves here
1. On kasse, `kasse-dkim-tomtervel.sh` makes the vel's signing key and
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`, `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.
The hosts in `dnsconfig.js` and the `*_HOST` variables are the same names
and have to stay so; DNSControl does not read the variables.
-7
View File
@@ -1,7 +0,0 @@
{
"none": { "TYPE": "NONE" },
"cloudflare": {
"TYPE": "CLOUDFLAREAPI",
"apitoken": "$CLOUDFLARE_API_TOKEN"
}
}
-78
View File
@@ -1,78 +0,0 @@
// tomtervel.no, all of it, as DNSControl applies it to Cloudflare.
//
// cd dns
// CLOUDFLARE_API_TOKEN=... dnscontrol preview # what would change
// CLOUDFLARE_API_TOKEN=... dnscontrol push # change it
//
// This file is the whole zone: a record that is in Cloudflare and not
// here is deleted on push. `preview` lists every deletion first, so read
// it before every push. See dns/README.md.
var REG_NONE = NewRegistrar("none");
var DSP_CLOUDFLARE = NewDnsProvider("cloudflare");
// kasse: Klingenberg Bygg's host, where the vel's stack runs (portal,
// 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";
// kasse's rspamd signs mail From @tomtervel.no with this key (selector
// `kasse`). It is the public half, printed by kasse-dkim-tomtervel.sh;
// the private half stays on kasse. Empty: no record yet, and the site
// must keep sending from klingenbergbygg.no (site.yaml `mail.from`).
var KASSE_DKIM = "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnFk6GpG/SKmBsed+iiuDQZmyZB/SyUqAqMsEDhZTzMSy8m4hW1TPhIUwZmq4c9RTyX8OPM8FhQMiMLjpAxWHQeOMV6AesbpCU+bdTZBddJyLFF5D7o5UKIEUuByAuZbBAvX0R/irQAtNbgeYiDpRwtg60dpoR6HfhA71xBKu8k4C0N4fMQk+SZundzCrOPVGQKSZUVcl5cH92V9SiRlj3y9SFlQIbqaJLA9F3zF4O4yJZ378ov93PFmGyHyG6OhA1KS6aFHxUbxflolKffXXbSjQUZvOhw/+zXEd0agCOmZVYOoeQcZdeHa59qdA7MV2P1/lfbDKHnuTVNiq8zI5kwIDAQAB";
D("tomtervel.no", REG_NONE, DnsProvider(DSP_CLOUDFLARE),
DefaultTTL(1), // Cloudflare's "auto"
// The site, the login and the chat. Not proxied: kasse's Caddy gets
// the certificates itself, and the login's cookies and the chat's
// websockets reach it as they are.
A("@", KASSE, CF_PROXY_OFF),
CNAME("www", "tomtervel.no.", CF_PROXY_OFF),
A("konto", KASSE, CF_PROXY_OFF),
// The money service (kron): pay links and Vipps's webhooks.
A("betaling", 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),
// 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
// old host must also know the name (a domain alias there). Drop it
// when nobody needs the old site.
A("gammel", "104.198.14.52", CF_PROXY_ON),
// The board's inbox, post@tomtervel.no, is at Zoho.
MX("@", 10, "mx.zoho.eu."),
MX("@", 20, "mx2.zoho.eu."),
MX("@", 50, "mx3.zoho.eu."),
TXT("@", "zoho-verification=zb14986736.zmverify.zoho.eu"),
// Who may send as @tomtervel.no: Zoho, for the board's own mail, and
// kasse, for the site's. One SPF record only; two break both.
TXT("@", "v=spf1 include:zoho.eu ip4:" + KASSE + " ~all"),
// Reports only, to start. Tighten to p=quarantine once the reports
// show both Zoho and kasse passing.
TXT("_dmarc", "v=DMARC1; p=none; rua=mailto:post@tomtervel.no"),
// Zoho's DKIM key, as it stands today: on the zone's apex, where no
// receiver looks for it, so mail from Zoho is unsigned in effect. Zoho
// Mail's admin (Domains -> Email configuration -> DKIM) names its
// selector; move it to TXT("<selector>._domainkey", ...) and drop it here.
TXT("@", "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCA2wb0ETspWV0uV8xjxBb4s0e+Ybe7Uh1CJgboXvZmBdZyUEfduuUXwBpJD+XuIXoaE16zGzeheVxwzMy4tvLa/FQ9XDZVQOSgUUoSyta1MHi5pPjgpmhqngEQczCrBzBuK/ew+biIdwNhyEHB738mxHTDTyY013Pob1cU9EFB+wIDAQAB"),
// Left from before; whoever set it up may still use Search Console.
TXT("@", "google-site-verification=ElKwNmdiHDNHHrK07rI9zWAIO979bkxbPOp1rWcG8ZY"),
KASSE_DKIM ? TXT("kasse._domainkey", KASSE_DKIM) : []
);
+1 -1
View File
@@ -25,7 +25,7 @@ RUN pacman-key --init \
'SigLevel = Required DatabaseOptional' \ 'SigLevel = Required DatabaseOptional' \
'Server = https://project.uhhm.no/api/packages/bl/arch/$repo/$arch' \ 'Server = https://project.uhhm.no/api/packages/bl/arch/$repo/$arch' \
>> /etc/pacman.conf \ >> /etc/pacman.conf \
&& pacman -Syu --noconfirm --needed ca-certificates gdo \ && pacman -Sy --noconfirm --needed ca-certificates gdo \
&& pacman -Scc --noconfirm \ && pacman -Scc --noconfirm \
&& rm -rf /var/cache/pacman/pkg/* /var/lib/pacman/sync/* && rm -rf /var/cache/pacman/pkg/* /var/lib/pacman/sync/*
+6
View File
@@ -0,0 +1,6 @@
# kasse's host Caddy: /etc/caddy/conf.d/kron.vel.klingenbergbygg.no.
# Vipps MobilePay delivers webhooks here, and a person who paid by link
# comes back here; both go to the vel stack's kron (127.0.0.1:3080).
kron.vel.klingenbergbygg.no {
reverse_proxy 127.0.0.1:3080
}
-75
View File
@@ -1,75 +0,0 @@
# kasse's host Caddy: /etc/caddy/conf.d/tomtervel.no. The vel's own
# names, in dns/dnsconfig.js, pointing here unproxied; Caddy gets their
# certificates itself as soon as the records point here. The same as the
# vel.klingenbergbygg.no blocks beside it, which stay until the move is
# done.
tomtervel.no {
reverse_proxy 127.0.0.1:3050
}
www.tomtervel.no {
redir https://tomtervel.no{uri} permanent
}
# The old login, Kanidm, is gone: its name sends people on to Rauthy.
id.tomtervel.no {
redir https://konto.tomtervel.no permanent
}
# 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
}
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 money service (kron, README.md "Payments"): the pay links portal
# gives out, the page people come back to from Vipps, and Vipps's
# webhooks. Kept out of search engines; nothing here is a page to find.
betaling.tomtervel.no {
header X-Robots-Tag "noindex, nofollow"
reverse_proxy 127.0.0.1:3080
}
# 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
}
+196
View File
@@ -0,0 +1,196 @@
#!/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
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
# Secrets into portal.env, never printed. The token is shown once, by
# Kanidm, at creation; a rerun keeps the one portal.env already has.
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; }
secret=$($K system oauth2 show-basic-secret $C 2>/dev/null | tail -1)
sed -i "s|^OAUTH2_CLIENT_SECRET=.*|OAUTH2_CLIENT_SECRET=$secret|" .env
setenv OAUTH2_CLIENT_SECRET "$secret"
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"
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
# The first person in, if .env names one: portal invites them into the
# most privileged group on its next start, once, and mails the link.
if [ -n "${SEED_ADMIN_EMAIL:-}" ]; then setenv SEED_ADMIN_EMAIL "$SEED_ADMIN_EMAIL"; fi
if [ -n "${SEED_ADMIN_NAME:-}" ]; then setenv SEED_ADMIN_NAME "$SEED_ADMIN_NAME"; fi
if [ -n "${RESPONSIBLE_GROUP:-}" ]; then setenv RESPONSIBLE_GROUP "$RESPONSIBLE_GROUP"; fi
# Where the groups live: `memberships` keeps them in portal, and this
# Kanidm only makes the accounts (portal docs, Memberships).
if [ -n "${PEOPLE_BACKEND:-}" ]; then setenv PEOPLE_BACKEND "$PEOPLE_BACKEND"; fi
podman compose up -d portal
echo "portal restarted: signs in through $C, onboards through $SA, desks: $(echo $groups)"
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
@@ -0,0 +1,30 @@
# 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
-41
View File
@@ -1,41 +0,0 @@
#!/bin/bash
# Run on kasse (see dns/README.md): rspamd signs mail From @tomtervel.no with its own DKIM key
# (selector "kasse"), beside klingenbergbygg.no and dodre.no. Additive:
# the other domains' signing is untouched. Safe to rerun.
set -euo pipefail
K=/var/lib/rspamd/dkim/tomtervel.no.kasse.key
C=/etc/rspamd/local.d/dkim_signing.conf
sudo cp -n "$C" "$C.before-tomtervel"
if ! sudo test -f "$K"; then
sudo rspamadm dkim_keygen -d tomtervel.no -s kasse -b 2048 -k "$K" | sudo tee /root/tomtervel-dkim-dns.txt >/dev/null
fi
sudo chown rspamd:rspamd "$K"
sudo chmod 600 "$K"
if ! sudo grep -q '"tomtervel.no"' "$C"; then
sudo python3 - "$C" <<'PY'
import sys
p = sys.argv[1]
s = open(p).read()
block = ''' "tomtervel.no" {
path = "/var/lib/rspamd/dkim/tomtervel.no.kasse.key";
selector = "kasse";
}
'''
i = s.rstrip().rfind('}') # the closing brace of domain { ... }
s = s[:i] + block + s[i:]
open(p, 'w').write(s)
PY
fi
sudo rspamadm configtest
sudo systemctl reload rspamd
systemctl is-active rspamd
echo
echo "== dkim_signing.conf"
sudo grep -vE '^\s*(#|$)' "$C"
echo
echo "== Publish this as TXT kasse._domainkey.tomtervel.no (the p= value, joined into one string):"
sudo cat /root/tomtervel-dkim-dns.txt
+19
View File
@@ -0,0 +1,19 @@
# kron, the money service beside portal: Vipps MobilePay for Tomter Vel.
# Copy to kron.env (root, mode 600, like portal.env) and fill in the
# values from the Vipps MobilePay portal, API-nøkler. Never commit kron.env.
#
# Test first: VIPPS_ENV=test with the keys from "API-nøkler – test"
# (MSN 563326); production is the same five lines with the production
# keys and VIPPS_ENV=prod.
PROVIDER=vipps
VIPPS_ENV=test
VIPPS_MSN=563326
VIPPS_CLIENT_ID=
VIPPS_CLIENT_SECRET=
# Ocp-Apim-Subscription-Key (primær). The secondary exists so this one
# can be rotated without downtime; kron takes one at a time.
VIPPS_SUBSCRIPTION_KEY=
# From registering <PUBLIC_URL>/webhook with Vipps: register-vipps-webhook.sh
# fills this in. Until it is set every webhook is refused and payments
# settle by the sweep alone, which works but is slower.
WEBHOOK_SECRET=
+2 -3
View File
@@ -1,6 +1,5 @@
# NATS with JetStream: portal's records, events and projections live # NATS with JetStream: portal's records, events and projections live
# here. The password is NATS_PASSWORD from the container's environment # here. bootstrap.sh renders this into nats.conf from .env.
# (nats.env, written by the deploy workflow from the org secret).
port: 4222 port: 4222
http_port: 8222 http_port: 8222
@@ -11,7 +10,7 @@ max_connections: 1000
# (nats://user:pass@host) behave the same in every client library. # (nats://user:pass@host) behave the same in every client library.
authorization { authorization {
users = [ users = [
{ user: "portal", password: $NATS_PASSWORD } { user: "portal", password: "${NATS_PASSWORD}" }
] ]
} }
+1 -4
View File
@@ -12,10 +12,7 @@
# reason. # reason.
FROM archlinux:base FROM archlinux:base
ARG PORTAL_RELEASE ARG PORTAL_RELEASE
# -Syu, never -Sy: a partial upgrade pulls a library newer than what the RUN pacman -Sy --noconfirm --needed ca-certificates curl \
# base image's own pacman was built against (openssl 4, November 2026) and
# refuses to install.
RUN pacman -Syu --noconfirm --needed ca-certificates curl \
&& pacman -Scc --noconfirm \ && pacman -Scc --noconfirm \
&& rm -rf /var/cache/pacman/pkg/* /var/lib/pacman/sync/* && rm -rf /var/cache/pacman/pkg/* /var/lib/pacman/sync/*
WORKDIR /app WORKDIR /app
-45
View File
@@ -1,45 +0,0 @@
#!/usr/bin/env bash
# The sign-in providers Rauthy offers beside its own accounts, as the
# deploy keeps them: today Vipps Login. Rauthy has no file for this, only
# its API, so this script is the file: run on every deploy, it makes the
# provider the first time and updates it after, by name, so a change here
# is a change in Rauthy. Needs RAUTHY_HOST, RAUTHY_API_KEY (AuthProviders
# read/create/update), VIPPS_LOGIN_CLIENT_ID and VIPPS_LOGIN_CLIENT_SECRET;
# with any of them unset it changes nothing and says so.
#
# Vipps's side: the sales unit's Vipps Login must have the redirect URI
# https://<RAUTHY_HOST>/auth/v1/providers/callback registered, or every
# sign-in is refused there.
#
# auto_link: a Vipps sign-in whose (Vipps-verified) email is an account
# here already is linked to that account, so the board's password and
# passkey accounts and Vipps lead to the same person and the same groups.
# Without it Rauthy refuses the sign-in and asks them to link it from
# their account page first, which nobody finds. auto_onboarding: a new
# address becomes an account on the spot.
set -euo pipefail
for v in RAUTHY_HOST RAUTHY_API_KEY VIPPS_LOGIN_CLIENT_ID VIPPS_LOGIN_CLIENT_SECRET; do
[ -n "${!v:-}" ] || { echo "rauthy-providers: $v is not set; nothing changed"; exit 0; }
done
base="https://$RAUTHY_HOST/auth/v1"
auth="Authorization: API-Key $RAUTHY_API_KEY"
vipps=$(jq -n --arg id "$VIPPS_LOGIN_CLIENT_ID" --arg secret "$VIPPS_LOGIN_CLIENT_SECRET" '{
name: "Vipps", typ: "custom", enabled: true,
issuer: "https://api.vipps.no/access-management-1.0/access/",
authorization_endpoint: "https://api.vipps.no/access-management-1.0/access/oauth2/auth",
token_endpoint: "https://api.vipps.no/access-management-1.0/access/oauth2/token",
userinfo_endpoint: "https://api.vipps.no/vipps-userinfo-api/userinfo",
jwks_endpoint: "https://api.vipps.no/access-management-1.0/access/.well-known/jwks.json",
client_id: $id, client_secret: $secret, client_secret_basic: true, client_secret_post: false,
scope: "openid name email phoneNumber", use_pkce: true, danger_allow_insecure: false, root_pem: null,
admin_claim_path: null, admin_claim_value: null, mfa_claim_path: null, mfa_claim_value: null,
auto_onboarding: true, auto_link: true }')
# Listing is a POST in Rauthy's API.
existing=$(curl -sf -X POST -H "$auth" -H 'content-type: application/json' -d '{}' "$base/providers" | jq -r '.[] | select(.name == "Vipps") | .id' | head -n1)
if [ -n "$existing" ]; then
curl -sf -X PUT -H "$auth" -H 'content-type: application/json' -d "$vipps" "$base/providers/$existing" >/dev/null
echo "rauthy-providers: Vipps updated ($existing)"
else
id=$(curl -sf -X POST -H "$auth" -H 'content-type: application/json' -d "$vipps" "$base/providers/create" | jq -r .id)
echo "rauthy-providers: Vipps made ($id)"
fi
-34
View File
@@ -1,34 +0,0 @@
#!/usr/bin/env bash
# Tomter Vel's colours on Rauthy's pages (sign-in, account, the admin),
# as the deploy keeps them: Rauthy has no file for a theme, only its API,
# so this script is the file. The palette is the site's (custom.css in
# tomtervel/questions): accent #1785c2, paper #fffceb, ink #111111, line
# #e6dfbf, error #ff4136, as HSL. Rauthy themes per OIDC client; the
# sign-in page shows the client's theme and the account pages Rauthy's
# own (`rauthy`), so both get the same. Needs RAUTHY_HOST and
# RAUTHY_API_KEY with Clients read and update; without those rights it
# says so and changes nothing.
set -euo pipefail
for v in RAUTHY_HOST RAUTHY_API_KEY; do
[ -n "${!v:-}" ] || { echo "rauthy-theme: $v is not set; nothing changed"; exit 0; }
done
base="https://$RAUTHY_HOST/auth/v1"
auth="Authorization: API-Key $RAUTHY_API_KEY"
# Light: paper and ink. Dark: the same blue on a night sky.
theme=$(jq -n '{
light: { text: [46, 15, 27], text_high: [0, 0, 7], bg: [51, 100, 96], bg_high: [49, 44, 90],
action: [201, 79, 43], accent: [201, 79, 33], error: [3, 100, 61],
btn_text: "white", theme_sun: "hsla(var(--action) / .7)", theme_moon: "hsla(var(--accent) / .85)" },
dark: { text: [49, 30, 78], text_high: [51, 100, 96], bg: [201, 35, 9], bg_high: [201, 25, 16],
action: [201, 79, 52], accent: [201, 70, 70], error: [3, 100, 61],
btn_text: "hsl(var(--bg))", theme_sun: "hsla(var(--action) / .7)", theme_moon: "hsla(var(--accent) / .85)" },
border_radius: "6px" }')
for client in rauthy ${OAUTH2_CLIENT_ID:-portal} ${CHAT_OAUTH2_CLIENT_ID:-}; do
body=$(jq --arg c "$client" '. + {client_id: $c}' <<<"$theme")
code=$(curl -s -o /tmp/rauthy-theme.out -w '%{http_code}' -X PUT -H "$auth" -H 'Content-Type: application/json' -d "$body" "$base/theme/$client")
case "$code" in
200|201|204) echo "rauthy-theme: $client themed" ;;
403) echo "rauthy-theme: the API key may not update clients (403); give it Clients read+update, or set the theme in the admin. Nothing changed."; exit 0 ;;
*) echo "rauthy-theme: $client: http $code: $(head -c 300 /tmp/rauthy-theme.out)"; exit 1 ;;
esac
done
-37
View File
@@ -1,37 +0,0 @@
# Rauthy, the vel's sign-in in Norwegian: what is not secret. The
# secrets (the encryption key, the cluster secrets) and the names that
# differ per site come from rauthy.env, which the deploy workflow writes
# from the Actions secrets and variables (README.md). A profile: only
# with `rauthy` in COMPOSE_PROFILES does it run.
[bootstrap]
# The first admin's address, from BOOTSTRAP_ADMIN_EMAIL (rauthy.env).
# Its password is printed once in the log on the very first start:
# podman compose logs rauthy | grep -A2 -i password
[cluster]
# One node, on its own.
node_id = 1
nodes = ["1 localhost:8100 localhost:8200"]
[email]
# Through kasse's postfix, like gdo: the host signs the vel's mail
# (DKIM for tomtervel.no) on the way out.
smtp_url = "host.containers.internal"
smtp_port = 25
smtp_tls_mode = "danger-insecure"
smtp_from = "Tomter Vel <post@tomtervel.no>"
sub_prefix = "Tomter Vel"
[i18n]
# Norwegian first, and English for whoever's browser asks for it.
filter_lang_common = ["nb", "en"]
filter_lang_admin = ["nb", "en"]
[server]
# Behind kasse's host Caddy, which holds the certificate.
scheme = "http"
proxy_mode = true
# Caddy reaches the published port from the host, which the container
# sees as the project network's gateway (compose.yml pins 172.18/16).
trusted_proxies = ["172.16.0.0/12"]
+44
View File
@@ -0,0 +1,44 @@
#!/bin/sh
# Registers <PUBLIC_URL>/webhook with Vipps MobilePay's Webhooks API and
# puts the secret it answers with into kron.env as WEBHOOK_SECRET,
# without showing it. Run once per environment, as root, in this
# directory, after kron.env has the four keys and before kron starts.
#
# sh register-vipps-webhook.sh
#
# The events are the ones kron reads (src/provider/vipps.rs,
# seen_of_event): authorized, captured, expired, cancelled, aborted,
# terminated and refunded. kron does not register itself, by design:
# registering is a one-time act with a secret in the answer, and a
# service that could do it could also do it twice.
set -eu
[ -f kron.env ] || { echo "no kron.env here" >&2; exit 1; }
. ./kron.env
: "${VIPPS_CLIENT_ID:?}" "${VIPPS_CLIENT_SECRET:?}" "${VIPPS_SUBSCRIPTION_KEY:?}" "${VIPPS_MSN:?}"
public_url=$(grep -E '^PUBLIC_URL=' kron.env | cut -d= -f2- || true)
[ -n "$public_url" ] || public_url="https://kron.$(sed -n 's/^PORTAL_HOST=//p' .env)"
base=https://api.vipps.no
[ "${VIPPS_ENV:-test}" = test ] && base=https://apitest.vipps.no
token=$(curl -sf -X POST "$base/accesstoken/get" \
-H "client_id: $VIPPS_CLIENT_ID" -H "client_secret: $VIPPS_CLIENT_SECRET" \
-H "Ocp-Apim-Subscription-Key: $VIPPS_SUBSCRIPTION_KEY" -H "Merchant-Serial-Number: $VIPPS_MSN" \
| jq -r .access_token)
[ -n "$token" ] && [ "$token" != null ] || { echo "no access token: check the four keys" >&2; exit 1; }
answer=$(curl -sf -X POST "$base/webhooks/v1/webhooks" \
-H "Authorization: Bearer $token" \
-H "Ocp-Apim-Subscription-Key: $VIPPS_SUBSCRIPTION_KEY" -H "Merchant-Serial-Number: $VIPPS_MSN" \
-H 'Content-Type: application/json' \
-d "$(jq -n --arg url "$public_url/webhook" '{url: $url, events: [
"epayments.payment.authorized.v1", "epayments.payment.captured.v1",
"epayments.payment.expired.v1", "epayments.payment.cancelled.v1",
"epayments.payment.aborted.v1", "epayments.payment.terminated.v1",
"epayments.payment.refunded.v1"]}')")
id=$(printf '%s' "$answer" | jq -r .id)
secret=$(printf '%s' "$answer" | jq -r .secret)
[ -n "$secret" ] && [ "$secret" != null ] || { echo "registered nothing: $(printf '%s' "$answer" | jq -c 'del(.secret)')" >&2; exit 1; }
tmp=$(mktemp) && grep -v '^WEBHOOK_SECRET=' kron.env > "$tmp" && printf 'WEBHOOK_SECRET=%s\n' "$secret" >> "$tmp" \
&& cat "$tmp" > kron.env && rm -f "$tmp"
echo "webhook $id registered at $public_url/webhook; WEBHOOK_SECRET written to kron.env"
-53
View File
@@ -1,53 +0,0 @@
#!/usr/bin/env bash
# Vipps's webhooks for the money service (kron): registers kron's
# endpoint with the Webhooks API for the Medlemskap sales unit, or lists
# what is registered. Run by a person with the keys in `pass`, not by the
# deploy: the registration answers with the webhook's secret exactly once,
# and that secret has to become the repo secret VIPPS_WEBHOOK_SECRET (and
# kron's WEBHOOK_SECRET) without ever being printed in a public log.
#
# ./vipps-webhook.sh list # what Vipps has for the unit
# ./vipps-webhook.sh register # kron's /webhook, secret into pass
# ./vipps-webhook.sh delete <webhook id>
#
# VIPPS_ENV=test uses apitest.vipps.no and the test unit's keys
# (tomtervel/vipps/medlemskap-test in pass); the default is production
# (tomtervel/vipps/medlemskap). PAY_HOST is the host kron answers on
# (betaling.tomtervel.no).
set -euo pipefail
env=${VIPPS_ENV:-prod}
case "$env" in
test) api=https://apitest.vipps.no; entry=tomtervel/vipps/medlemskap-test ;;
prod) api=https://api.vipps.no; entry=tomtervel/vipps/medlemskap ;;
*) echo "VIPPS_ENV is $env; it is test or prod" >&2; exit 2 ;;
esac
host=${PAY_HOST:-betaling.tomtervel.no}
field() { pass show "$entry" | sed -n "s/^$1: //p" | head -n1; }
msn=$(field msn); cid=$(field client_id); csec=$(field client_secret); sub=$(field subscription_key_primary)
[ -n "$msn" ] && [ -n "$cid" ] && [ -n "$csec" ] && [ -n "$sub" ] || { echo "pass entry $entry lacks msn, client_id, client_secret or subscription_key_primary" >&2; exit 1; }
token=$(curl -sf -X POST "$api/accesstoken/get" -H "client_id: $cid" -H "client_secret: $csec" \
-H "Ocp-Apim-Subscription-Key: $sub" -H "Merchant-Serial-Number: $msn" -H 'Content-Length: 0' | jq -r .access_token)
[ -n "$token" ] && [ "$token" != null ] || { echo "no access token from $api" >&2; exit 1; }
auth=(-H "Authorization: Bearer $token" -H "Ocp-Apim-Subscription-Key: $sub" -H "Merchant-Serial-Number: $msn" -H 'Content-Type: application/json')
case "${1:-list}" in
list)
curl -sf "$api/webhooks/v1/webhooks" "${auth[@]}" | jq .
;;
register)
url="https://$host/webhook"
events='["epayments.payment.created.v1","epayments.payment.authorized.v1","epayments.payment.captured.v1","epayments.payment.aborted.v1","epayments.payment.expired.v1","epayments.payment.cancelled.v1","epayments.payment.terminated.v1","epayments.payment.refunded.v1"]'
answer=$(curl -sf -X POST "$api/webhooks/v1/webhooks" "${auth[@]}" -d "$(jq -n --arg url "$url" --argjson events "$events" '{url: $url, events: $events}')")
id=$(jq -r .id <<<"$answer"); secret=$(jq -r .secret <<<"$answer")
[ -n "$secret" ] && [ "$secret" != null ] || { echo "Vipps answered without a secret: $(jq -c 'del(.secret)' <<<"$answer")" >&2; exit 1; }
# The secret goes into pass and nowhere on screen.
printf 'id: %s\nurl: %s\nsecret: %s\n' "$id" "$url" "$secret" | pass insert -m -f "$entry-webhook" >/dev/null
echo "registered webhook $id for $url; its secret is in pass as $entry-webhook"
echo "now: pass show $entry-webhook | sed -n 's/^secret: //p' | gt secret set VIPPS_WEBHOOK_SECRET"
;;
delete)
[ -n "${2:-}" ] || { echo "which webhook? ./vipps-webhook.sh delete <id>" >&2; exit 2; }
curl -sf -X DELETE "$api/webhooks/v1/webhooks/$2" "${auth[@]}" && echo "deleted $2"
;;
*) echo "usage: $0 list | register | delete <id>" >&2; exit 2 ;;
esac