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
11 changed files with 128 additions and 177 deletions

No files matched your search

+2
View File
@@ -63,3 +63,5 @@ RUNNER_REGISTRATION_TOKEN=
# 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
+1 -1
View File
@@ -6,4 +6,4 @@ nats/nats.conf
certs/
.kanidm-recovered
gitea-oauth.secret
dns/cloudflare.env
kron.env
+29 -8
View File
@@ -122,6 +122,35 @@ whose `runs-on` matches that runner's host label, running
`nats --server nats://portal:$NATS_PASSWORD@127.0.0.1:4222 pub portal.content.reload ""`.
Until then, `podman compose restart portal` picks up new content.
## 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
Bump `PORTAL_RELEASE` in `.env` (a tag of uhhm/portal) and
@@ -142,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
until the vel points the apex at PORTAL_HOST.
## DNS
tomtervel.no's records are `dns/dnsconfig.js`, applied to Cloudflare
with DNSControl: the site, the login and the chat pointing here, Zoho's
mail, and SPF, DKIM and DMARC for the mail the site sends. How to run
it, the token it needs, and the order of a move are in
[dns/README.md](dns/README.md).
## Mail
Portal decides what to send - a `mail:` on a state in the content, or an
+27
View File
@@ -95,6 +95,11 @@ services:
# The namespace of everything this site keeps on NATS from portal 0.9.
# Must not change: a new name is a new, empty site.
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:
- learn_cache:/app/learn-cache
ports:
@@ -135,6 +140,28 @@ services:
nats:
condition: service_healthy
# The money service. Portal decides what is owed - a `payment:` on a
# state in the content - and publishes the request on this NATS; kron
# is what asks Vipps MobilePay for it, pushes it to the person's app,
# and says on the same NATS what became of it. One kron per site, its
# keys in kron.env and nowhere else. Host-published for kasse's host
# Caddy (kron.vel.klingenbergbygg.no -> here): Vipps has to reach
# /webhook over public HTTPS, and a person who paid by link lands on
# /returned/<id>.
kron:
image: docker.io/bendik/kron:${KRON_RELEASE}
restart: unless-stopped
env_file: kron.env
environment:
NATS_URL: nats://portal:${NATS_PASSWORD}@nats:4222
SITE_NAME: tomtervel
PUBLIC_URL: https://kron.${PORTAL_HOST}
ports:
- "127.0.0.1:3080:3000"
depends_on:
nats:
condition: service_healthy
# The Gitea Actions runner is a host service on kasse (pacman gitea-runner),
# registered against prosjekt.klingenbergbygg.no. It reaches this NATS via the
# published 127.0.0.1:4222 port above, so no in-compose runner — and no
-60
View File
@@ -1,60 +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.
```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. `dnscontrol push`. The apex leaves the old website at this moment.
3. `.env` here: `PORTAL_HOST=tomtervel.no`, `ID_HOST=id.tomtervel.no`,
`CHAT_HOST=chat.tomtervel.no`, and the Caddy blocks in
`host-caddy/` on kasse; Kanidm's domain is renamed before anyone
but the first person has a passkey.
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 in `.env` are the same names and have to
stay so; DNSControl does not read `.env`.
-7
View File
@@ -1,7 +0,0 @@
{
"none": { "TYPE": "NONE" },
"cloudflare": {
"TYPE": "CLOUDFLAREAPI",
"apitoken": "$CLOUDFLARE_API_TOKEN"
}
}
-60
View File
@@ -1,60 +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,
// Kanidm, 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 = "";
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("id", KASSE, CF_PROXY_OFF),
A("chat", KASSE, CF_PROXY_OFF),
// 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) : []
);
+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
}
-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=
+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"