coreapp new --sso: sign-in through the Core's Authelia

A template overlay (templates/sso) registers the app as an OpenID Connect
client in Authelia's idproviders.yml (between markers, secret hashed by
the running Authelia), checks the configuration before restarting
Authelia and restores it if the check fails; uninstall removes the client.
The app reaches Authelia's https address through traefik (@TRAEFIK_IP@,
provided by the template's install and by redeploys). The example is a
standard-library Python OIDC client (code flow with PKCE). Tested by
install, redeploy, remove and reinstall, and a real sign-in in a browser.

Also: the postgres overlay appends to the base install, uninstall and
env.in; database names get a coreapp_ prefix (PostgreSQL reserves pg_*);
deploy waits until the app answers on its own address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:34:27 -07:00
co-authored by Claude Opus 5.5
parent 74bdc13f0f
commit 284f52fc29
19 changed files with 419 additions and 37 deletions
+37 -9
View File
@@ -3,8 +3,9 @@
# Purpose : Make, deploy and test apps for Federated Core, against the Core
# in coreapp-dev's VM (coreapp-vm).
#
# coreapp new [--postgres] <name>
# make a new app in ./<name> (with its own database)
# coreapp new [--postgres|--sso] <name>
# make a new app in ./<name> (with its own database,
# or with sign-in through the Core's Authelia)
# coreapp deploy build, copy to the Core, install or update
# coreapp check the app answers at https://<name>.<domain>/
# coreapp status its container, address and URL
@@ -77,7 +78,7 @@ core_domain() {
# --- The app in the current folder ---------------------------------------
# NAME is the app's id (its folder on the Core); TITLE is NAME in service
NAME="" TITLE="" CONTAINER="" VERSION="" INTERNAL_IP="" MONITOR="" HIDDEN=""
NAME="" TITLE="" CONTAINER="" VERSION="" INTERNAL_IP="" MONITOR="" HIDDEN="" PORTS=""
load_app() {
[[ -f service && -f install ]] \
|| die "No app here: run this in an app's folder (one with service and install), or make one with coreapp new <name>."
@@ -113,14 +114,18 @@ cmd_new() {
local name="" overlay="" title ip dbname f
while [[ $# -gt 0 ]]; do
case "$1" in
--postgres) overlay="$TEMPLATES/postgres" ;;
-*) die "Unknown option $1. Usage: coreapp new [--postgres] <name>" ;;
--postgres | --sso)
# Each brings its own example app, so one at a time for now
[[ -z "$overlay" ]] || die "Use --postgres or --sso, not both (yet)."
overlay="$TEMPLATES/${1#--}"
;;
-*) die "Unknown option $1. Usage: coreapp new [--postgres|--sso] <name>" ;;
*) name="$1" ;;
esac
shift
done
[[ -d "$TEMPLATE" ]] || die "The app template is missing: $TEMPLATE"
[[ -n "$name" ]] || die "Usage: coreapp new [--postgres] <name> (lowercase letters, digits and -)"
[[ -n "$name" ]] || die "Usage: coreapp new [--postgres|--sso] <name> (lowercase letters, digits and -)"
[[ "$name" =~ ^[a-z][a-z0-9-]{1,30}$ ]] \
|| die "'$name': use 2-31 lowercase letters, digits and -, starting with a letter. It becomes https://$name.<domain>."
[[ ! -e "$name" ]] || die "./$name already exists."
@@ -131,9 +136,11 @@ cmd_new() {
mkdir -p "$DATA"
echo "$name $ip" >> "$ADDRESSES"
fi
# "my-app" -> "My App"; database names can't have "-"
# "my-app" -> "My App". Database names: no "-", and a prefix, because
# PostgreSQL reserves names starting with pg_ and Federated's apps have
# their own databases (nextcloud, superpanel, ...)
title="$(echo "$name" | sed -E 's/-/ /g; s/(^| )([a-z])/\1\u\2/g')"
dbname="${name//-/_}"
dbname="coreapp_${name//-/_}"
mkdir "$name"
tar -C "$TEMPLATE" --exclude=.claude -cf - . | tar -C "$name" -xf -
@@ -154,7 +161,12 @@ cmd_new() {
-e "s/{{DBNAME}}/$dbname/g" "$f"
done < <(find "$name" -type f ! -name '*.png' -print0)
echo "Made $title in ./$name (address on the Core: $ip${overlay:+, database $dbname})."
case "$overlay" in
*/postgres) f=", database $dbname" ;;
*/sso) f=", sign-in through Authelia" ;;
*) f="" ;;
esac
echo "Made $title in ./$name (address on the Core: $ip$f)."
echo "Next: cd $name && coreapp deploy"
}
@@ -240,6 +252,8 @@ cmd_deploy() {
. /etc/federated
. lib/helpers.sh
. services/$NAME/service
# The same extra values the template's install provides
TRAEFIK_IP=\"\$(sed -n 's/^INTERNAL_IP=//p' services/traefik/service)\"
templatize services/$NAME/docker-compose.yml.in > apps/$NAME/docker-compose.yml
sed -i 's/^IMAGE_VERSION=.*/IMAGE_VERSION=$VERSION/' apps/$NAME/.env
docker compose -f apps/$NAME/docker-compose.yml -p $NAME up -d --remove-orphans 2>&1 | grep -v '^ *Container .* Running\$' || true"
@@ -249,6 +263,20 @@ cmd_deploy() {
core "docker logs --tail 20 $NAME 2>&1" >&2 || true
die "$NAME isn't running on the Core (its log is above, if it has one)."
fi
# Running isn't answering: wait until it answers on its own address and
# port (PORTS in service), from the Core, as traefik reaches it
if [[ -n "$PORTS" ]]; then
echo -n "Waiting for it to answer on $INTERNAL_IP:${PORTS%% *}..."
if ! core "for i in \$(seq 1 30); do
curl -s -o /dev/null --max-time 2 http://$INTERNAL_IP:${PORTS%% *}/ && exit 0
sleep 2
done; exit 1"; then
echo
core "docker logs --tail 20 $NAME 2>&1" >&2 || true
die "$NAME runs but doesn't answer on port ${PORTS%% *} after a minute (its log is above)."
fi
echo " it does."
fi
echo "Deployed: https://$NAME.$domain/ (coreapp check tests it)"
}