Fixes from the Leantime rehearsal: unhealthy apps, signin links and errors

Deploy now waits while an image's own HEALTHCHECK says "starting" and
stops on "unhealthy" with the check and its result, since traefik doesn't
route unhealthy containers (it used to say "Updated"); an update rolls
back, a first install says it stays installed, and a rollback waits until
the old version is routed again. coreapp signin follows a page's one
"Core SSO" or "Authelia" link, prints the app's visible error when it
doesn't end signed in, and has --help. The skill covers 127.0.0.1 among
trusted proxies, the image's HEALTHCHECK, COPY --chmod, $TMPDIR outside
the sandbox, patching an app's OIDC code for userinfo claims, and testing
a new account's first sign-in. PLAN: ID-token claims for Federated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-04 11:33:52 -07:00
co-authored by Claude Opus 5.5
parent cbdf0e5789
commit f4b869decd
8 changed files with 261 additions and 22 deletions
+105 -7
View File
@@ -9,7 +9,9 @@ signin.py [--cookies FILE] [--form ACTION] <start-url> <username>
and say where it ended. If start-url is a page whose form starts sign-in
(a button, with hidden fields only, e.g. a CSRF token), submit it, as a
person pressing the button would: the only such form, or the one whose
action is ACTION.
action is ACTION. Without such a form, follow its one link whose text
names Core SSO or Authelia. When it doesn't end signed in, it prints
the error or notice the app's page shows.
signin.py --code [--pkce] <issuer> <client-id> <callback-url> <username>
For apps whose sign-in starts in the browser's JavaScript: start at
Authelia's authorization with the app's client, sign in, and stop at the
@@ -120,6 +122,92 @@ class Forms(html.parser.HTMLParser):
self.form["button"] = (self.form["button"] + " " + data.strip()).strip()
class Links(html.parser.HTMLParser):
"""The page's links that start sign-in with the Core: their text (or
title or aria-label) names Core SSO or Authelia, as Coreapps label it."""
NAMES = re.compile(r"core\s*sso|authelia", re.I)
def __init__(self):
super().__init__()
self.found, self.href, self.text = [], None, ""
def handle_starttag(self, tag, attrs):
if tag == "a":
a = dict(attrs)
self.href = a.get("href")
self.text = " ".join(filter(None, [a.get("title"), a.get("aria-label")]))
def handle_data(self, data):
if self.href is not None:
self.text += " " + data
def handle_endtag(self, tag):
if tag == "a" and self.href is not None:
text = " ".join(self.text.split())
if self.NAMES.search(text) and not self.href.startswith(("#", "javascript:")):
self.found.append((self.href, text))
self.href = None
def pick_link(page_url, body):
"""(url, label) for the page's one Core SSO link, or None."""
parser = Links()
parser.feed(body.decode(errors="replace"))
urls = {}
for href, text in parser.found:
urls.setdefault(urllib.parse.urljoin(page_url, href), text)
if len(urls) != 1:
return None
url, text = next(iter(urls.items()))
return url, f"the link \"{text[:60]}\""
class Messages(html.parser.HTMLParser):
"""Text the page shows as an error or notice: elements whose class, id
or role says alert, error, notice, flash or the like."""
KINDS = re.compile(r"alert|error|danger|warning|notice|notification|flash|toast|invalid", re.I)
VOID = {"br", "img", "input", "meta", "link", "hr", "wbr", "source"}
def __init__(self):
super().__init__()
self.depth, self.parts, self.found = 0, [], []
def handle_starttag(self, tag, attrs):
if tag in self.VOID:
return
if self.depth:
self.depth += 1
return
a = dict(attrs)
marks = " ".join(filter(None, [a.get("class"), a.get("id"), a.get("role")]))
if tag not in ("script", "style", "template") and self.KINDS.search(marks):
self.depth, self.parts = 1, []
def handle_endtag(self, tag):
if tag in self.VOID or not self.depth:
return
self.depth -= 1
if not self.depth:
text = " ".join(" ".join(self.parts).split())
if text and text not in self.found:
self.found.append(text)
def handle_data(self, data):
if self.depth:
self.parts.append(data)
def page_says(body):
"""' The page says: "..."' with its visible error or notice, or ''."""
parser = Messages()
try:
parser.feed(body.decode(errors="replace"))
except Exception:
return ""
text = "; ".join(parser.found)[:300]
return f' The page says: "{text}".' if text else ""
def pick_form(page_url, body, wanted):
"""(url, data, label) for the form that starts sign-in, or None."""
parser = Forms()
@@ -221,6 +309,14 @@ def follow(browser, url, username, password, stop_at=None, form=None):
browser.signin_urls.append(url)
submitted = True
continue
if not signed_in and not submitted and status == 200 and not form:
# Or whose link does ("Sign in with Core SSO")
picked = pick_link(url, body)
if picked:
url, label = picked
browser.signin_urls.append(url)
submitted = True
continue
return url, status, body, signed_in
raise SystemExit(f"Not signed in: more than {MAX_STEPS} redirects.")
@@ -285,14 +381,16 @@ def main(args):
if not signed_in:
raise SystemExit(
f"Not signed in: {shown(start)} didn't lead to the Core's sign-in (it ended at "
f"{shown(last)}, HTTP {status}). Give the app's path that starts sign-in, or its sign-in "
"page with --form <action> for a form; if the app starts it in the browser's "
"JavaScript, use --code.")
f"{shown(last)}, HTTP {status}).{page_says(body)} Give the app's path that starts "
"sign-in, or its sign-in page (a button is pressed, a \"Core SSO\" link followed; "
"--form <action> picks a form); if the app starts it in the browser's JavaScript, "
"use --code.")
if urllib.parse.urlsplit(last).netloc != app.netloc:
raise SystemExit(f"Not signed in: it ended at {shown(last)} (HTTP {status}), not at the app.")
if status >= 400:
raise SystemExit(f"Not signed in: Authelia accepted the test account, but the app answered "
f"HTTP {status} at {shown(last)} (coreapp logs says why).")
f"HTTP {status} at {shown(last)}.{page_says(body)} (coreapp logs may say "
"more.)")
text = re.sub(rb"<[^>]+>", b" ", body).decode(errors="replace")
mentions = username.split("@")[0] in text
# Back at the app isn't signed in if the app's page offers sign-in again
@@ -306,8 +404,8 @@ def main(args):
if offers and not mentions:
raise SystemExit(
f"Not signed in: Authelia accepted the test account, but the app ended at "
f"{shown(last)}, which offers sign-in again: its callback didn't sign the person in "
"(coreapp logs says why).")
f"{shown(last)}, which offers sign-in again: its callback didn't sign the person "
f"in.{page_says(body)} (coreapp logs may say more.)")
if cookies:
jar.save(ignore_discard=True, ignore_expires=True)
print(f"Signed in: back at the app, {shown(last)} answered HTTP {status}.")