The Core's admin account is always an admin of the app

Every app's .env gets CORE_ADMIN_EMAIL (admin@<domain>, the Core's own
admin, as Federated's apps use). The skill says apps make that account an
admin on each Core sign-in, trusting only Authelia's email, instead of a
setup link; the sso example apps show the check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 18:34:36 -07:00
co-authored by Claude Opus 5.5
parent da36a669bf
commit dca8837487
8 changed files with 54 additions and 13 deletions
+1
View File
@@ -41,6 +41,7 @@ keep its values and add new ones):
| `APP_SECRET` | A random secret, for signing cookies and such |
| `IMAGE_VERSION` | The version that's installed |
| `CORE_DOMAIN` | The Core's domain (set only on a Core) |
| `CORE_ADMIN_EMAIL` | `admin@<domain>`, the Core's admin account: always an admin of the app, when it signs in with the Core |
`needs = ["postgres"]` adds `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER` and
`DB_PASSWORD` (`needs = ["mysql"]` the same, for MariaDB); `needs = ["sso"]` adds `OIDC_ISSUER`, `OIDC_CLIENT_ID` and
+2 -1
View File
@@ -88,9 +88,10 @@ class Handler(BaseHTTPRequestHandler):
"SELECT count(*) FROM visits WHERE person = %s", (user["sub"],)
).fetchone()[0]
people = db.execute("SELECT count(DISTINCT person) FROM visits").fetchone()[0]
admin = ", the app's admin" if user.get("admin") else ""
self.page(
f"<p>Signed in as <strong id=\"user\">{html.escape(user['name'])}</strong>"
f" ({html.escape(user['email'])}).</p>"
f" ({html.escape(user['email'])}){admin}.</p>"
f"<p>Your visits: <strong id=\"visits\">{mine}</strong>"
f" (people who have visited: {people}), counted in PostgreSQL.</p>"
'<p><a href="/logout">Sign out</a></p>'
+3 -1
View File
@@ -42,9 +42,11 @@ class Handler(BaseHTTPRequestHandler):
user = oidc.read_session(self.cookie("session"))
if user:
groups = ", ".join(user.get("groups") or []) or "none"
admin = ", the app's admin" if user.get("admin") else ""
body = (
f"<p>Signed in as <strong id=\"user\">{html.escape(user['name'])}</strong>"
f" ({html.escape(user['email'])}), groups: {html.escape(groups)}.</p>"
f" ({html.escape(user['email'])}), groups: {html.escape(groups)}"
f"{admin}.</p>"
'<p><a href="/logout">Sign out</a></p>'
)
else:
+7 -2
View File
@@ -2,7 +2,7 @@
Authorization code flow with PKCE, and a signed session cookie. Settings
come from the environment (.env on the Core): APP_URL, APP_SECRET,
OIDC_ISSUER, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET.
OIDC_ISSUER, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET, CORE_ADMIN_EMAIL.
location, flow = start_login() # /login: redirect to Authelia
user = finish_login(query, flow) # /auth/callback: who signed in
@@ -29,6 +29,9 @@ ISSUER = os.environ["OIDC_ISSUER"].rstrip("/")
CLIENT_ID = os.environ["OIDC_CLIENT_ID"]
CLIENT_SECRET = os.environ["OIDC_CLIENT_SECRET"]
REDIRECT_URI = APP_URL + "/auth/callback"
# The Core's admin account (admin@<domain>) is always the app's admin. Only
# trusted here, from the Core's sign-in: never from an address someone types
CORE_ADMIN_EMAIL = os.environ.get("CORE_ADMIN_EMAIL", "").lower()
SESSION_SECONDS = 3600
FLOW_SECONDS = 600
@@ -100,7 +103,8 @@ def start_login():
def finish_login(query, flow_cookie):
"""Who signed in: {sub, name, email, groups}, from Authelia's answer."""
"""Who signed in: {sub, name, email, groups, admin}, from Authelia's
answer."""
flow = unsign(flow_cookie)
if not flow or not hmac.compare_digest(flow["state"], query.get("state", "")):
raise SignInError("The sign-in expired or didn't start here. Try again.")
@@ -132,6 +136,7 @@ def finish_login(query, flow_cookie):
"name": info.get("name") or info.get("preferred_username") or info["sub"],
"email": info.get("email", ""),
"groups": info.get("groups", []),
"admin": bool(CORE_ADMIN_EMAIL) and info.get("email", "").lower() == CORE_ADMIN_EMAIL,
}