The stack's settings are repo variables, its secrets repo secrets, and NATS_PASSWORD an org secret the content repo can share. The deploy workflow checks they are all set, writes .env, portal.env, nats.env and chat.env into the runner's own directory, and the root script (now in the repo as deploy-tomtervel) pulls main, puts them in place as root's and brings the stack up. So nothing is edited on the host or committed: a host name or a version is a variable changed and a Run workflow. nats.conf reads NATS_PASSWORD from its environment, so it is committed rather than rendered. bootstrap.sh only makes Kanidm's config and certificate and recovers its admins; kanidm-setup.sh reads portal.env, and leaves the two secrets it makes in kanidm-setup.secrets for gt. The DNS workflow uses actions/checkout and actions/cache (the runner's cache server) for dnscontrol, at the DNSCONTROL_VERSION variable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L5fbDmSQSb6u27EiEuwzoM
This commit is contained in:
12 files changed
+282
-207
No files matched your search
+24
-47
@@ -1,50 +1,26 @@
|
||||
#!/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.
|
||||
# What a fresh host needs before the first deploy, and what only exists
|
||||
# after it. Everything the stack runs with is an Actions variable or
|
||||
# secret (README.md), written onto the host by the deploy workflow; this
|
||||
# makes the two things that are not values: Kanidm's config and its
|
||||
# internal certificate. Idempotent: rerunning skips what exists.
|
||||
#
|
||||
# cp secrets.env.example secrets.env # the hosts are in .env, committed
|
||||
# sudo sh bootstrap.sh
|
||||
# sudo ID_HOST=id.tomtervel.no sh bootstrap.sh # before the first deploy
|
||||
# (Actions -> deploy -> Run workflow)
|
||||
# sudo sh bootstrap.sh # after: Kanidm admin recovery
|
||||
#
|
||||
# Run rootful (as root) so Kanidm sees a stable source IP.
|
||||
set -eu
|
||||
cd "$(dirname "$0")"
|
||||
[ -f secrets.env ] || { echo "copy secrets.env.example to secrets.env first"; exit 1; }
|
||||
chmod 600 secrets.env
|
||||
. ./.env
|
||||
. ./secrets.env
|
||||
[ -f .env ] && . ./.env
|
||||
: "${ID_HOST:?ID_HOST=id.<the vel's domain> sh bootstrap.sh, or run the deploy workflow first}"
|
||||
|
||||
# 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|" 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)
|
||||
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 domain is fixed here, once: renaming it later is Kanidm's own
|
||||
# `domain rename`, not a variable changed.
|
||||
[ -f kanidm/server.toml ] || {
|
||||
sed "s|\${ID_HOST}|$ID_HOST|g" kanidm/server.toml.tpl > kanidm/server.toml
|
||||
echo "kanidm/server.toml made for $ID_HOST"
|
||||
}
|
||||
|
||||
# Kanidm's internal certificate: Caddy holds the public one.
|
||||
mkdir -p certs
|
||||
@@ -56,12 +32,13 @@ if [ ! -f certs/kanidm-key.pem ]; then
|
||||
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.
|
||||
# passwords are set by recovery. Once; the output is the password, shown
|
||||
# once.
|
||||
if ! podman compose ps --format '{{.Names}}' 2>/dev/null | grep -q kanidm; then
|
||||
echo "Kanidm is not running yet: run the deploy workflow, then this again."
|
||||
exit 0
|
||||
fi
|
||||
if [ ! -f .kanidm-recovered ]; then
|
||||
echo
|
||||
echo "=== Kanidm admin recovery (write these passwords down) ==="
|
||||
|
||||
Reference in new issue
Block a user