What the stack is, in git: .env committed, the secrets on the host

.env is what `podman compose` reads as is: the hosts, the versions and
where the content comes from, so moving to tomtervel.no or bumping portal
is a commit that the deploy workflow brings up. Nothing in it is secret.

The secrets stay on kasse in secrets.env (the old .env's NATS password,
OAuth2 secret and first person), and what the scripts render from it.
gdo and the chat get NATS_URL from nats.env instead of interpolating
the password, and portal takes its URLs and content settings from .env
over portal.env, so a new host name reaches it without re-running
bootstrap.sh. The deploy script on kasse is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L5fbDmSQSb6u27EiEuwzoM
This commit is contained in:
blandClaude Opus 5.5 committed 2026-11-07 16:29:55 +01:00
1 parent 213ef712c7
commit a76e6321ee
9 files changed
+125 -83

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
# The vel's stack as it is meant to run: hosts, versions, where the
# content comes from. Committed, and read by `podman compose` as is, so a
# change here is a reviewed commit and a push to main deploys it.
#
# Nothing secret goes here: the repo is public. The secrets are in
# secrets.env, portal.env, nats.env and chat.env on the host, made there
# by bootstrap.sh and kanidm-setup.sh (see secrets.env.example).
# Where the site, the login and the chat are served. Each needs an A
# record pointing here (dns/dnsconfig.js) and a block in kasse's Caddy.
PORTAL_HOST=vel.klingenbergbygg.no
ID_HOST=id.vel.klingenbergbygg.no
CHAT_HOST=chat.vel.klingenbergbygg.no
# Versions. A bump is the upgrade.
# portal: a tag of https://project.uhhm.no/uhhm/portal; keep the content
# repo's lint (PORTAL_RELEASE in its lint-and-reload.yml) on the same one.
PORTAL_RELEASE=v0.13.0
# gdo: a tag of https://project.uhhm.no/uhhm/gdo. It hands the vel's mail
# to kasse's postfix.
GDO_RELEASE=v0.2.0
# cnats, the chat: a bendik/cnats tag on Docker Hub, above 0.4.0.
CNATS_TAG=0.4.2
# kron, the money service: a bendik/kron tag on Docker Hub.
KRON_RELEASE=0.1.0
COMPOSE_PROFILES=chat
# The content this instance serves, and reloads live on every push.
CONTENT_REPO=https://prosjekt.klingenbergbygg.no/tomtervel/questions
CONTENT_BRANCH=main
# The namespace of everything the site keeps on NATS. Must not change: a
# new name is a new, empty site.
SITE_NAME=tomtervel
# Who is who. `memberships`: portal keeps the groups itself, and Kanidm
# only makes the accounts. Everyone a page names as responsible joins
# RESPONSIBLE_GROUP.
PEOPLE_BACKEND=memberships
RESPONSIBLE_GROUP=redaktor
OAUTH2_CLIENT_ID=tomtervel-portal
# A project Gitea that RESPONSIBLE_GROUP may sign in to with the same
# account (kanidm-setup.sh makes its client). Empty: no Gitea.
GITEA_URL=https://prosjekt.klingenbergbygg.no
GITEA_AUTH_NAME=tomtervel
-65
View File
@@ -1,65 +0,0 @@
# 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
+6 -4
View File
@@ -1,18 +1,20 @@
# Deploy this stack onto the host it runs on. A push that changes the
# compose file, a Dockerfile or a rendered config pulls and brings the
# stack up; a portal or gdo upgrade is a commit that bumps the version in
# .env.example and, on the host, in .env.
# stack up; a portal or gdo upgrade, or a new host name, is a commit that
# changes .env.
#
# Runs on kasse's host runner. It is not root: it may run one script,
# /usr/local/bin/deploy-tomtervel, which pulls this repo under
# /srv/tomtervel and runs `podman compose up -d --build` and nothing
# 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.
# else. The secrets on the host - secrets.env, portal.env, nats.env,
# chat.env: the NATS password, the OAuth2 secret, the Kanidm token - are
# never in this repo and are not touched by a deploy.
name: deploy
on:
push:
branches: [main]
paths:
- .env
- compose.yml
- Caddyfile
- portal/**
+2 -1
View File
@@ -1,4 +1,3 @@
.env
portal.env
chat.env
kanidm/server.toml
@@ -7,3 +6,5 @@ certs/
.kanidm-recovered
gitea-oauth.secret
dns/cloudflare.env
secrets.env
nats.env
+24 -5
View File
@@ -25,7 +25,7 @@ i.e. as root, so Caddy can bind 80/443 and Kanidm sees a stable source IP):
```sh
git clone https://prosjekt.klingenbergbygg.no/tomtervel/infrastructure /srv/tomtervel/infrastructure
cd /srv/tomtervel/infrastructure
cp .env.example .env # set PORTAL_HOST and ID_HOST; DNS must point here
cp secrets.env.example secrets.env # the hosts are in .env, committed; 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
```
@@ -80,7 +80,7 @@ and is safe to rerun:
- **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,
- **The first person in.** `SEED_ADMIN_EMAIL` in `secrets.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
@@ -124,9 +124,28 @@ Until then, `podman compose restart portal` picks up new content.
## Upgrading portal
Bump `PORTAL_RELEASE` in `.env` (a tag of uhhm/portal) and
`podman compose up -d --build portal`. Keep `IRIS_RELEASE` in the
content repo's workflow matched to it.
Bump `PORTAL_RELEASE` in `.env` (a tag of uhhm/portal), commit and push
to main: the deploy workflow brings it up. Keep `PORTAL_RELEASE` in the
content repo's `lint-and-reload.yml` matched to it.
## What is in git, and what is on the host
`.env` is committed: the hosts, the versions, where the content comes
from - everything the stack *is*. `podman compose` reads it as it is,
so a change to it is a commit, and a push to main deploys it. The repo is
public, so nothing secret goes there.
The secrets stay on the host, made there and never in CI: `secrets.env`
(the NATS password, the OAuth2 secret, the first person's address; see
`secrets.env.example`), and what the scripts render from it - `portal.env`,
`nats.env`, `chat.env`, `nats/nats.conf`, `kanidm/server.toml`.
`bootstrap.sh` and `kanidm-setup.sh` read `.env` and then `secrets.env`.
`kanidm/server.toml` takes `ID_HOST` when `bootstrap.sh` renders it, not on
a deploy: Kanidm's domain is renamed on purpose, once (see dns/README.md).
The one secret in Gitea is the repo secret `CLOUDFLARE_API_TOKEN`, for
the DNS workflow.
## Backups
+9 -4
View File
@@ -4,23 +4,28 @@
# 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
# cp secrets.env.example secrets.env # the hosts are in .env, committed
# sudo sh bootstrap.sh
set -eu
cd "$(dirname "$0")"
[ -f .env ] || { echo "copy .env.example to .env and fill it in first"; exit 1; }
[ -f secrets.env ] || { echo "copy secrets.env.example to secrets.env first"; exit 1; }
chmod 600 secrets.env
. ./.env
. ./secrets.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"
sed -i "s|^NATS_PASSWORD=.*|NATS_PASSWORD=$NATS_PASSWORD|" secrets.env
echo "NATS_PASSWORD generated into secrets.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
# gdo and the chat reach NATS with the same password.
printf 'NATS_URL=nats://portal:%s@nats:4222\n' "$NATS_PASSWORD" > nats.env
chmod 600 nats.env
# 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)
+16 -3
View File
@@ -85,8 +85,20 @@ services:
args:
PORTAL_RELEASE: ${PORTAL_RELEASE}
restart: unless-stopped
# portal.env holds the secrets (NATS, the OAuth2 secret, the
# onboarding token, Garage's keys); what the site is comes from .env
# here, and wins over the same name in portal.env.
env_file: portal.env
environment:
PUBLIC_URL: https://${PORTAL_HOST}
KANIDM_URL: https://${ID_HOST}
CHAT_URL: https://${CHAT_HOST}
OAUTH2_CLIENT_ID: ${OAUTH2_CLIENT_ID}
COOKIE_SECURE: "true"
CONTENT_REPO: ${CONTENT_REPO}
CONTENT_BRANCH: ${CONTENT_BRANCH}
PEOPLE_BACKEND: ${PEOPLE_BACKEND}
RESPONSIBLE_GROUP: ${RESPONSIBLE_GROUP}
LEPTOS_SITE_ADDR: 0.0.0.0:3000
LEPTOS_SITE_ROOT: site
LEPTOS_HASH_FILES: "true"
@@ -121,8 +133,9 @@ services:
args:
GDO_RELEASE: ${GDO_RELEASE}
restart: unless-stopped
# NATS_URL, with the password: made by bootstrap.sh, never committed.
env_file: nats.env
environment:
NATS_URL: nats://portal:${NATS_PASSWORD}@nats:4222
# The host, from inside the container. Podman resolves this to the
# gateway; the host's postfix listens on 0.0.0.0:25.
SMTP_HOST: host.containers.internal
@@ -151,14 +164,14 @@ services:
image: docker.io/bendik/cnats:${CNATS_TAG:-no-tag-set}
restart: unless-stopped
env_file:
- nats.env
- path: chat.env
required: false
environment:
# Must be the portal's own: a new name is a new, empty chat.
SITE_NAME: tomtervel
NATS_URL: nats://portal:${NATS_PASSWORD}@nats:4222
KANIDM_URL: https://${ID_HOST}
PUBLIC_URL: https://${CHAT_HOST:-chat.vel.klingenbergbygg.no}
PUBLIC_URL: https://${CHAT_HOST}
COOKIE_SECURE: "true"
ports:
- "127.0.0.1:3070:3000"
+2 -1
View File
@@ -12,6 +12,7 @@
set -eu
cd "$(dirname "$0")"
. ./.env
[ -f secrets.env ] && . ./secrets.env
K="kanidm -D idm_admin -H https://$ID_HOST"
C=$OAUTH2_CLIENT_ID
SA=portal-onboarding
@@ -167,7 +168,7 @@ fi
# 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
sed -i "s|^OAUTH2_CLIENT_SECRET=.*|OAUTH2_CLIENT_SECRET=$secret|" secrets.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)
+21
View File
@@ -0,0 +1,21 @@
# Copy to secrets.env on the host (chmod 600). Never committed: what the
# stack runs as is in .env, which is. bootstrap.sh and kanidm-setup.sh
# read both, .env first.
# Generated once by bootstrap.sh if left empty. bootstrap.sh also writes
# it into nats/nats.conf and nats.env (NATS_URL for gdo and the chat).
NATS_PASSWORD=
# Filled in by kanidm-setup.sh after it creates the Kanidm client.
OAUTH2_CLIENT_SECRET=
# The first person in: portal invites this address into the site's most
# privileged group (the board) and mails them the one-time link, once.
# Everyone else they invite themselves, from their desk. An address, so
# not in the public repo.
SEED_ADMIN_EMAIL=
SEED_ADMIN_NAME=
# Only for the optional runner profile: a registration token from
# prosjekt.klingenbergbygg.no -> tomtervel org -> Settings -> Actions -> Runners.
RUNNER_REGISTRATION_TOKEN=