From a0af4808900083fc6c6880c08b0459c8d6da4d5b Mon Sep 17 00:00:00 2001 From: Bendik Aagaard Lynghaug Date: Tue, 10 Nov 2026 20:25:46 +0100 Subject: [PATCH 1/3] kron in the stack: the money service, Vipps ePayment for Medlemskap Under the pay profile: kron.env from the Medlemskap sales unit's keys, PAY_URL for portal once the profile is on, betaling.tomtervel.no in DNS and kasse's Caddy, and vipps-webhook.sh for the one-time webhook registration whose secret must never reach a public log. Co-Authored-By: Claude Fable 5.1 --- .gitea/workflows/deploy.yml | 38 +++++++++++++++++++++++++- .gitignore | 1 + README.md | 42 +++++++++++++++++++++++++++++ compose.yml | 28 ++++++++++++++++++++ dns/dnsconfig.js | 2 ++ host-caddy/tomtervel.no | 8 ++++++ vipps-webhook.sh | 53 +++++++++++++++++++++++++++++++++++++ 7 files changed, 171 insertions(+), 1 deletion(-) create mode 100755 vipps-webhook.sh diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 353df4d..204d0ae 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -19,6 +19,7 @@ on: - Caddyfile - portal/** - gdo/** + - rauthy-providers.sh - nats/nats.conf - rauthy/config.toml - deploy-tomtervel @@ -34,6 +35,7 @@ jobs: # 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 }} @@ -76,6 +78,15 @@ jobs: 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: # A missing value stops here, by name, before anything on the host # is touched. Only names are printed: the log is public. @@ -92,6 +103,14 @@ jobs: [ -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" @@ -104,6 +123,7 @@ jobs: 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 @@ -133,6 +153,13 @@ jobs: 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" < "$STAGE/kron.env" < "$STAGE/rauthy.env" <$`, 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. @@ -131,6 +135,44 @@ 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. +## 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/`, 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 bendik/kron + tag), 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` diff --git a/compose.yml b/compose.yml index fe7fce9..68e12da 100644 --- a/compose.yml +++ b/compose.yml @@ -144,6 +144,34 @@ services: nats: condition: service_healthy + # The money service (uhhm/kron): portal asks for a payment on this + # NATS as a household owes its fee, kron gives it a link to pay by, + # talks to Vipps's ePayment API for the Medlemskap sales unit, and + # says `paid` back on the same bus. Vipps's keys are in kron.env and + # nowhere else; portal never calls Vipps. Host-published for kasse's + # host Caddy (betaling.tomtervel.no -> here): the pay links, the page + # people come back to from Vipps, and Vipps's webhooks. A profile, since + # it needs kron.env: COMPOSE_PROFILES gains `pay` once the keys are set. + kron: + profiles: ["pay"] + image: docker.io/bendik/kron:${KRON_RELEASE:-no-tag-set} + restart: unless-stopped + env_file: + - nats.env + - kron.env + environment: + # Must be the portal's own: a request names its site. + SITE_NAME: tomtervel + PROVIDER: vipps + VIPPS_ENV: prod + PUBLIC_URL: https://${PAY_HOST:-no-host-set} + LISTEN_ADDR: 0.0.0.0:3000 + 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 diff --git a/dns/dnsconfig.js b/dns/dnsconfig.js index c0494f4..1f177e3 100644 --- a/dns/dnsconfig.js +++ b/dns/dnsconfig.js @@ -31,6 +31,8 @@ D("tomtervel.no", REG_NONE, DnsProvider(DSP_CLOUDFLARE), 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. diff --git a/host-caddy/tomtervel.no b/host-caddy/tomtervel.no index 1095eb6..f75b680 100644 --- a/host-caddy/tomtervel.no +++ b/host-caddy/tomtervel.no @@ -33,6 +33,14 @@ 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 .forhandsvisning.tomtervel.no, for five days # after its last push, and the list of them on the bare name. Every name diff --git a/vipps-webhook.sh b/vipps-webhook.sh new file mode 100755 index 0000000..8469f72 --- /dev/null +++ b/vipps-webhook.sh @@ -0,0 +1,53 @@ +#!/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 +# +# 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 " >&2; exit 2; } + curl -sf -X DELETE "$api/webhooks/v1/webhooks/$2" "${auth[@]}" && echo "deleted $2" + ;; + *) echo "usage: $0 list | register | delete " >&2; exit 2 ;; +esac -- 2.56.1 From 7e241a90d02fb2ad5a858cee30de225997571efa Mon Sep 17 00:00:00 2001 From: Bendik Aagaard Lynghaug Date: Tue, 10 Nov 2026 20:27:49 +0100 Subject: [PATCH 2/3] Tomter Vel's colours on Rauthy's pages, kept by the deploy Co-Authored-By: Claude Fable 5.1 --- .gitea/workflows/deploy.yml | 6 ++++++ README.md | 9 +++++++++ rauthy-theme.sh | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100755 rauthy-theme.sh diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 204d0ae..f86f5cc 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -20,6 +20,7 @@ on: - portal/** - gdo/** - rauthy-providers.sh + - rauthy-theme.sh - nats/nats.conf - rauthy/config.toml - deploy-tomtervel @@ -212,3 +213,8 @@ jobs: 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 diff --git a/README.md b/README.md index 0034bea..a5d342a 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,15 @@ 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 diff --git a/rauthy-theme.sh b/rauthy-theme.sh new file mode 100755 index 0000000..fe5829c --- /dev/null +++ b/rauthy-theme.sh @@ -0,0 +1,34 @@ +#!/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 -- 2.56.1 From 0c60e8f1811be150e84401cd48643dafef3fb60f Mon Sep 17 00:00:00 2001 From: Bendik Aagaard Lynghaug Date: Tue, 10 Nov 2026 20:37:32 +0100 Subject: [PATCH 3/3] kron's image from project.uhhm.no, where its release publishes it Co-Authored-By: Claude Fable 5.1 --- README.md | 5 +++-- compose.yml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a5d342a..28771b3 100644 --- a/README.md +++ b/README.md @@ -169,8 +169,9 @@ Going live, in order: 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 bendik/kron - tag), then Run workflow. `https://betaling.tomtervel.no/healthz` +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 diff --git a/compose.yml b/compose.yml index 68e12da..5fd1343 100644 --- a/compose.yml +++ b/compose.yml @@ -154,7 +154,7 @@ services: # it needs kron.env: COMPOSE_PROFILES gains `pay` once the keys are set. kron: profiles: ["pay"] - image: docker.io/bendik/kron:${KRON_RELEASE:-no-tag-set} + image: project.uhhm.no/uhhm/kron:${KRON_RELEASE:-no-tag-set} restart: unless-stopped env_file: - nats.env -- 2.56.1