Apps get 192.168.5.0/24; keep a copy of each Authelia client

Addresses now come from 192.168.5.0/24, the range Federated's Core
developer set aside for custom apps. Apps installed in 192.168.200.x get
a new address on their next update.

Like Federated's apps, the sso need keeps a copy of its Authelia client in
/federated/apps/<name>/.<name>.oidc-client.yml, so Authelia's start
(reconcile_authelia_sso) restores it if Authelia is reinstalled. Removing
an app deletes the copy before restarting Authelia, which would otherwise
add the client back. Needs can have an update step, run on every update;
sso's writes the copy for apps installed before this.

Fixed: an update of an app with no needs failed at its end (a test that
found nothing to run set the exit status), leaving the app on its old
address.

PLAN.md: the Core developer's guidance and where coreapp-dev stands on
each point.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 14:10:43 -07:00
co-authored by Claude Opus 5.5
parent fdb57d260d
commit 89585e81aa
9 changed files with 96 additions and 22 deletions
+17 -10
View File
@@ -42,10 +42,11 @@ APPS = FEDERATED + "/apps"
LOGS = FEDERATED + "/logs/coreapps"
# Marks a services folder as made by coreapps (and holds what it set up)
MARKER = ".coreapp"
# Addresses for apps, away from Federated's 192.168.0.x (all in the core
# network's 192.168.0.0/16)
PREFIX = "192.168.200."
FIRST, LAST = 10, 250
# Addresses for apps: 192.168.5.0/24, which Federated set aside for them
# (all in the core network's 192.168.0.0/16; Federated's apps are in
# 192.168.0.x)
PREFIX = "192.168.5."
FIRST, LAST = 2, 254
# Hostnames on the Core that aren't apps in /federated/services or lib
RESERVED = {"www", "mail", "ns1", "ns2", "autodiscover", "autoconfig",
"panel", "dashboard", "mcphub", "api", "admin"}
@@ -201,10 +202,11 @@ def used_addresses():
def pick_address(name):
"""The app's address: the one it has, or the first free one."""
"""The app's address: the one it has, or the first free one. (Apps
from before the range moved get a new one; updating moves them.)"""
if is_ours(name):
ip = service_value(os.path.join(SERVICES, name, "service"), "INTERNAL_IP")
if ip:
if ip.startswith(PREFIX):
return ip
used = used_addresses()
for n in range(FIRST, LAST + 1):
@@ -309,9 +311,10 @@ def make_service_folder(m, p, source):
write(os.path.join(new, "uninstall"), fill(read_text(TEMPLATES, "uninstall"), values), 0o755)
for need in m["needs"]:
os.makedirs(os.path.join(new, "needs", need))
for step in ("setup", "teardown"):
write(os.path.join(new, "needs", need, step),
fill(read_text(NEEDS_DIR, need, step), values))
for step in ("setup", "teardown", "update"):
text = read_text(NEEDS_DIR, need, step)
if text:
write(os.path.join(new, "needs", need, step), fill(text, values))
shutil.copyfile(icon_from(source), os.path.join(new, "icon.png"))
shutil.copyfile(os.path.join(source, "coreapp.toml"), os.path.join(new, "coreapp.toml"))
write(os.path.join(new, MARKER),
@@ -393,7 +396,8 @@ def compose_up(m, log, recreate=False):
# Run on update: the same values the generated install provides, then the
# compose file again (it may have changed), settings the new version adds,
# and the setup of needs that are new. Arguments: name, version, needs.
# the setup of needs that are new, and each need's update step (keeping
# what it set up current). Arguments: name, version, new needs.
# (service sets NAME to the app's title, so the name is also in NAME_ID.)
UPDATE_SCRIPT = r'''
cd /federated
@@ -415,6 +419,9 @@ sed -i "s/^IMAGE_VERSION=.*/IMAGE_VERSION=$2/" apps/$1/.env
chmod 600 apps/$1/.env
shift 2
for need in "$@"; do . services/$NAME_ID/needs/$need/setup; done
for step in services/$NAME_ID/needs/*/update; do
if [ -e "$step" ]; then . "$step"; fi
done
'''
+5
View File
@@ -34,6 +34,11 @@ cat >> "$IDP" <<OIDC
OIDC
if docker exec authelia authelia validate-config > /dev/null 2>&1; then
rm -f "$IDP.coreapp-{{NAME}}.bak"
# A copy of the client, as Federated's apps keep: if Authelia is ever
# reinstalled, its start (reconcile_authelia_sso) adds it back
sed -n '/^ ### coreapp-{{NAME}} begin$/,/^ ### coreapp-{{NAME}} end$/p' "$IDP" \
> /federated/apps/{{NAME}}/.{{NAME}}.oidc-client.yml
chmod 600 /federated/apps/{{NAME}}/.{{NAME}}.oidc-client.yml
restart_service authelia
else
echo "Authelia rejected the new client; left its configuration as it was." >&2
+4 -1
View File
@@ -1,4 +1,7 @@
# Remove its OpenID Connect client from the Core's Authelia
# Remove its OpenID Connect client from the Core's Authelia. The copy goes
# first: Authelia's start (reconcile_authelia_sso) would add the client back
# from it
rm -f /federated/apps/{{NAME}}/.{{NAME}}.oidc-client.yml
sed -i '/^ ### coreapp-{{NAME}} begin$/,/^ ### coreapp-{{NAME}} end$/d' \
/federated/apps/authelia/data/config/idproviders.yml
restart_service authelia
+9
View File
@@ -0,0 +1,9 @@
# Keep the copy of its Authelia client current (apps installed before
# copies were kept get one); Authelia's start restores clients from these
IDP=/federated/apps/authelia/data/config/idproviders.yml
COPY=/federated/apps/{{NAME}}/.{{NAME}}.oidc-client.yml
if grep -qx ' ### coreapp-{{NAME}} begin' "$IDP"; then
sed -n '/^ ### coreapp-{{NAME}} begin$/,/^ ### coreapp-{{NAME}} end$/p' "$IDP" > "$COPY"
chmod 600 "$COPY"
fi
unset IDP COPY
+1 -1
View File
@@ -9,6 +9,6 @@ installGeneric {{NAME}}
chmod 600 /federated/apps/{{NAME}}/.env
# What the app needs from the Core (its database, its sign-in client)
for setup in /federated/services/{{NAME}}/needs/*/setup; do
[ -e "$setup" ] && . "$setup"
if [ -e "$setup" ]; then . "$setup"; fi
done
unset setup
+1 -1
View File
@@ -3,7 +3,7 @@
# the Core, delete its settings and data.
docker compose -f /federated/apps/{{NAME}}/docker-compose.yml -p {{NAME}} down
for teardown in /federated/services/{{NAME}}/needs/*/teardown; do
[ -e "$teardown" ] && . "$teardown"
if [ -e "$teardown" ]; then . "$teardown"; fi
done
unset teardown
rm -rf /federated/apps/{{NAME}}