Let apps describe their sign-in client: [sso] callback, pkce, token_auth

A rehearsal with Vikunja showed apps with their own redirect path or no
PKCE needed a bridge in the container. coreapp.toml's [sso] now sets the
Authelia client's callback, PKCE and token method; changes re-register
the client, and a failed update restores it. The skill covers [sso],
images without a shell and upstream ENV defaults; coreapp shell and
status explain rough edges the rehearsal hit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 17:45:54 -07:00
co-authored by Claude Opus 5.5
parent e2d9381c35
commit 5d06f1bd9b
10 changed files with 174 additions and 12 deletions
+55 -1
View File
@@ -86,9 +86,17 @@ FIELDS = {
"health": r"/[A-Za-z0-9._~/-]{0,100}",
"docs": r"(?:https://[A-Za-z0-9.-]+(?::[0-9]{1,5})?(?:/[A-Za-z0-9._~/%+-]*)?)?",
"needs": None,
"sso": None,
}
REQUIRED = ["name", "title", "version", "image", "port"]
# [sso]: how the app's OpenID Connect client in Authelia differs from the
# default, for apps whose sign-in can't be configured to match it
SSO_DEFAULTS = {"callback": "/auth/callback", "pkce": True,
"token_auth": "client_secret_basic"}
SSO_CALLBACK = r"/[A-Za-z0-9._~/-]{0,200}"
SSO_TOKEN_AUTH = ["client_secret_basic", "client_secret_post"]
# Repositories apps are installed from: https only, no user or password in
# the URL. Tags: v + a version; releases (picked by default) are numeric.
REPO_URL = r"https://[A-Za-z0-9.-]+(?::[0-9]{1,5})?(?:/[A-Za-z0-9._-]+){2,}?(?:\.git)?/?"
@@ -118,6 +126,25 @@ def say(*args):
# --- coreapp.toml -------------------------------------------------------------
def read_sso(value):
"""coreapp.toml's [sso] table, checked, with defaults filled in."""
if not isinstance(value, dict):
raise Refused("coreapp.toml: sso must be a table: [sso] with callback, pkce, token_auth.")
unknown = sorted(set(value) - set(SSO_DEFAULTS))
if unknown:
raise Refused(f"coreapp.toml: [sso]: unknown setting(s) {', '.join(unknown)} "
f"(it knows {', '.join(SSO_DEFAULTS)}).")
sso = dict(SSO_DEFAULTS, **value)
if not isinstance(sso["callback"], str) or not re.fullmatch(SSO_CALLBACK, sso["callback"]):
raise Refused(f"coreapp.toml: [sso] callback = {sso['callback']!r} isn't allowed: "
"a path on the app's own address, like \"/auth/callback\".")
if not isinstance(sso["pkce"], bool):
raise Refused("coreapp.toml: [sso] pkce must be true or false.")
if sso["token_auth"] not in SSO_TOKEN_AUTH:
raise Refused(f"coreapp.toml: [sso] token_auth must be {' or '.join(SSO_TOKEN_AUTH)}.")
return sso
def read_manifest(folder):
"""coreapp.toml in folder, checked, with defaults filled in."""
path = os.path.join(folder, "coreapp.toml")
@@ -139,7 +166,7 @@ def read_manifest(folder):
if missing:
raise Refused(f"coreapp.toml needs {', '.join(missing)}.")
m = {"description": "", "health": "/", "docs": "", "needs": []}
m = {"description": "", "health": "/", "docs": "", "needs": [], "sso": dict(SSO_DEFAULTS)}
for key, value in data.items():
if key == "port":
if not isinstance(value, int) or isinstance(value, bool) or not 1 <= value <= 65535:
@@ -152,6 +179,8 @@ def read_manifest(folder):
raise Refused(f"coreapp.toml: needs: unknown {', '.join(bad)} "
f"(it knows {', '.join(NEEDS)}).")
value = [n for n in NEEDS if n in value]
elif key == "sso":
value = read_sso(value)
if "postgres" in value and "mysql" in value:
raise Refused("coreapp.toml: needs: postgres or mysql, not both "
"(both give the app DB_* settings).")
@@ -160,6 +189,8 @@ def read_manifest(folder):
raise Refused(f"coreapp.toml: {key} = {value!r} isn't allowed. "
+ HINTS.get(key, ""))
m[key] = value
if "sso" in data and "sso" not in m["needs"]:
raise Refused('coreapp.toml: [sso] is for apps with "sso" in needs.')
if m["name"] in RESERVED:
raise Refused(f"'{m['name']}' is one of the Core's own hostnames. Pick another name.")
m["dbname"] = "coreapp_" + m["name"].replace("-", "_")
@@ -604,6 +635,9 @@ def make_service_folder(m, p, source, origin):
# Without docs, Superpanel links a search of Federated's documentation
"DOCS": m["docs"] or (origin["source"] if origin else ""), "IMAGE": m["image"], "VERSION": m["version"],
"IP": p["address"], "PORT": str(m["port"]), "DBNAME": m["dbname"],
"SSO_CALLBACK": m["sso"]["callback"], "SSO_TOKEN_AUTH": m["sso"]["token_auth"],
"SSO_PKCE": ("require_pkce: true\n pkce_challenge_method: 'S256'"
if m["sso"]["pkce"] else "require_pkce: false"),
"DEPENDS": " ".join(read_text(NEEDS_DIR, n, "depends").strip() for n in m["needs"]),
}
compose_extra = "".join(read_text(NEEDS_DIR, n, "compose") for n in m["needs"])
@@ -920,6 +954,18 @@ for need in "$@"; do
done
'''
# After the old service folder is back: its needs' update steps, so what
# they set up matches it again (e.g. an Authelia client the update changed)
RESYNC_SCRIPT = r'''
cd /federated
. /etc/federated
. lib/functions.sh
. lib/helpers.sh
for step in services/$1/needs/*/update; do
if [ -e "$step" ]; then . "$step"; fi
done
'''
def roll_back(m, p, backup, log):
"""Put back the version that ran before a failed update, with its
@@ -952,6 +998,11 @@ def roll_back(m, p, backup, log):
for f in ROLLBACK_FILES:
if os.path.exists(os.path.join(backup, f)):
shutil.copy2(os.path.join(backup, f), os.path.join(APPS, name, f))
with open(log, "a") as f:
result = subprocess.run(["bash", "-c", RESYNC_SCRIPT, "resync", name],
stdout=f, stderr=subprocess.STDOUT)
if result.returncode != 0:
problems.append("putting back what its needs set up")
try:
old = read_manifest(final)
except Refused:
@@ -1126,6 +1177,9 @@ def main(args):
"health", "docs", "dbname"):
print(f"{key}={m[key]}")
print(f"needs={' '.join(m['needs'])}")
if "sso" in m["needs"]:
for key, value in m["sso"].items():
print(f"sso_{key}={str(value).lower() if isinstance(value, bool) else value}")
state, note = icon_check(rest[0])
print(f"icon={state}")
print(f"icon_note={note}")