From dca883748789d3f090b4f0a85ddd0d4d442f7fe5 Mon Sep 17 00:00:00 2001 From: David Young Date: Thu, 3 Dec 2026 18:34:36 -0700 Subject: [PATCH] The Core's admin account is always an admin of the app Every app's .env gets CORE_ADMIN_EMAIL (admin@, 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 --- PLAN.md | 9 +++++++++ TEST.md | 10 ++++++++-- core/templates/env.in | 3 +++ skills/coreapp/SKILL.md | 28 +++++++++++++++++++++------- templates/app/README.md | 1 + templates/postgres-sso/app.py | 3 ++- templates/sso/app.py | 4 +++- templates/sso/oidc.py | 9 +++++++-- 8 files changed, 54 insertions(+), 13 deletions(-) diff --git a/PLAN.md b/PLAN.md index ae608bd..1d7d265 100644 --- a/PLAN.md +++ b/PLAN.md @@ -416,6 +416,15 @@ Steps: the first admin comes from a setup link in the log, not whoever signs in first; apps with their own client-setup step take `OIDC_*` instead; icons under 80 pixels get a note + - Decided 2026-12-03 (David): on a Core, the Core's admin account + `admin@` (uid `admin`, the one member of `admins`; Federated's + own apps make it their admin too) is always an admin of the app, + trusted only from the Core's sign-in. Every app's `.env` has + `CORE_ADMIN_EMAIL`; the skill says so instead of a setup link, and + the sso example shows it. Supermarket (setup link) should change + to it + - [ ] David: sign in to a `coreapp new --sso` app as admin in a + browser ("the app's admin") - [ ] David: the agent's changes, for Supermarket's own repository (and a login CSRF it noticed in the app's sign-in: its OIDC state isn't tied to a browser cookie) diff --git a/TEST.md b/TEST.md index a3f64a9..40f4eb2 100644 --- a/TEST.md +++ b/TEST.md @@ -192,8 +192,9 @@ The Core's own scripts trace secrets, so their output goes to `docker-compose.yml.in`, `env.in`, `install`, `uninstall`, `icon.png`, `coreapp.toml` and `.coreapp` (`needs=`); `/federated/apps/hello/.env` is root's, mode 600, with `IMAGE_VERSION` equal to `version` and a - random `APP_SECRET`, and `CORE_DOMAIN` the Core's domain (an app - installed before `CORE_DOMAIN` existed gets it on its next update). + random `APP_SECRET`, `CORE_DOMAIN` the Core's domain and + `CORE_ADMIN_EMAIL` `admin@` (an app installed before they + existed gets them on its next update). Superpanel's catalog (`/federated/apps/superpanel/data/catalog.json`) lists `hello`. 3. `coreapp check`: `OK: HTTP 200, valid certificate.` (the first @@ -354,6 +355,11 @@ has the `DB_*` variables, `.coreapp` says `needs=postgres`. /nope (its forms: /signin, /signin/core)". sso-demo's `/` (a link, not a form): "didn't lead to the Core's sign-in". A page with two hidden-only forms: "several forms ... pick one with --form". +12. The Core's admin: a new `coreapp new --sso` app, deployed, `coreapp + signin --cookies jar`: its page says "Signed in as coreapp.test ... + groups: none." (not admin). With `CORE_ADMIN_EMAIL` in its `.env` set + to the test account's address in other capitals, recreated: "..., the + app's admin." In a browser as `admin@`: "the app's admin". ### With mysql diff --git a/core/templates/env.in b/core/templates/env.in index d53c301..13e2fe5 100644 --- a/core/templates/env.in +++ b/core/templates/env.in @@ -4,4 +4,7 @@ IMAGE_VERSION=@VERSION@ APP_URL=https://{{NAME}}.@DOMAIN@ # The Core's domain; set only on a Core, so an app can tell it runs on one CORE_DOMAIN=@DOMAIN@ +# The Core's admin account: always an admin of the app, when signed in with +# the Core (needs "sso") +CORE_ADMIN_EMAIL=admin@@DOMAIN@ APP_SECRET=@APP_SECRET:RANDOM:LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL@ diff --git a/skills/coreapp/SKILL.md b/skills/coreapp/SKILL.md index 47b91d3..04db525 100644 --- a/skills/coreapp/SKILL.md +++ b/skills/coreapp/SKILL.md @@ -54,6 +54,7 @@ What the Core gives every app: | `APP_SECRET` | 32 random letters and digits, for signing cookies, sessions | | `IMAGE_VERSION` | The installed version (`coreapp deploy` builds with plain `docker build .`, no build args, so read the version from here, not a build-time `VERSION`) | | `CORE_DOMAIN` | The Core's domain (``). Set only on a Core: an app that also runs elsewhere can use it to tell | + | `CORE_ADMIN_EMAIL` | `admin@`, the Core's admin account: always an admin of the app (see `sso`) | `APP_SECRET` isn't hex or base64: an app that wants key bytes (e.g. 32 bytes for encryption) derives them, e.g. SHA-256 of `APP_SECRET`. It @@ -187,10 +188,23 @@ may log; it should retry). today's Cores: they have two groups, `admins` and `everybody`, but Authelia's settings don't find them yet (for Federated to fix). Read `groups` if the app can use it, but don't depend on it for roles. -- The app's first admin: not "whoever signs in first" (any employee could - be first). Prefer a one-time setup link or code the app prints in its log - (`coreapp logs`, or `coreapp shell ''`), then admins it - names in its own settings. Later, the Core's `admins` group. +- **The app's admin is the Core's admin.** On a Core, the account + `CORE_ADMIN_EMAIL` (`admin@`, the Core's own admin, as in + Federated's apps) is always an admin of the app, from its first sign-in: + no setup link, no first-come owner. It can then make other people admins + in the app. Two rules: + - Trust it only from the Core's sign-in: the `email` in Authelia's + userinfo or ID token, compared case-insensitively. Never make a local + account, a sign-up or an invitation with that address an admin; anyone + could type it. + - Every time, not only the first: if its admin role was taken away in + the app, its next Core sign-in gives it back. + + If the app has its own first-run setup (an owner to create, a setup + link), skip it on a Core: the Core's admin is the owner. The example app + (`coreapp new --sso`) shows the check in `oidc.py`. `coreapp signin` + signs in as the test account, not the admin, so ask the user to sign in + once as `admin@` in a browser and check it gets the admin pages. - Discovery: `$OIDC_ISSUER/.well-known/openid-configuration`. The Core routes `authelia.` from inside the app's container to the real HTTPS endpoint, with a valid certificate, so normal TLS verification works. @@ -377,9 +391,9 @@ state (a server-side callback page) refuses it: use the path form for those. Authelia bans an account for a few minutes after repeated failed sign-ins, so don't loop on it. -Still ask the user to sign in once in a browser with their own account -before a release: it checks what a script can't (the app's pages, and a -real person's account). +Still ask the user to sign in once in a browser before a release, as the +Core's admin (`admin@`): it checks what a script can't (the app's +pages, and that the admin gets the admin role). ### 4. When something fails diff --git a/templates/app/README.md b/templates/app/README.md index b9a6fda..223c5a8 100644 --- a/templates/app/README.md +++ b/templates/app/README.md @@ -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@`, 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 diff --git a/templates/postgres-sso/app.py b/templates/postgres-sso/app.py index aabe8f4..053ddf0 100644 --- a/templates/postgres-sso/app.py +++ b/templates/postgres-sso/app.py @@ -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"

Signed in as {html.escape(user['name'])}" - f" ({html.escape(user['email'])}).

" + f" ({html.escape(user['email'])}){admin}.

" f"

Your visits: {mine}" f" (people who have visited: {people}), counted in PostgreSQL.

" '

Sign out

' diff --git a/templates/sso/app.py b/templates/sso/app.py index f18fedb..1313900 100644 --- a/templates/sso/app.py +++ b/templates/sso/app.py @@ -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"

Signed in as {html.escape(user['name'])}" - f" ({html.escape(user['email'])}), groups: {html.escape(groups)}.

" + f" ({html.escape(user['email'])}), groups: {html.escape(groups)}" + f"{admin}.

" '

Sign out

' ) else: diff --git a/templates/sso/oidc.py b/templates/sso/oidc.py index e4b35fa..c47177a 100644 --- a/templates/sso/oidc.py +++ b/templates/sso/oidc.py @@ -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@) 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, }