2026-09-22 19:06:31 +02:00
|
|
|
#!/bin/sh
|
2026-11-07 16:44:51 +01:00
|
|
|
# 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.
|
2026-09-22 19:06:31 +02:00
|
|
|
#
|
2026-11-07 16:44:51 +01:00
|
|
|
# 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.
|
2026-09-22 19:06:31 +02:00
|
|
|
set -eu
|
|
|
|
|
cd "$(dirname "$0")"
|
2026-11-07 16:44:51 +01:00
|
|
|
[ -f .env ] && . ./.env
|
|
|
|
|
: "${ID_HOST:?ID_HOST=id.<the vel's domain> sh bootstrap.sh, or run the deploy workflow first}"
|
2026-09-22 19:06:31 +02:00
|
|
|
|
2026-11-07 16:44:51 +01:00
|
|
|
# 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"
|
|
|
|
|
}
|
2026-09-22 19:06:31 +02:00
|
|
|
|
|
|
|
|
# Kanidm's internal certificate: Caddy holds the public one.
|
|
|
|
|
mkdir -p certs
|
|
|
|
|
if [ ! -f certs/kanidm-key.pem ]; then
|
|
|
|
|
openssl req -x509 -newkey rsa:2048 -nodes -days 3650 \
|
|
|
|
|
-subj "/CN=kanidm" -addext "subjectAltName=DNS:kanidm,DNS:$ID_HOST" \
|
|
|
|
|
-keyout certs/kanidm-key.pem -out certs/kanidm-chain.pem >/dev/null 2>&1
|
|
|
|
|
chmod 600 certs/kanidm-key.pem
|
|
|
|
|
echo "internal Kanidm certificate made"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# The Kanidm admin accounts exist only after the first start; their
|
2026-11-07 16:44:51 +01:00
|
|
|
# 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
|
2026-09-22 19:06:31 +02:00
|
|
|
if [ ! -f .kanidm-recovered ]; then
|
|
|
|
|
echo
|
|
|
|
|
echo "=== Kanidm admin recovery (write these passwords down) ==="
|
2026-09-28 11:15:29 +02:00
|
|
|
podman compose exec kanidm kanidmd recover-account admin
|
|
|
|
|
podman compose exec kanidm kanidmd recover-account idm_admin
|
2026-09-22 19:06:31 +02:00
|
|
|
touch .kanidm-recovered
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo
|
|
|
|
|
echo "Next: sh kanidm-setup.sh (log in as idm_admin, create the portal client and desk groups)"
|