Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99852cdce6 | ||
|
|
3d7da36401 | ||
|
|
bd37ae5786 | ||
|
|
6cbd6ada9b | ||
|
|
459f780049 | ||
|
|
0c60e8f181 | ||
|
|
7e241a90d0 | ||
|
|
a0af480890 | ||
|
|
47342b0867 | ||
|
|
97083982ba | ||
|
|
c88d396ad7 | ||
|
|
33e102dc25 | ||
|
|
64fc9a1911 | ||
|
|
b2ee900602 | ||
|
|
b128801ee2 | ||
|
|
fdac5084d1 | ||
|
|
4cf56ac588 |
No files matched your search
@@ -19,6 +19,8 @@ on:
|
||||
- Caddyfile
|
||||
- portal/**
|
||||
- gdo/**
|
||||
- rauthy-providers.sh
|
||||
- rauthy-theme.sh
|
||||
- nats/nats.conf
|
||||
- rauthy/config.toml
|
||||
- deploy-tomtervel
|
||||
@@ -34,6 +36,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,7 +79,21 @@ 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:
|
||||
# The repo's own scripts (rauthy-providers.sh) run from the
|
||||
# checkout; the stack itself is pulled on the host by
|
||||
# deploy-tomtervel, not from here.
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# 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
|
||||
@@ -92,6 +109,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 +129,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 +159,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" <<EOF
|
||||
NATS_PASSWORD=$NATS_PASSWORD
|
||||
@@ -142,6 +175,15 @@ jobs:
|
||||
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
|
||||
@@ -156,6 +198,28 @@ jobs:
|
||||
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
|
||||
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
|
||||
@@ -5,3 +5,4 @@ gitea-oauth.secret
|
||||
dns/cloudflare.env
|
||||
nats.env
|
||||
rauthy.env
|
||||
kron.env
|
||||
@@ -62,10 +62,13 @@ account mail, in Norwegian. Portal and the chat sign in there
|
||||
`responsible` gets an account at start and a place in
|
||||
`RESPONSIBLE_GROUP` (`redaktor`).
|
||||
|
||||
The groups are portal's (`PEOPLE_BACKEND=memberships`): who is in
|
||||
`styret` is on the board's desk, "Medlemmer og invitasjoner", where a
|
||||
person is taken out or invited again. Portal decides what a group may
|
||||
do, on the site and in the chat's rooms alike.
|
||||
The groups are kept in Rauthy (`PEOPLE_BACKEND=rauthy`): an invite
|
||||
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
|
||||
desk, "Medlemmer og invitasjoner", where a person is taken out or invited
|
||||
again. Portal decides what a group may do, on the site and in the chat's
|
||||
rooms alike. Records in `portal_memberships` are left from before
|
||||
(Kanidm); nothing new is written there.
|
||||
|
||||
## Content changes
|
||||
|
||||
@@ -103,7 +106,7 @@ Run workflow**. Set them with `gt` (`gt variable set NAME --body ...`,
|
||||
| `COMPOSE_PROFILES` | variable | repo | `chat` |
|
||||
| `CONTENT_REPO`, `CONTENT_BRANCH` | variable | repo | the content this site serves |
|
||||
| `SITE_NAME` | variable | repo | `tomtervel`; never changed (a new name is a new, empty site) |
|
||||
| `PEOPLE_BACKEND`, `RESPONSIBLE_GROUP` | variable | repo | `memberships`, `redaktor` |
|
||||
| `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 |
|
||||
@@ -120,6 +123,11 @@ Run workflow**. Set them with `gt` (`gt variable set NAME --body ...`,
|
||||
| `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.
|
||||
@@ -127,6 +135,58 @@ 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`. The host
|
||||
script must know `kron.env` (this repo's `deploy-tomtervel`, optional
|
||||
files): on kasse, `sudo install -m 0755 -o root -g root
|
||||
/srv/tomtervel/infrastructure/deploy-tomtervel /usr/local/bin/deploy-tomtervel`
|
||||
after the pull, since the installed copy does not update itself.
|
||||
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`
|
||||
@@ -152,12 +212,18 @@ On a new host:
|
||||
Signed in, it sets up a passkey.
|
||||
3. In Rauthy's admin (`https://konto.tomtervel.no/auth/v1/admin`), or
|
||||
with the bootstrap key: the client `portal` (`authorization_code`,
|
||||
`S256`, scopes `openid profile email`, redirect
|
||||
`https://tomtervel.no/auth/callback`) and `chat` (also
|
||||
`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 and groups into `RAUTHY_API_KEY`.
|
||||
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.
|
||||
|
||||
+28
@@ -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: project.uhhm.no/uhhm/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
|
||||
|
||||
+3
-2
@@ -18,8 +18,9 @@ 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)
|
||||
# Written only when the site runs what needs it (Rauthy, the money
|
||||
# service under the pay profile).
|
||||
optional=(rauthy.env kron.env)
|
||||
|
||||
[ -d "$root/.git" ] || { echo "no checkout at $root - bootstrap it first" >&2; exit 1; }
|
||||
for f in "${files[@]}"; do
|
||||
|
||||
@@ -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.
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ RUN pacman-key --init \
|
||||
'SigLevel = Required DatabaseOptional' \
|
||||
'Server = https://project.uhhm.no/api/packages/bl/arch/$repo/$arch' \
|
||||
>> /etc/pacman.conf \
|
||||
&& pacman -Sy --noconfirm --needed ca-certificates gdo \
|
||||
&& pacman -Syu --noconfirm --needed ca-certificates gdo \
|
||||
&& pacman -Scc --noconfirm \
|
||||
&& rm -rf /var/cache/pacman/pkg/* /var/lib/pacman/sync/*
|
||||
|
||||
|
||||
@@ -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 <branch>.forhandsvisning.tomtervel.no, for five days
|
||||
# after its last push, and the list of them on the bare name. Every name
|
||||
|
||||
+4
-1
@@ -12,7 +12,10 @@
|
||||
# reason.
|
||||
FROM archlinux:base
|
||||
ARG PORTAL_RELEASE
|
||||
RUN pacman -Sy --noconfirm --needed ca-certificates curl \
|
||||
# -Syu, never -Sy: a partial upgrade pulls a library newer than what the
|
||||
# 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 \
|
||||
&& rm -rf /var/cache/pacman/pkg/* /var/lib/pacman/sync/*
|
||||
WORKDIR /app
|
||||
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/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
|
||||
Executable
+34
@@ -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
|
||||
Executable
+53
@@ -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 <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
|
||||
Reference in new issue
Block a user